3.7 ID Selectors
It’s time for another type of selector—an ID selector. An ID selector is similar to a class selector in that it relies on an element attribute value in searching for element matches. As you might guess, an ID selector uses an element’s id attribute (as opposed to a class selector, which uses an element’s class attribute). A significant feature of an id attribute is that its value must be unique within a particular web page. That’s different from a class attribute’s value, which does not have to be unique within a particular web page. The ID selector’s unique-value feature means that an ID selector’s CSS rule matches only one element on a web page. This single-element matching mechanism is particularly helpful with links and ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access