Beautiful Parts: Universal Attributes

You’ll be seeing a lot of the class and id attributes throughout this book. These are universal attributes—they can be used by any element in the HTML vocabulary that’s valid as well as body itself.

In addition to class and id, there are four other attributes that are similarly versatile:

  • title

  • lang/xml:lang

  • dir

  • style

dir specifies which direction type should run. style will be described in Chapter 14.

Providing Stylesheet Hooks with class and id

Two attributes that can be assigned to all elements are class and id. Several class values but only one id value can be assigned to a given element. Multiple class values are separated by spaces, e.g., class="alternate callToAction".

Valid class and id values should contain only letters, numbers, hyphens, and underscores. These values should begin only with letters and numbers. However, Internet Explorer 6 parses and applies stylesheet values that are associated with class values, id values, and property names that begin with underscores—an oversight that provides stylists with a low-pass filtering technique.

A more important question is where to put classes and ids. As a rule, classes should be assigned to those frequently encountered elements that share both design purpose and presentation peculiarities, but aren’t used predictably. On many sites, classes are also assigned to the body elements of pages that fall within a single section of the site’s architecture, such as the common “About” and “Contact” sections. ...

Get HTML & CSS: The Good Parts now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.