What is the CSS class selector?

The class selector selects all elements that have a given class. In CSS you write a dot before the class name.

.note { background: #fff3cd; padding: 8px; }
p.note { border-left: 4px solid orange; }   /* only p elements with the class */
<p class="note">A note</p>
<div class="note important">Another note</div>

One class can be used on many elements, and one element can have many classes. An id is different: see id and class and CSS Selectors.


Learn more about the similar topics:
Tutorials
CSS Selectors
CSS Specificity
CSS Pseudo-classes and Pseudo-elements
Exercises & Assignments
No Content Found.
Interview Questions & Answers
What is the CSS class selector?
What is grouping in CSS and what is it used for?
What are child selectors in CSS?
What is the difference between id and class selector in CSS?
What is specificity in CSS?
What does !important do in CSS?
What are pseudo-classes and pseudo-elements in CSS?