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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access