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
Specifies a CSS class to define the element's visual appearance.
class=classname
Defines a unique reference ID for the element.
id=name
Sets an inline style. Deprecated in XHTML 1.1, so it should be
style=style
used sparingly and with caution.
(deprecated)
Specifies the element's title. Often used with links to provide a
title=string
tooltip expanding on the link's purpose or the target's content.
Not valid in these elements: base, head, html, meta, param, script, style, and title.
Keyboard attributes
Attribute Description
Defines a keyboard shortcut to access an element. The short-
accesskey=character
cut must be a single character. Most commonly used with
navigation links.
See also Chapter 5, "Using accesskey and tabindex."
Defines the tab order of an element. Most commonly used
tabindex=number
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).
See also Chapter 5, "Using accesskey and tabindex."
Language attributes
Attribute Description
Specifies the text rendering direction: left-to-right (ltr, the
dir=dir
default) or right-to-left (rtl).
Specifies the language for the tag's contents, using two-letter
lang=language
primary ISO639 codes and optional dialect codes. Included
(deprecated)
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).
Replaces lang in XHTML 1.1, but both should be used
xml:lang=language
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.
Not valid in these elements: base, br, frame, frameset, hr, iframe, param, and script.
Event attributes A
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
Specifies a script to be run when the user clicks the ele-
onclick=script
ment's content area
Specifies a script to be run when the user double-clicks the
ondblclick=script
element's content area
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
Specifies a CSS class to define the element's visual appearance.
class=classname
Defines a unique reference ID for the element.
id=name
Sets an inline style. Deprecated in XHTML 1.1, so it should be
style=style
used sparingly and with caution.
(deprecated)
Specifies the element's title. Often used with links to provide a
title=string
tooltip expanding on the link's purpose or the target's content.
Not valid in these elements: base, head, html, meta, param, script, style, and title.
Keyboard attributes
Attribute Description
Defines a keyboard shortcut to access an element. The short-
accesskey=character
cut must be a single character. Most commonly used with
navigation links.
See also Chapter 5, "Using accesskey and tabindex."
Defines the tab order of an element. Most commonly used
tabindex=number
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).
See also Chapter 5, "Using accesskey and tabindex."
Language attributes
Attribute Description
Specifies the text rendering direction: left-to-right (ltr, the
dir=dir
default) or right-to-left (rtl).
Specifies the language for the tag's contents, using two-letter
lang=language
primary ISO639 codes and optional dialect codes. Included
(deprecated)
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).
Replaces lang in XHTML 1.1, but both should be used
xml:lang=language
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.
Not valid in these elements: base, br, frame, frameset, hr, iframe, param, and script.
Event attributes A
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
Specifies a script to be run when the user clicks the ele-
onclick=script
ment's content area
Specifies a script to be run when the user double-clicks the
ondblclick=script
element's content area
Attribute Description
Specifies a script to be run when the user presses a key while
onkeydown=script
the element's content area is focused
Specifies a script to be run when the user presses and
onkeypress=script
releases a key while the element's content area is focused
Specifies a script to be run when the user releases a pressed
onkeyup=script
key while the element's content area is focused
Specifies a script to be run when the user presses down
onmousedown=script
the mouse button while the cursor is over the element's
content area
Specifies a script to be run when the user moves the mouse
onmousemove=script
cursor in the element's content area
Specifies a script to be run when the user moves the mouse
onmouseout=script
cursor off the element's content area
Specifies a script to be run when the user moves the mouse
onmouseover=script
cursor onto the element's content area
Specifies a script to be run when the user releases the mouse
onmouseup=script
button on the element's content area
Not valid in these elements: base, bdo, br, frame, frameset, head, html, iframe, meta,
param, script, style, and title.
Form element events
These events are generally restricted to form elements, although some other elements
accept some of them.
Attribute Description
Specifies a script to be run when the element loses focus
onblur=script
Specifies a script to be run when the element changes
onchange=script
Specifies a script to be run when the element is focused
onfocus=script
Specifies a script to be run when the user presses a key while
onkeydown=script
the element's content area is focused
Specifies a script to be run when the user presses and
onkeypress=script
releases a key while the element's content area is focused
Specifies a script to be run when the user releases a pressed
onkeyup=script
key while the element's content area is focused
Specifies a script to be run when the user presses down
onmousedown=script
the mouse button while the cursor is over the element's
content area
Specifies a script to be run when the user moves the mouse
onmousemove=script
cursor in the element's content area
Specifies a script to be run when the user moves the mouse
onmouseout=script
cursor off the element's content area
Specifies a script to be run when the user moves the mouse
onmouseover=script
cursor onto the element's content area
Specifies a script to be run when the user releases the mouse
onmouseup=script
button on the element's content area
Not valid in these elements: base, bdo, br, frame, frameset, head, html, iframe, meta,
param, script, style, and title.
Form element events
These events are generally restricted to form elements, although some other elements
accept some of them.
Attribute Description
Specifies a script to be run when the element loses focus
onblur=script
Specifies a script to be run when the element changes
onchange=script
Specifies a script to be run when the element is focused
onfocus=script
Attribute Description
Specifies a script to be run when a form is reset
onreset=script
Specifies a script to be run when the element is selected
onselect=script
Specifies a script to be run when a form is submitted
onsubmit=script
Window events
These events are valid only in the following elements: body and frameset.
Attribute Description
Specifies a script to be run when the document loads
onload=script
Specifies a script to be run when the document unloads
onunload=script
Although onresize is part of DOM2, it's not recognized by the XHTML specification. If an
onresize event is required, it cannot be applied directly to the body element. Instead,
you must declare it in the document head using window.onresize=functionName.
Specifies a script to be run when a form is reset
onreset=script
Specifies a script to be run when the element is selected
onselect=script
Specifies a script to be run when a form is submitted
onsubmit=script
Window events
These events are valid only in the following elements: body and frameset.
Attribute Description
Specifies a script to be run when the document loads
onload=script
Specifies a script to be run when the document unloads
onunload=script
Although onresize is part of DOM2, it's not recognized by the XHTML specification. If an
onresize event is required, it cannot be applied directly to the body element. Instead,
you must declare it in the document head using window.onresize=functionName.
No comments:
Post a Comment