CSS id selector
The id selector uses the id
attribute of an element to find a specific element on the page — as you probably remember from our HTML course, ids can't repeat on the same page. To select the element by its id, use a hash (#
) before the id's value — for example, #header
.
You might want to add element tags just to let yourself visually know in your CSS what you are targeting. For example, if id="header"
is applied to the container <div>
, you can use div#header
as a selector.
Pro Tip: Id selectors aren't widely used in CSS, but they are crucial in JavaScript.