O'Reilly logo

Microsoft® HTML5 Step by Step by Faithe Wempen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 that 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” attribute to each of the list items, like this:

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required