HTML and CSS Reference
But how do I use id in CSS?
You select an element with an id almost exactly like you select an element with a
class. To quickly review: if you have a class called specials , there are a couple
of ways you can select elements using this class. You could select just certain
elements in the class, like this:
This selects only par agraphs that are in the specials class.
Or you can select all the elements that belong to the specials class, like this:
This selects all elements in the specials class.
Using an id selector is very similar. To select an element by its id, you use a # (hash mark)
character in front of the id (compare this to class, where you use a . [dot] in front of the
class name). Say you want to select any element with the id footer :
This s elects any element that has the id “footer”.
Or you could select only a <p> element with the id footer , like this:
Th is selects a <p> element if it has the id “foot er”.
The other difference between class and id is that an id selector should match
only one element in a page.