Xhtml Reference

generally supported elements and associated attributes. This is not intended as an exhaustive guide; rather, its aim is to list those elements important and relevant to current web design. Archaic deprecated elements such as font and layer are therefore ignored, as well as many attributes once associated with the body element


Standard attributes

Standard attributes are common to many elements. For brevity, they are listed in full here rather than in the XHTML element table later in the chapter. For each element in the forth- coming table, I simply state which groups of standard attributes are applicable to the element.

Core attributes

Attribute

Description

class=classname

Specifies a CSS class to define the element’s visual appearance.

id=name

Defines a unique reference ID for the element.

style=style
(deprecated)

Sets an inline style. Deprecated in XHTML 1.1, so it should be
used sparingly and with caution.

title=string

Specifies the element’s title. Often used with links to provide a
tooltip expanding on the link’s purpose or the target’s content.

 


Keyboard attributes

Attribute

Description

accesskey=character

Defines a keyboard shortcut to access an element. The short-
cut must be a single character. Most commonly used with
navigation links.

tabindex=number

Defines the tab order of an element. Most commonly used
with form input elements. Setting the value to 0 excludes
the element from the tabbing order. The maximum value
allowed is 32767. The tabindex values on a page needn’t be
consecutive (for instance, you could use multiples of 10, to
leave space for later additions).


Language attributes

Attribute

Description

dir=dir

Specifies the text rendering direction: left-to-right (ltr, the
default) or right-to-left (rtl).

lang=language
(deprecated)

Specifies the language for the tag’s contents, using two-letter
primary ISO639 codes and optional dialect codes. Included
for backward compatibility with HTML. Used together with
xml:lang (see below) in XHTML 1.0, but deprecated in
XHTML 1.1.
Examples:
lang="en" (English)
lang="en-US" (US English)
ISO639 codes include the following: ar (Arabic), zh
(Chinese), nl (Dutch), fr (French), de (German), el (Greek),
he (Hebrew), it (Italian), ja (Japanese), pt (Portuguese), ru
(Russian), sa (Sanskrit), es (Spanish), and ur (Urdu).

xml:lang=language

Replaces lang in XHTML 1.1, but both should be used
together in XHTML 1.0 to ensure backward compatibility with
HTML and older browsers. xml:lang takes precedence over
lang if set to a different value.


Event attributes

As of HTML 4.0, it’s been possible to trigger browser actions by way of HTML events. Again, these are listed in full here and referred to for the relevant elements of the XHTML ele- ment table. In XHTML, all event names must be in lowercase (e.g., onclick, not onClick).

Core events

Attribute

Description

onclick=script

Specifies a script to be run when the user clicks the ele-
ment’s content area

ondblclick=script

Specifies a script to be run when the user double-clicks the
element’s content area

onkeydown=script

Specifies a script to be run when the user presses a key while
the element’s content area is focused

onkeypress=script

Specifies a script to be run when the user presses and
releases a key while the element’s content area is focused

onkeyup=script

Specifies a script to be run when the user releases a pressed
key while the element’s content area is focused

onmousedown=script

Specifies a script to be run when the user presses down
the mouse button while the cursor is over the element’s
content area

onmousemove=script

Specifies a script to be run when the user moves the mouse
cursor in the element’s content area

onmouseout=script

Specifies a script to be run when the user moves the mouse
cursor off the element’s content area

onmouseover=script

Specifies a script to be run when the user moves the mouse
cursor onto the element’s content area

onmouseup=script

Specifies a script to be run when the user releases the mouse
button on the element’s content area