Creating Classes and IDs for Applying Styles

As you have just seen, style rules can modify the built-in tags in HTML by redefining their formatting. Styles don’t stop there, however. You can make your own styles by creating classes and IDs.

Classes and IDs mark certain elements so you can refer to them in your style sheet. A class can be applied to multiple selections, whereas an ID uniquely identifies a specific selection within a document. (Different documents can use the same ID.)

For example, suppose you have an unordered list of products, and you want new products to appear in red. One way to do it would be to manually add the style="color: red" argument to each of the list items, like this:

<li style="color: red">Spraying Techniques for Fruit ...

Get HTML and XHTML Step by Step now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.