The id Selector
With the id selector you can define the same style for different HTML elements.
The style rule below will match any element that has an id attribute with a value of "green":
#green {color: green} |
The rule above will match both the h1 and the p element:
<h1 id="green">Some text</h1> <p id="green">Some text</p> |
The style rule below will match a p element that has an id with a value of "para1":
p#para1 { text-align: center; color: red } |
The style rule below will match any p element that has an id attribute with a value of "green":
p#green {color: green} |
The rule above will not match an h1 element:
<h1 id="green">Some text</h1> |