CSS id selector selects an element that has the specified id attribute. As an id is always unique within a page, therefore, the id selector always selects a single element from the page and applies CSS styles to it.
To select an element using the id selector, use a hash symbol(#)
followed by the id of the element. For example, #myId
.
In the example below, the id selector selects a <p>
element that has id="p2"
and applies CSS styles to it. Try it out to see how it works:
Example:
#p2{ background: yellow; border: 2px dashed blue; padding: 10px; }
CSS id Selector Syntax
#id{ CSS styles }
Related Pages
CSS Tutorial: CSS Selectors