XML technologies / HTML & XHTML / Common attributes and events

(Excerpt from "HTML & XHTML ─ kurz & gut" by Jennifer Niederst Robbins)

   

Several attributes can be used on almost all elements. We use the same abbreviations as the W3C recommendations. This page serves as a reference for the “Alphabetical list of HTML and XHTML elements” and explains the abbreviations for individual attributes.

In HTML 4.01 and XHTML 1.0, attributes and events belong to one of the groups Core, Internationalization (Internationalization), focus (Focus) and events. HTML 5 instead provides a set of global attributes (Global Attributes) applicable to all HTML elements.

HTML 4.01 and XHTML 1.0

Core

When the term Core appears under attributes, it means the core attributes applicable to most elements, as noted in each entry:

  • id

    Assigns a unique identifier to the element.

  • class

    Assigns one or more class names to the element.

  • style

    Assigns specific styling information (CSS) to an element.

  • title

    Contains a title or additional information about the element.

Internationalization

If the attribute list includes the term Internationalization the following language and reading-direction attributes can be defined for the element:

  • dir

    Specifies the element’s reading direction, left to right or the reverse.

  • lang

    Specifies an element’s language using a language code.

  • xml:lang

    XHTML only. Specifies the language of elements in an XHTML document.

focus

focus means that an element, such as a link or form control, is selected and ready for input. Where focus is specified, the following focus attributes and events can apply to the element:

  • accesskey="character"

    Assigns a keyboard shortcut to a link or form field. Its value is one character. Users can access the marked element using Alt-<Zeichen> (PC) or Ctrl-<Zeichen> (Mac).

  • onblur

    The element loses focus through pointer movement or pressing the Tab key.

  • onfocus

    The element receives focus through pointer movement or pressing the Tab key.

  • tabindex="Zahl"

    Specifies the element’s position in the document’s tab order. Valid values range from 0 to 32,767. With this attribute, users can move through links or form fields using the Tab key.

events

If events are listed for an element, the core scripting events apply. Other events outside the core are listed separately:

  • onclick

    An element is clicked.

  • ondblclick

    An element is double-clicked.

  • onkeydown

    A key is pressed while the element is active, for example after being clicked.

  • onkeypress

    A key is pressed and released while the element is active.

  • onkeyup

    A key is released while the element is active.

  • onmousedown

    A mouse button is held down over the element.

  • onmousemove

    The pointer moves while over the element.

  • onmouseout

    The pointer moves away from the element.

  • onmouseover

    The pointer moves onto the element.

  • onmouseup

    A mouse button is released over the element.

HTML 5

Global attributes

In addition to the attributes id, class, style, title, dir, lang, accesskey and tabindex, inherited from HTML 4.01, HTML 5 defines the following global attributes, applicable to all elements:

  • contenteditable="true|false"

    Indicates that the user can edit the element. Many current browsers already support this attribute.

  • contextmenu="ID des Menüelements"

    Refers to a context menu for the element. The user must invoke it, for example by right-clicking.

  • draggable="true|false"

    Specifies whether the element can be dragged and dropped to a new window position with the mouse.

  • hidden (hidden="hidden" in XHTML)

    Prevents the browser from displaying the element and its descendants. Scripts and form elements in the hidden portion still run but are not shown to the user.

  • itemid="Text"

    Part of the microdata system for embedding machine-readable data. The attribute itemid marks a globally recognized identifier, such as a book’s ISBN. It is used with the attribute itemtype in the same document, which also contains the attribute itemscope.

  • itemprop="Text"

    Part of the microdata system for embedding machine-readable data. The attribute itemprop specifies the name of aproperty. The element’s content determines the attribute value. The value can also be a URL specified by the attribute href in a a element or by the attribute src in the img element.

  • itemref="durch Leerzeichen getrennte Liste mit IDs"

    Part of the microdata system for embedding machine-readable data. The attribute itemref specifies elements on the current page, listed by ID, to include in an item. The attribute itemref must be used on the same element as the itemscope attribute declaring the item.

  • itemscope

    Part of the microdata system for embedding machine-readable data. The attribute itemscope creates a new item. This is a group of properties, or name/value pairs.

  • itemtype="URL oder umgekehrtes DNS-Label"

    Part of the microdata system for embedding machine-readable data. The attribute itemtype uses a URL ("http://vocab.example.net/book") or a reversed DNS label (for example "com.example.person") to identify a standardized item type. The attribute itemtype is used on the same element as the attribute itemscope.

  • spellcheck="true|false"

    Specifies whether spelling and grammar are checked for the element.

HTML 5 event handlers

Unless otherwise noted, the following event handlers can be used with any HTML 5 element:

onabort

onmessage*

onafterprint

onmousedown

onbeforeprint

onmousemove

onbeforeunload

onmouseout

onblur*

onmouseover

oncanplay

onmouseup

oncanplaythrough

onmousewheel

onchange

onoffline

onclick

ononline

oncontextmenu

onpagehide*

ondblclick

onpageshow*

ondrag

onpopstate*

ondragend

onpause

ondragenter

onplay

ondragleave

onplaying

ondragover

onprogress

ondragstart

onratechange

ondrop

onreadystatechange

ondurationchange

onredo*

onemptied

onresize*

onended

onscroll

onerror

onseeked

onfocus*

onseeking

onformchange

onselect

onforminput

onshow

oninput

onstalled

oninvalid

onsubmit

onkeydown

onsuspend

onkeypress

ontimeupdate

onkeyup

onundo*

onload*

onunload*

onloadeddata

onvolumechange

onloadedmetadata

onwaiting

onloadstart

Note: onblur, onerror, onfocus and onload behave slightly differently when applied to the body element element, since body inherits these event handlers from its parent window.

*Event handlers for the object Window, when used with the body element.

   

 

 

 

back to top