First page Back Continue Last page Graphics
Classes and IDs: IDs
IDs are similar to classes, but IDs are unique – they can only be used with one instance of an element within a document.
When defining a CSS rule using an ID-based selector, use a number/pound/hash sign (#) followed by the style name. To limit the style to a particular element with that id attribute, use a selector combining the tag name with a # and then the id name.
- The following rule would apply to any element with the attribute id="intro"
- #intro { font-size: 2em; }
- The following rule would apply only to heading 1 tags with the id intro (<h1 id="intro">)
- h1#intro { color: green; }