What is the difference between id and class selector in CSS?
An id must be unique on the page and is selected with #. A class can be used on many elements and is selected with a dot ..
| Point | id | class |
|---|---|---|
| Selector | #header | .note |
| Elements | One | Many |
| Specificity | Higher (100) | Lower (10) |
#header { background: navy; }
.note { color: gray; }
Use classes for styling in most cases, and keep ids for page anchors and JavaScript. See CSS Specificity.
Learn more about the similar topics:
| Tutorials |
|---|
| CSS Selectors |
| CSS Specificity |
| CSS Pseudo-classes and Pseudo-elements |
| Exercises & Assignments |
|---|
| No Content Found. |