class identifier
The class
attribute
is used for grouping similar elements. Multiple elements may be
assigned the same class
name, and
doing so enables them to be treated similarly.
In the span
example above,
the telephone number was identified as telephone
with the class
attribute. This implies that there may
be many more telephone numbers in the document. A single style sheet
rule could then be used to make them all bold and blue. Changing them
all to green requires editing just one line of code. This offers an
obvious advantage over changing color one by one with the deprecated
font
element. In addition to being
inefficient to maintain, font
doesn’t add any semantic cues for user agents.
According to the HTML 4.01 specification, the class
attribute may be used:
As a style sheet selector
For general purpose processing by user agents
In HTML 4.01, id
and class
attributes may be used with all
elements except base
, basefont
, head
, html
, meta
, param
, script
, style
, and title
. In XHTML, id
support has been added to those
elements.
Get Web Design in a Nutshell, 3rd Edition 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.