The id attribute’s value must be unique
The id attribute is used to give an HTML element a unique name. That name has several uses:
- In ID selectors in CSS
- Referencing the element with JavaScript through the
getElementByIdDOM method - Making the element an anchor which can be linked to with a fragment identifier
- Associating a
labelelement with a form control via the for attribute - Specifying which header cell(s) that provide header information for a data cell via the headers attribute
The value of each id attribute must be unique in a document. An easy way to check that your HTML document does not contain multiple occurrences of the same id value is to run it through W3C’s HTML Validator.
This post is a Quick Tip. Background info is available in Quick Tips for web developers and web designers.
- Previous post: Quick Tips for web developers and web designers
- Next post: Version control with Subversion on Mac OS X