Naming Elements with a Class or ID

Although it isn’t required, you can give your HTML elements a unique identifier, assign them a particular class (or classes), or both. After doing so, you can apply styles to all elements with a given id or class name. That’s certainly their most popular use, but not their only one (see the tips in this section).

To name an element with a unique id

Within the start tag of the element, type id="name", where name uniquely identifies the element Image. name can be almost anything, as long as it doesn’t start with a number or contain any spaces.

Add a unique id attribute to an element in order to identify it for later ...

Get HTML5 and CSS3: Visual QuickStart Guide, Seventh Edition now with O’Reilly online learning.

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