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
class
es and id
s. As a rule, class
es should be assigned to those frequently
encountered elements that share both design purpose and presentation
peculiarities, but arenât used predictably. On many sites, class
es 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â ...
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.