Mozilla Developer Network states in their CSS tutorial -
"you can only have one element with each unique ID on a page, but many elements within the same class".
I must not be understanding that correctly.
I interpret that statement in the following way:
- Within an HTML document, styled with a .css file, you can assign a styling to a Unique Identifier (ID).
- You can apply that styling to only one element within your page.
- Any subsequent uses of the ID will fail, or perhaps only the last application will be applied to the page.
However, in practice, I am able to apply an ID to as many elements as I want. As an example, I applied the ID to two <p>
elements and one <div>
element, and all of the those elements had the styling attached to that ID applied to them.
How am I meant to interpret that statement at the beginning of my post?
Is that more of a "best practices" type thing or are there hard rules within HTML and CSS that I am misunderstanding?
With my interpretation, only one of those elements should be styled by the ID, but all three are receiving the styling.