This specification defines the Document Object Model Events Level 3, a generic platform- and language-neutral event system which allows registration of event handlers, describes event flow through a tree structure, and provides basic contextual information for each event. The Document Object Model Events Level 3 builds on the Document Object Model Events Level 2 [DOM2 Events].

This document is a Working Draft of the Document Object Model Level 3 Events (DOM3 Events) specification. It is expected that this specification will progress to W3C Recommendation status after review and refinement.

This document is produced by the Web Applications WG, part of the Rich Web Clients Activity in the W3C Interaction Domain. It is expected that this document will progress along the W3C's Recommendation track. Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and MAY be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

You can find the latest Editor's Draft of this document in the W3C's Mercurial repository, which is updated on a regular basis.

Implementers should be aware that this document is not stable. Implementers who are not taking part in the discussions are likely to find the specification changing out from under them in incompatible ways. Vendors interested in implementing this document before it eventually reaches the Candidate Recommendation stage should join the aforementioned mailing lists and take part in the discussions.

Document Object Model Events

Introduction

DOM Events is designed with two main goals. The first goal is the design of an event system which allows registration of event listeners and describes event flow through a tree structure. Additionally, the specification will provide standard modules of events for user interface control and document mutation notifications, including defined contextual information for each of these event modules.

The second goal of DOM Events is to provide a common subset of the current event systems used in existing browsers. This is intended to foster interoperability of existing scripts and content. It is not expected that this goal will be met with full backwards compatibility. However, the specification attempts to achieve this when possible.

Conformance

This section is normative.

Within this specification, the key words MUST, MUST NOT, REQUIRED, SHALL, SHALL NOT, SHOULD, SHOULD NOT, RECOMMENDED, MAY, and OPTIONAL are to be interpreted as described in [RFC2119].

This specification is to be understood in the context of the DOM Level 3 Core specification [DOM3 Core] and the general considerations for DOM implementations apply. For example, handling of namespace URIs is discussed in XML Namespaces. For additional information about conformance, please see the DOM Level 3 Core specification [DOM3 Core]. A user agent is not required to conform to the entirety of another specification in order to conform to this specification, but it MUST conform to the specific parts of any other specification which are called out in this specification (e.g., a conforming DOM3 Events user agent MUST support the DOMString data type as defined in Web IDL, but need not support every method or data type defined in Web IDL in order to conform to DOM3 Events).

This specification defines several classes of conformance for different user agents, specifications, and content authors:

Web browsers and other dynamic or interactive user agents

A dynamic or interactive user agent, referred to here as a browser (be it a Web browser, AT (Accessibility Technology) application, or other similar program), conforms to DOM Level 3 Events if it supports the Core module defined in [DOM3 Core], the Event dispatch and DOM event flow mechanism, all the interfaces and events with their associated methods, attributes, and semantics defined in this specification with the exception of those marked as deprecated (a conforming user agent MAY implement the deprecated interfaces, events, or APIs for backwards compatibility, but is not required to do so in order to be conforming), and the complete set of character values and key values in the Key Value Tables (subject to platform availability), as well as all other normative requirements defined in this specification. A conforming browser MUST dispatch events appropriate to the given EventTarget when the conditions defined for that event type have been met.

A browser conforms specifically to the DOM Level 3 Events Architecture if it implements the DOM Event Architecture and Basic Event Interfaces, regardless of its support for any other event interfaces or event types defined in this specification. A browser conforms specifically to the DOM Level 3 Events Module if it implements the interfaces and its related event types specified in the Events Module, and to each event interface if it implements that interface and its related event types.

A conforming browser MUST support scripting, declarative interactivity, or some other means of detecting and dispatching events in the manner described by this specification, and MUST support the APIs specified for that event type.

In addition to meeting all other conformance criteria, a conforming browser MAY implement features of this specification marked as deprecated, for backwards compatibility with existing content, but such implementation is discouraged.

A conforming browser MAY also support features not found in this specification, but which use the Event dispatch and DOM event flow mechanism, interfaces, events, or other features defined in DOM Level 3 Events, and MAY implement additional interfaces and event types appropriate to that implementation. Such features can be later standardized in future specifications.

A browser which does not conform to all required portions of this specification MUST NOT claim conformance to DOM Level 3 Events. Such an implementation which does conform to portions of this specification MAY claim conformance to those specific portions.

A conforming browser MUST also be a conforming implementation of the IDL fragments in this specification, as described in the Web IDL specification. [WEBIDL]

Authoring tools

A content authoring tool conforms to DOM Level 3 Events if it produces content which uses the event types and Event dispatch and DOM event flow model, consistent in a manner as defined in this specification. A content authoring tool MUST NOT claim conformance to DOM Level 3 Events for content it produces which uses features of this specification marked as deprecated in this specification. A conforming content authoring tool SHOULD provide to the content author a means to use all event types and interfaces appropriate to all host languages in the content document being produced.

Content authors and content

A content author creates conforming DOM Level 3 Events content if that content uses the event types and Event dispatch and DOM event flow model, consistent in a manner as defined in this specification. A content author SHOULD NOT use features of this specification marked as deprecated, but SHOULD rely instead upon replacement mechanisms defined in this specification and elsewhere. Conforming content MUST use the semantics of the interfaces and event types as described in this specification.

Authoring Note: Content authors are advised to follow best practices as described in accessibility and internationalization guideline specifications.

Specifications and host languages

A specification or host language conforms to DOM Level 3 Events if it references and uses the Event dispatch and DOM event flow mechanism, interfaces, events, or other features defined in this specification, and does not extend these features in incompatible ways. A specification or host language conforms specifically to the DOM Level 3 Events Architecture if it references and uses the DOM Event Architecture and Basic Event Interfaces, regardless of its use of any other event interfaces or event types defined in this specification.

A specification or host language conforms specifically to the DOM Level 3 Events Module if it references and uses the interfaces and its related event types specified in the Events Module, and to each event interface if it references and uses that interface and its related event types. A conforming specification MAY define additional interfaces and event types appropriate to that specification, or MAY extend the DOM Level 3 Events interfaces and event types in a manner that does not contradict or conflict with the definitions of those interfaces and event types in this specification.

Specifications or host languages which reference DOM Level 3 Events SHOULD NOT use or recommend features of this specification marked as deprecated, but SHOULD use or recommend the indicated replacement for that the feature (if available).

Stylistic Conventions

The following stylistic conventions are followed in this specification, per the Proposed W3C Specification Conventions:

Keywords or values
This is a keyword or value
Event types
This is an event type
Key and character values
This is a key name: '=' (e.g., the value of KeyboardEvent.key). This is the equivalent character value: '\u003d'. This is a glyph that represents that same character value: '='.
Glossary definitions
This is a link to a definition in the glossary
Notes

Note: This is a note.

Warnings

Warning! This is a warning. It is used on security notes and to mark deprecated features.

Examples

This is an example.

Spec Issues

This is an open issue.

In addition, certain terms are used in this specification with particular meanings. The term implementation applies to a browser, content authoring tool, or other user agent that implements this specification, while a content author is a person who writes script or code that takes advantage of the interfaces, methods, attributes, events, and other features described in this specification in order to make Web applications, and a user is the person who uses those Web applications in an implementation.

Glossary

Some of the following term definitions have been borrowed or modified from similar definitions in other W3C or standards documents. See the links within the definitions for more information.

activation behavior
The action taken when an event, typically initiated by users through an input device, causes an element to fulfill a defined task. The task MAY be defined for that element by the host language, or by author-defined variables, or both. The default task for any given element MAY be a generic action, or MAY be unique to that element. For example, the activation behavior of an HTML or SVG <a> element is to cause the user agent to traverse the link specified in the href attribute, with the further optional parameter of specifying the browsing context for the traversal (such as the current window or tab, a named window, or a new window). The activation behavior of an HTML <input> element with the type attribute value submit is be to send the values of the form elements to an author-defined IRI by the author-defined HTTP method. See Activation triggers and behavior for more details.
activation trigger
An event which is defined to initiate an activation behavior. Refer to Activation triggers and behavior for more details.
author
In the context of this specification, an author, content author, or script author is a person who writes script or other executable content that uses the interfaces, events, and event flow defined in this specification. See Content authors and content conformance category for more details.
bubbling phase
The process by which an event can be handled by one of the target's ancestors after being handled by the event target. See the description of the bubble phase in the context of event flow for more details.
capture phase
The process by which an event can be handled by one of the target's ancestors before being handled by the event target. See the description of the capture phase in the context of event flow for more details.
character value
In the context of key values, a character value is a string representing one or more Unicode characters, such as a letter or symbol, or a set of letters. In this specification, character values are denoted as a unicode string (e.g., '\u0020') or a glyph representation of the same code point (e.g., ' '), and are color coded to help distinguish these two representations.

Note: In source code, some key values, such as non-graphic characters, can be represented using the character escape syntax of the programming language in use.

candidate event handlers
candidate event listeners
The list of all event listeners that have been registered on the target object in their order of registration. This list is captured or frozen before event listeners on the target object are dispatched, and released or un-frozen after this set of candidate event handlers have been dispatched (allowing these event listeners to add or remove additional listeners on other objects in an event's propagation chain, but not affect the order of listeners that will be invoked on the target object).

Note: Initially capturing the candidate event handlers prevents infinite loops of event listener dispatch on a given target object.

current event target
In an event flow, the current event target is the object associated with the event handler that is currently being dispatched. This object MAY be the event target itself or one of its ancestors. The current event target changes as the event propagates from object to object through the various phases of the event flow. The current event target is the value of the Event.currentTarget attribute.
dead key
A dead key is a key or combination of keys which produces no character by itself, but which in combination or sequence with another key produces a modified character, such as a character with diacritical marks (e.g., ö, é, â).
default action
A default action is an OPTIONAL supplementary behavior that an implementation MUST perform in combination with the dispatch of the event object. Each event type definition, and each specification, defines the default action for that event type, if it has one. An instance of an event MAY have more than one default action under some circumstances, such as when associated with an activation trigger. A default action MAY be cancelled through the invocation of the Event.preventDefault() method. For more details, see Default actions and cancelable events.
delta
The estimated scroll amount (in pixels, lines, or pages) that the user agent will scroll or zoom the page in response to the physical movement of an input device that supports the WheelEvent interface (such as a mouse wheel or touch pad). The value of a delta (e.g., the deltaX, deltaY, or deltaZ attributes) is to be interpreted in the context of the current deltaMode property. The relationship between the physical movement of a wheel (or other device) and whether the delta is positive or negative is environment and device dependent. However, if a user agent scrolls as the default action then the sign of the delta is given by a right-hand coordinate system where positive X,Y, and Z axes are directed towards the right-most edge, bottom-most edge, and farthest depth (away from the user) of the document, respectively.
deprecated
Features marked as deprecated are included in the specification as reference to older implementations or specifications, but are OPTIONAL and discouraged. Only features which have existing or in-progress replacements MUST be deprecated in this specification. Implementations which do not already include support for the feature MAY implement deprecated features for reasons of backwards compatibility with existing content, but content authors creating content SHOULD NOT use deprecated features, unless there is no other way to solve a use case. Other specifications which reference this specification SHOULD NOT use deprecated features, but SHOULD point instead to the replacements of which the feature is deprecated in favor. Features marked as deprecated in this specification are expected to be dropped from future specifications.
dispatch
To create an event with attributes and methods appropriate to its type and context, and propagate it through the DOM tree in the specified manner. Interchangeable with the term fire, e.g., fire a click event or dispatch a load event.
document
An object instantiating the Document interface [DOM3 Core], representing the entire HTML or XML text document. Conceptually, it is the root of the document tree, and provides the primary access to the document's data.
DOM application
A DOM application is script or code, written by a content author or automatically generated, which takes advantage of the interfaces, methods, attributes, events, and other features described in this specification in order to make dynamic or interactive content, such as Web applications, exposed to users in a user agent.
DOM Level 0
The term DOM Level 0 refers to a mix of HTML document functionalities, often not formally specified but traditionally supported as de facto standards, implemented originally by Netscape Navigator version 3.0 or Microsoft Internet Explorer version 3.0. In many cases, attributes or methods have been included for reasons of backward compatibility with DOM Level 0.
empty string
The empty string is a value of type DOMString of length 0, i.e., a string which contains no characters (neither printing nor control characters).
event
An event is the representation of some occurrence (such as a mouse click on the presentation of an element, the removal of child node from an element, or any number of other possibilities) which is associated with its event target. Each event is an instantiation of one specific event type.
event focus
Event focus is a special state of receptivity and concentration on an particular element or other event target within a document. Each element has different behavior when focused, depending on its functionality, such as priming the element for activation (as for a button or hyperlink) or toggling state (as for a checkbox), receiving text input (as for a text form field), or copying selected text. For more details, see Document Focus and Focus Context.
event focus ring
An event focus ring is an ordered set of event focus targets within a document. A host language MAY define one or more ways to determine the order of targets, such as document order, a numerical index defined per focus target, explicit pointers between focus targets, or a hybrid of different models. Each document MAY contain multiple focus rings, or conditional focus rings. Typically, for document-order or indexed focus rings, focus wraps around from the last focus target to the first.
event handler
event listener
An object that implements the EventListener interface and provides an EventListener.handleEvent() callback method. Event handlers are language-specific. Event handlers are invoked in the context of a particular object (the current event target) and are provided with the event object itself.

Note: In JavaScript, user-defined functions are considered to implement the EventListener interface. Thus the Event object will be provided as the first parameter to the user-defined function when it is invoked. Additionally, JavaScript objects can also implement the EventListener interface when they define a handleEvent method.

event order
The sequence in which events from the same event source or process occur, using the same or related event interfaces. For example, in an environment with a mouse, a track pad, and a keyboard, each of those input devices would constitute a separate event source, and each would follow its own event order. A mousedown event from the trackpad followed by a mouseup event from the mouse would not result in a click event.

Note: There can be interactions between different event orders. For example, a click event might be modified by a concurrent keydown event ('Shift'+click). However, the event orders of these different event sources would be distinct.

The event order of some interfaces are device-independent. For example, a user might change focus using the 'Tab' key, or by clicking the new focused element with the mouse. The event order in such cases depends on the state of the process, not on the state of the device that initiates the state change.
event phase
See phase.
event target
The object to which an event is targeted using the DOM event flow. The event target is the value of the Event.target attribute.
event type
An event type is an event object with a particular name and which defines particular trigger conditions, properties, and other characteristics which distinguish it from other event types. For example, the click event type has different characteristics than the mouseover or load event types. The event type is exposed as the Event.type attribute on the event object. See event types for more details. Also loosely referred to as 'event', such as the click event.
fire
A synonym for dispatch.
host language
Any language which integrates the features of another language or API specification, while normatively referencing the origin specification rather than redefining those features, and extending those features only in ways defined by the origin specification. An origin specification typically is only intended to be implemented in the context of one or more host languages, not as a standalone language. For example, XHTML, HTML, and SVG are host languages for DOM 3 Events, and they integrate and extend the objects and models defined in this specification.
hysteresis
A feature of human interface design to accept input values within a certain range of location or time, in order to improve the user experience. For example, allowing for small deviation in the time it takes for a user to double-click a mouse button is temporal hysteresis, and not immediately closing a nested menu if the user mouses out from the parent window when transitioning to the child menu is locative hysteresis.
IME
input method editor
An input method editor (IME), also known as a front end processor, is an application that performs the conversion between keystrokes and ideographs or other characters, usually by user-guided dictionary lookup, often used in East Asian languages (e.g., Chinese, Japanese, Korean). An IME MAY also be used for dictionary-based word completion, such as on mobile devices. See Input Method Editors for treatment of IMEs in this specification. See also text composition system.
key value
A key value is a character value or multi-character string (such as 'Enter' , 'Tab', or 'MediaTrackNext') associated with a key in a particular state. Every key has a key value, whether or not it has a character value. This includes control keys, function keys, modifier keys, dead keys, and any other key. The key value of any given key at any given time depends upon the key mapping.
key mapping
Key mapping is the process of assigning a key value to a particular key, and is the result of a combination of several factors, including the operating system and the keyboard layout (e.g., QWERTY, Dvorak, Spanish, InScript, Chinese, etc.), and after taking into account all modifier key ('Shift', 'Alt', etc.) and dead key states.
local name
See local name in [XML Namespaces 1.0].
modifier key
A modifier key changes the normal behavior of a key, such as to produce a character of a different case (as with the 'Shift' key), or to alter what functionality the key triggers (as with the 'Fn' or 'Alt' keys). Refer to the KeyboardEvent.getModifierState() method for a list of modifier keys defined in this specification. See also Modifier keys.
namespace URI
A namespace URI is a URI that identifies an XML namespace. This is called the namespace name in [XML Namespaces 1.0]. See also sections 1.3.2 DOM URIs and 1.3.3 XML Namespaces regarding URIs and namespace URIs handling and comparison in the DOM APIs.
phase
In the context of events, a phase is set of logical traversals from node to node along the DOM tree, from the Window to the Document object, root element, and down to the event target (capture phase), at the event target itself (target phase), and back up the same chain (bubbling phase).
propagation path
The ordered set of current event targets though which an event object will pass sequentially on the way to and back from the event target. As the event propagates, each current event target in the propagation path is in turn set as the Event.currentTarget. The propagation path is initially composed of one or more event phases as defined by the event type, but MAY be interrupted. Also known as an event target chain.
QWERTY
QWERTY (pronounced ˈkwɜrti) is a common keyboard layout, so named because the first five character keys on the top row of letter keys are Q, W, E, R, T, and Y. There are many other popular keyboard layouts (including the Dvorak and Colemak layouts), most designed for localization or ergonomics.
root element
The first element node of a document, of which all other elements are children. The document element.
rotation
An indication of incremental change on an input device using the WheelEvent interface. On some devices this MAY be a literal rotation of a wheel, while on others, it MAY be movement along a flat surface, or pressure on a particular button.
text composition system
A software component that interprets some form of alternate input (such as a input method editor, a speech processor, or a handwriting recognition system) and converts it to text.
target phase
The process by which an event can be handled by the event target. See the description of the target phase in the context of event flow for more details.
topmost event target
The topmost event target MUST be the element highest in the rendering order which is capable of being an event target. In graphical user interfaces this is the element under the user's pointing device. A user interface's hit testing facility is used to determine the target. For specific details regarding hit testing and stacking order, refer to the host language.
tree
A data structure that represents a document as a hierarchical set of nodes with child-parent-sibling relationships, i.e., each node having one or more possible ancestors (nodes higher in the hierarchy in a direct lineage), one or more possible descendants (nodes lower in the hierarchy in a direct lineage), and one or more possible peers (nodes of the same level in the hierarchy, with the same immediate ancestor).
Unicode character categories
A subset of the General Category values that are defined for each Unicode code point. This subset contains all the Letter (Ll, Lm, Lo, Lt, Lu), Number (Nd, Nl, No), Punctuation (Pc, Pd, Pe, Pf, Pi, Po, Ps) and Symbol (Sc, Sk, Sm, So) category values.
Unicode code point
A Unicode code point is a unique hexadecimal number signifying a character by its index in the Unicode codespace (or library of characters). In the context of key values, a Unicode code point is expressed as a string in the format \u followed by a hexadecimal character index in the range 0000 to 10FFFF, using at least four digits. See also character value.
un-initialized value
The value of any event attribute (such as Event.bubbles or Event.currentTarget) before the event has been initialized with Event.initEvent(). The un-initialized values of an Event apply immediately after a new event has been created using the method DocumentEvent.createEvent().
user agent
A program, such as a browser or content authoring tool, normally running on a client machine, which acts on a user's behalf in retrieving, interpreting, executing, presenting, or creating content. Users MAY act on the content using different user agents at different times, for different purposes. See the Web browsers and other dynamic or interactive user agents and Authoring tools for details on the requirements for a conforming user agent.
Window
The Window is the object referred to by the current document's browsing context's Window Proxy object as defined in HTML5 [HTML5].

DOM Event Architecture

Event dispatch and DOM event flow

This section defines the event dispatch mechanism of the event model defined in this specification. Applications MAY dispatch event objects using the EventTarget.dispatchEvent() method, and implementations MUST dispatch event objects as if through this method. The behavior of this method depends on the event flow associated with the underlying object. An event flow describes how event objects propagate through a data structure. As an example, when an event object is dispatched to an element in an XML document, the object propagates through parts of the document, as determined by the DOM event flow which is defined at the end of this section.

Graphical representation of an event dispatched in a DOM tree using the DOM event flow

Event objects are dispatched to an event target. At the beginning of the dispatch, implementations MUST first determine the event object's propagation path.

The propagation path MUST be an ordered list of current event targets through which the event object MUST pass. For DOM implementations, the propagation path MUST reflect the hierarchical tree structure of the document. The last item in the list MUST be the event target. The preceding items in the list are referred to as the target's ancestors, and the immediately preceding item as the target's parent. Once determined, the propagation path MUST NOT be changed. For DOM implementations, this applies even if an element in the propagation path is moved within the DOM or removed from the DOM.

In the DOM event flow, event listeners might change the position of the event target in the document while the event object is being dispatched. Such changes do not affect the propagation path.

Exceptions thrown inside event listeners MUST NOT stop the propagation of the event or affect the propagation path. The exception itself MUST NOT propagate outside the scope of the event handler.

In the following code, the exception thrown from the call to throw "Error" does not propagate into the parent scope (which would prevent the console.log statement from executing):

var e = document.createEvent("Event");
e.initEvent("myevent", false, false);
var target = document.createElement("div");
target.addEventListener("myevent", function () {
   throw "Error";
});
target.dispatchEvent(e); // Causes the event listener to throw an exception...
// The previously thrown exception doesn't affect the code that follows:
console.log("Exceptions? No problem");

As the next step, the event object MUST complete one or more event phases. This specification defines three event phases: capture phase, target phase and bubble phase. Event objects complete these phases in the specified order using the partial propagation paths as defined below. A phase MUST be skipped if it is not supported, or if the event object's propagation has been stopped. For example, if the Event.bubbles attribute is set to false, the bubble phase will be skipped, and if Event.stopPropagation() has been called prior to the dispatch, all phases MUST be skipped.

  1. The capture phase: The event object MUST propagate through the target's ancestors from the Window to the target's parent. This phase is also known as the capturing phase. Event listeners registered for this phase MUST handle the event before it reaches its target.
  2. The target phase: The event object MUST arrive at the event object's event target. This phase is also known as the at-target phase. Event listeners registered for this phase MUST handle the event once it has reached its target. If the event type indicates that the event MUST NOT bubble, the event object MUST halt after completion of this phase.
  3. The bubble phase: The event object propagates through the target's ancestors in reverse order, starting with the target's parent and ending with the Window. This phase is also known as the bubbling phase. Event listeners registered for this phase MUST handle the event after it has reached its target.

Implementations MUST let event objects accomplish an event phase by applying the following steps while there are pending event targets in the partial propagation path for this phase and the event object's propagation has not been stopped through Event.stopPropagation().

First, the implementation MUST determine the current target. This MUST be the next pending event target in the partial propagation path, starting with the first. From the perspective of an event listener this MUST be the event target the listener has been registered on.

Next, the implementation MUST determine the current target's candidate event listeners. This MUST be the list of all event listeners that have been registered on the current target in their order of registration. [HTML5] defines the ordering of listeners registered through event handler attributes. Once determined, the candidate event listeners MUST NOT be changed. Adding or removing listeners does not affect the current target's candidate event listeners.

Finally, the implementation MUST process all candidate event handlers in order and trigger each handler if all the following conditions are met:

In the production of the propagation path, the event propagates from the Window to the document object during the capture phase, and from the document object to the Window during the bubble phase.

After an event completes all the phases of its propagation path, its Event.currentTarget MUST be set to null and the Event.eventPhase MUST be set to 0 (NONE). All other attributes of the Event (or interface derived from Event) are unchanged (including the Event.target attribute, which MUST continue to reference the event target).

The model defined above MUST be applied regardless of the specific event flow associated with an event target. Each event flow MUST define how the propagation path MUST be determined and which event phases are supported. The DOM event flow is an application of this model: the propagation path for a Node object MUST be determined by its Node.parentNode chain, and if applicable, the document's containing Window. All events accomplish the capture and target phases. Whether an event accomplishes the bubble phase MUST be defined individually for each event type. An alternate application of this model can be found in [DOM3 Load and Save].

Implementations of the DOM event model MUST be reentrant. Event listeners MAY perform actions that cause additional events to be dispatched. Such events are handled in a synchronous manner, the event propagation that causes the event listener to be triggered MUST resume only after the event dispatch of the new event is completed.

Default actions and cancelable events

Events are typically dispatched by the implementation as a result of a user action, in response to the completion of a task, or to signal progress during asynchronous activity (such as a network request). Some events can be used to control the behavior that the implementation MAY take next (or undo an action that the implementation already took). Events in this category are said to be cancelable and the behavior they cancel is called their default action. Cancelable event objects can be associated with one or more default actions. To cancel an event, call the Event.preventDefault() method.

A mousedown event is dispatched immediately after the user presses down a button on a pointing device (typically a mouse). One possible default action taken by the implementation is to set up a state machine that allows the user to drag images or select text. The default action depends on what happens next — for example, if the user's pointing device is over text, a text selection might begin. If the user's pointing device is over an image, then an image-drag action could begin. Preventing the default action of a mousedown event prevents these actions from occuring.

Default actions SHOULD be performed after the event dispatch has been completed, but in exceptional cases MAY also be performed immediately before the event is dispatched.

The default action associated with the click event on <input type="checkbox"> elements toggles the checked IDL attribute value of that element. If the click event's default action is cancelled, then the value is restored to its former state.

When an event is canceled, then the conditional default actions associated with the event MUST be skipped (or as mentioned above, if the default actions are carried out before the dispatch, their effect MUST be undone). Whether an event object is cancelable MUST be indicated by the Event.cancelable attribute. Event.preventDefault() stops all related default actions of an event object. The Event.defaultPrevented attribute indicates whether an event has already been canceled (e.g., by a prior event listener). If the DOM application itself initiated the dispatch, then the return value of the EventTarget.dispatchEvent() method indicates whether the event object was cancelled.

Authoring Note: Many implementations additionally interpret an event listener's return value, such as the value false, to mean that the default action of cancelable events will be cancelled (though window.onerror handlers are cancelled by returning true).

Authoring Note: Some cancelable events might not have any observable default actions. For example, the mousemove event.

This specification does not offer features to programatically query if an event object has any default action associated with it, or to associate new default actions with an event object. Other specifications SHOULD define what default actions, if any, are associated with certain event objects. Further, implementations MAY associate default actions with events as necessary and appropriate for that implementation.

As an example, one implementation might scroll a document view by a certain amount as the default action of a wheel event, while another implementation might instead zoom the document as its default action.

Synchronous and asynchronous events

Events MAY be dispatched either synchronously or asynchronously.

Events which are synchronous (sync events) MUST be treated as if they are in a virtual queue in a first-in-first-out model, ordered by sequence of temporal occurrence with respect to other events, to changes in the DOM, and to user interaction. Each event in this virtual queue MUST be delayed until the previous event has completed its propagation behavior, or been canceled. Some sync events are driven by a specific device or process, such as mouse button events. These events are governed by the event order algorithms defined for that set of events, and a user agent MUST dispatch these events in the defined order.

A user double-clicks a passage of text to select a word, then presses the 'Delete' key to erase the word, triggering the following synchronous sequence of events: mousedown, mouseup, click, mousedown, mouseup, click, dblclick, select, keydown, beforeinput, input, keyup. Each of these events are fired in the sequence initiated by the user's actions.

Events which are asynchronous (async events) MAY be dispatched as the results of the action are completed, with no relation to other events, to other changes in the DOM, nor to user interaction.

During loading of a document, an inline script element is parsed and executed. The load event is queued to be fired asynchronously at the script element. However, because it is an async event, its order with relation to other synchronous events fired during document load (such as the DOMContentLoaded event from HTML5) is not guaranteed.

Event order and event loops

Most events take place in a sequential context. [HTML5] defines its event operations in terms of an event loop mechanism, in which events of all types are fed into different task queues. This specification does not define events in terms of this event loop mechanism, but it is compatible with this mechanism. Instead, this specification defines several operation-specific event orders.

Using the terminology of HTML5, each independent device, such as a mouse or keyboard, SHOULD be treated as a task source which feeds into the appropriate task queue, in the order defined by the event order associated with that device. Each operation, such as a focus change or composition input, also acts as a task source for the appropriate task queue. The resolution of these event loops is handled in a manner conforming to the host language, such as HTML [HTML5].

Authoring Note: Certain events, such as hotkeys or control keys pressed in a certain sequence, can be swallowed by the operating system or the application, interrupting the expected event order.

Trusted events

Events that are generated by the user agent, either as a result of user interaction, or as a direct result of changes to the DOM, are trusted by the user agent with privileges that are not afforded to events generated by script through the DocumentEvent.createEvent("Event") method, modified using the Event.initEvent() method, or dispatched via the EventTarget.dispatchEvent() method. The isTrusted attribute of trusted events has a value of true, while untrusted events have a isTrusted attribute value of false.

Most untrusted events SHOULD NOT trigger default actions, with the exception of click or DOMActivate events. These events trigger the default action of an activation trigger (see Activation triggers and behaviors for more details). These untrusted events have an isTrusted attribute value of false, but still initiate any default actions for backwards compatibility. All other untrusted events MUST behave as if the Event.preventDefault() method had been called on that event.

Activation triggers and behavior

Certain event targets (such as a link or button element) MAY have associated activation behavior (such a following a link) that implementations perform in response to an activation trigger (such as clicking a link).

A host language SHOULD indicate which, if any, elements have activation behavior, describe appropriate activation triggers, and define the result of that activation behavior. An implementation which supports a host language SHOULD initiate these activation behavior when the associated activation trigger occurs.

Both HTML and SVG have an <a> element which indicates a link. Relevant activation triggers for an <a> element are a click event on the text or image content of the <a> element, or a keydown event with a key attribute value of 'Enter' key when the <a> element has focus. The activation behavior for an <a> element is normally to change the content of the window to the content of the new document, in the case of external links, or to reposition the current document relative to the new anchor, in the case of internal links.

An activation trigger is a user action or an event which indicates to the implementation that an activation behavior SHOULD be initiated. User-initiated activation triggers include clicking a mouse button on an activatable element, pressing the 'Enter' key when an activatable element has focus, or pressing a key that is somehow linked to an activatable element (a hotkey or access key) even when that element does not have focus. Event-based activation triggers MAY include timer-based events that activate an element at a certain clock time or after a certain time period has elapsed, progress events after a certain action has been completed, or many other condition-based or state-based events.

In some cases, a host language MAY define attributes or even attribute values which add to or change the native activation trigger or activation behavior of an element. For example, ARIA [ARIA] defines values for the role attribute that add semantics to the element to which it is applied, for purposes of enhanced accessibility. In such cases, if the host language does not explicitly define the activation trigger or activation behavior, the content author MUST provide the mechanics of the activation trigger (via an event listener) or activation behavior (such as calling an ECMAScript function) for that element when applying that attribute or attribute value.

Activation event synthesis

If the instance of the activation trigger is not an event of event type click (that is, when it does not result from a user's activation of a button or link using a mouse or equivalent pointing device), the implementation MUST synthesize and dispatch an event of event type click as one of the default actions of that activation trigger. The value of the Event.target MUST be set to the event target (normally, the currently focused element), and the event MUST simulate a left click (i.e., the MouseEvent.button attribute value MUST be 0, and the MouseEvent.buttons attribute value MUST be 1). Other context information of such a simulated click event is implementation dependent, but for historical purposes, the interface for the click event MUST be the MouseEvent interface, regardless of the actual device used to activate the element. Preventing the default action of the activation trigger, such as with the Event.preventDefault(), MUST stop the initiation of the activation behavior.

When a user activates a hyperlink using a keyboard, such as by focusing the hyperlink element and pressing the 'Enter' or ' ' key, a click event would be dispatched as the default action of the respective keydown event.

Implementations MUST dispatch the synthesized click event as described above even if they do not normally dispatch such an event (e.g., when activation is requested by a voice command, since this specification does not address event types for voice input).

Note: The activation of an event target is device dependent, but is also application dependent, e.g., a link in a document can be activated using a mouse click or a mouse double click.

Activation event order

Activation triggers and behavior can be defined in part by the events which are dispatched in a set order relative to one another. The following is the typical sequence of events for an element activated by a pointing device (with only pertinent events listed):

1. click
2. All default actions, including the activation behavior

The following is the typical sequence of events when a focused element is activated by a key event (with only pertinent events listed):

1. keydown MUST be a key which can activate the element, such as the 'Enter' or ' ' key, or the element is not activated
2. click default action; synthesized; trusted="false"
3. All default actions, including the activation behavior

Event exceptions

This section is informative.

Event operations can throw a DOMException as specified in their method descriptions.

Note: The exception EventException introduced in DOM Level 2 is removed in this specification as part of this specification's normative support of Web IDL. EventException formerly defined an exception code UNSPECIFIED_EVENT_TYPE_ERR which is replaced in this specification by the use of a DOMException of type InvalidStateError.

The following DOMException types are used in this specification.

Type Description
InvalidStateError Thrown when the Event.type was not specified by initializing the event before dispatchEvent was called. Also thrown when the Event object provided to dispatchEvent is already being dispatched.
NotSupportedError Thrown when DocumentEvent.createEvent() is passed an Event interface that the implementation does not support.

Basic Event Interfaces

The interfaces described in this section are fundamental to DOM Level 3 Events and MUST always be supported by the implementation.

The event types defined in this specification derive from these basic interfaces, and MUST inherit all of the attributes, methods, and constants of the interfaces they derive from. Event types defined in other specifications MAY similarly inherit from these basic interfaces or other interfaces defined in this specification, or MAY define their own interfaces. The following chart describes the inheritance structure of interfaces defined in this specification.

Graphical representation of the DOM3 Events interface inheritance

Need to add InputEvent to this diagram.

Interface Event

Introduced in DOM Level 2

The Event interface provides basic contextual information about an event to all registered event handlers. Specific events can also implement other derived interfaces, for example the UIEvent and MouseEvent interfaces.

To create an instance of the Event interface, use the DocumentEvent.createEvent("Event") method call.

boolean bubbles = false
boolean cancelable = false
// PhaseType
const unsigned short NONE = 0

The current event is not being dispatched, i.e., the Event.eventPhase is being observered prior to calling EventTarget.dispatchEvent() or following the completion of the event phases of a given Event.

const unsigned short CAPTURING_PHASE = 1

The current event phase is the capture phase.

const unsigned short AT_TARGET = 2

The current event is in the target phase, i.e., it is being evaluated at the event target.

const unsigned short BUBBLING_PHASE = 3

The current event phase is the bubbling phase.

readonly attribute DOMString type

The name of the event type. Specifications that define events, content authors, and authoring tools MUST use case-sensitive event type names.

The un-initialized value of this attribute MUST be "" (the empty string).

readonly attribute EventTarget? target

Used to retrieve the event target associated with the Event dispatch and DOM event flow.

The un-initialized value of this attribute MUST be null.

readonly attribute EventTarget? currentTarget

Used to retrieve the current event target whose EventListeners are currently being processed. This is particularly useful during the capture and bubbling phases.

The un-initialized value of this attribute MUST be null.

readonly attribute unsigned short eventPhase

Used to indicate the phase of the event's current propagation path (capture, target, or bubble). The event flow phases are defined in Event dispatch and DOM event flow.

The un-initialized value of this attribute MUST be 0 (NONE).

readonly attribute boolean bubbles

Used to indicate whether or not an event is a bubbling event. If the event can bubble the value MUST be true, otherwise the value MUST be false.

The un-initialized value of this attribute MUST be false.

readonly attribute boolean cancelable

Used to indicate whether or not an event can have its default action prevented. If the default action can be prevented the value MUST be true, otherwise the value MUST be false. See Default actions and cancelable events for more information on cancelable events.

The un-initialized value of this attribute MUST be false.

Note: Use Event.defaultPrevented to see whether a cancelable event has been cancelled or not.

readonly attribute DOMTimeStamp timeStamp

Used to specify the time at which the event was created in milliseconds relative to 1970-01-01T00:00:00Z. This value is the un-initialized value of this attribute.

void stopPropagation()

Prevents all other event listeners from being triggered for this event dispatch, excluding any remaining candidate event listeners. Once it has been called, further calls to this method have no additional effect.

Note: This method does not prevent the default action from being invoked — use Event.preventDefault() for that effect.

void preventDefault()

When this method is invoked, the event MUST be canceled, meaning any default actions normally taken by the implementation as a result of the event MUST NOT occur. Default actions which occur prior to the event's dispatch are reverted. Calling this method for a non-cancelable event MUST have no effect. If an event has more than one default action, each cancelable default action MUST be canceled. See Default actions and cancelable events for more information on cancelable events.

Note: This method does not stop the event propagation — use Event.stopPropagation() or Event.stopImmediatePropagation() for that effect.

void initEvent()

Initializes attributes of an Event. The Event could have been created through the DocumentEvent.createEvent method or by the implementation in response to a user action. For any Event created with the DocumentEvent.createEvent method, this method MUST be called before the Event is dispatched via the EventTarget.dispatchEvent() method. If the method is called several times before invoking EventTarget.dispatchEvent, only the final invocation takes precedence. If this method is called during an invocation of EventTarget.dispatchEvent, this method MUST do nothing and return immediately. If called from a subclass of the Event interface only the values specified in this method are modified, all other attributes are left unchanged.

This method MUST also reset the event object's internal-propagation and default-action-prevention states. This allows an event object to be "reset" before being dispatched multiple times.

If an EventListener called stopPropagation() or stopImmediatePropagation() during the event's previous dispatch, then after calling this method, the event can be re-dispatched (via dispatchEvent) and will propagate through all candidate event listeners along its propagation path (as it did during the prior dispatch). Similarly, if an EventListener called preventDefault() during the event's previous dispatch, then after calling this method, the event's defaultPrevented property will be false.

Warning! For security reasons, events modified using Event.initEvent() MUST have a isTrusted attribute value of false. See trusted events for more details.

Authoring Note: Trusted events can have their event type and other attributes changed using this method. However, this method always converts the Event from a trusted event to an untrusted event (e.g., the Event.isTrusted attribute will return false).

Authoring Note: Trusted events are pre-initialized by the implementation before being dispatched. As a result, it is not necessary to call Event.initEvent() prior to re-dispatching the trusted event — however calling EventTarget.dispatchEvent() will convert the Event from a trusted event to an untrusted event (e.g., the Event.isTrusted attribute will return false).

DOMString eventTypeArg

Specifies Event.type, the name of the event type.

boolean bubblesArg

Specifies Event.bubbles. This parameter overrides the intrinsic bubbling behavior of the event.

boolean cancelableArg

Specifies Event.cancelable. This parameter overrides the intrinsic cancelable behavior of the event.

// Introduced in DOM Level 3
void stopImmediatePropagation()

Introduced in DOM Level 3

Prevents all other event listeners from being triggered for this event dispatch, including any remaining candidate event listeners. Once it has been called, further calls to this method have no additional effect.

Note: This method does not prevent the default action from being invoked — use Event.preventDefault() for that effect.

readonly attribute boolean defaultPrevented

Introduced in DOM Level 3

Used to indicate whether this event has been cancelled or not. Event.defaultPrevented MUST return true if both Event.cancelable is true and Event.preventDefault() has been called for this event. Otherwise this attribute MUST return false.

The un-initialized value of this attribute MUST be false.

Note: Calling Event.initEvent() after an event has been dispatched will reset the internal default-prevented state of the event.

readonly attribute boolean isTrusted

Introduced in DOM Level 3

Used to indicate whether this event was generated by the user agent (trusted) or by script (untrusted). See trusted events for more details.

The un-initialized value of this attribute MUST be false.

Interface CustomEvent

Introduced in DOM Level 3

The CustomEvent interface is the RECOMMENDED interface for application-specific event types. Unlike the Event interface, it allows applications to provide contextual information about the event type.

Authoring Note: Use a prefix string on the event type name for application-specific event types to avoid clashes with future general-purpose event types.

To create an instance of the CustomEvent interface, use the DocumentEvent.createEvent("CustomEvent") method call.

any detail = null
readonly attribute any detail

Specifies some detail information about the Event.

The un-initialized value of this attribute MUST be null.

Interface EventTarget

Introduced in DOM Level 2

The EventTarget interface allows registration and removal of event listeners, and dispatch of events to an event target.

Note: Though an event listener can be registered for any event target node, the user agent only dispatches UA-generated (trusted) events on node types that are defined as event target types for that specific event type (see the List of DOM3 Event Types). For example, a mouseover event type registered on a text node will never be fired by the user agent, though a content author could dispatch an event of that type on the text node via script.

When used with the DOM event flow, this interface MUST be implemented by all event targets and target ancestors, i.e., all DOM Nodes of the tree support this interface when the implementation conforms to DOM Level 3 Events and, therefore, this interface can be obtained by using binding-specific casting methods on an instance of the Node interface.

Invoking addEventListener (or removeEventListener) repeatedly on the same EventTarget with the same values for the parameters type, listener, and useCapture has no effect. Doing so does not cause the event listener to be registered more than once and does not cause a change in the triggering order.

Note: In addition to the EventTarget.addEventListener method, some host languages allow a content author to register event listeners by the use of attributes, e.g., onclick="handleClick()" (see [HTML5] for further examples). Due to the language-specific details, this type of event listener registration is not defined in this specification. In general, many event types can be used as an attribute in this way by adding the prefix on- to the event type name. Dispatching events to these listeners is expected to behave consistently with the event registration and propagation defined in this specification, with the same interfaces, properties, and methods.

// Modified in DOM Level 3
void addEventListener()

Modified in DOM Level 3

Registers an event listener on the EventTarget. The listener is registered for the capture phase if the useCapture parameter is true, and for the bubble phase otherwise. When the event reaches the target element, listeners for both the capture and bubble phases are triggered as part of the target phase.

DOMString type

Specifies the Event.type associated with the event for which the user is registering.

EventListener? listener

If non-null, the listener parameter MUST be an object that implements the EventListener interface or a function. If listener is a function then it MUST be used as the callback for the event. Otherwise, if listener implements EventListener, then its handleEvent method MUST be used as the callback.

If null is passed for the listener, then addEventListener does nothing.

optional boolean useCapture = false

If true, useCapture indicates that the user wishes to add the event listener for the capture and target phases only, i.e., this event listener will not be triggered during the bubbling phase. If false, the event listener MUST only be triggered during the target and bubbling phases.

This parameter MUST be optional. If not provided, the EventTarget.addEventListener method MUST behave as if useCapture was specified to be false.

Authoring Note: The useCapture parameter was mandatory in DOM2 Events [DOM2 Events], and omitting this parameter could cause an error in older implementations.

void removeEventListener()

Modified in DOM Level 3

Removes an event listener. Calling removeEventListener with arguments that do not identify any currently registered EventListener on the EventTarget has no effect.

DOMString type

Specifies the Event.type for which the user registered the event listener.

EventListener? listener

The EventListener to be removed.

optional boolean useCapture = false

Specifies whether the EventListener being removed was registered for the capture phase or not. Implementations MUST treat the same listener that was registered twice with both useCapture true and useCapture false as independent registrations, and remove them independently.

Authoring Note: If a listener was registered twice, once for the capture and target phases and once for the target and bubbling phases, this represents two unique registrations. Removal of an event listener registered for the capture and target phases does not affect the same event listener registered for the target and bubbling phases, and vice versa.

This parameter MUST be optional. If not provided, the EventTarget.removeEventListener method MUST behave as if useCapture were specified to be false.

Authoring Note: The useCapture parameter was mandatory in DOM2 Events [DOM2 Events], and omitting this parameter could cause an error in older implementations.

boolean dispatchEvent()

Modified in DOM Level 3

Dispatches an event into the implementation's event model. The event target of the event MUST be the EventTarget object on which dispatchEvent is called.

If after the event object finishes propagating through the DOM event flow its Event.defaultPrevented attribute is false, then this method returns true. Otherwise this method returns false.

Warning! For security reasons, events dispatched using EventTarget.dispatchEvent() MUST have a isTrusted attribute value of false. See trusted events for more details.

Note: While a dispatch (triggered by EventTarget.dispatchEvent()) is in progress, calls to Event.initEvent() are ignored (the method returns immediately without side-effects) and calls to EventTarget.dispatchEvent() result in an exception.

Event event

The event to be dispatched.

Note: This parameter receives an Event object, or any object that inherits from Event, e.g., MouseEvent, KeyboardEvent, MutationEvent, etc.

Exceptions: If the Event.type was not specified by initializing the event before dispatchEvent was called OR the Event object is already being dispatched, a DOMException of type InvalidStateError is thrown.

Interface EventListener

Introduced in DOM Level 2

The EventListener interface is the primary way to handle events. EventListener represents the callback object that the user agent will invoke when dispatching an Event to an EventTarget.

Note: Authors define an object which implements the EventListener interface and register their event listener using EventTarget.addEventListener. In JavaScript, an EventListener can be either a function or an object with a handleEvent member function.

Note: It is a best practice for authors to remove their EventListener from its EventTarget after they have completed using the listener.

Copying a Node, with methods such as Node.cloneNode or Range.cloneContents [DOM Range], MUST NOT copy the event listeners attached to it. Event listeners can be attached to the newly created Node afterwards, if so desired.

Moving a Node, with methods such as Document.adoptNode, Node.appendChild, or Range.extractContents [DOM Range], MUST NOT cause the event listeners attached to it to be removed or un-registered.

void handleEvent()

This method MUST be called whenever an event occurs of the event type for which the EventListener interface was registered.

Event event

The Event contains contextual information about the event.

Interface DocumentEvent

Introduced in DOM Level 2

The DocumentEvent interface provides a mechanism by which the user can create an Event object of a type supported by the implementation. The DocumentEvent interface MUST be implemented on the same object that implements the Document interface.

Event createEvent()

Modified in DOM Level 3

Creates an event object of the type specified. Returns the newly created object.

The text of this note needs to be reviewed. Remove reference to initMouseEvent (here and throughout main text).

Note: After calling createEvent, and prior to dispatching the event with the EventTarget.dispatchEvent() method, the Event will need to be initialized with the appropriate event initialization method (e.g., initEvent, initMouseEvent, etc.) in order to associate it with an event type and related values.

A content author wishing to synthesize some kind of UIEvent would invoke DocumentEvent.createEvent("UIEvent"). The UIEvent.initUIEvent() method could then be called on the newly created UIEvent object to set the specific type of user interface event to be dispatched, scroll for example, and set its context information, e.g., UIEvent.detail.

Warning! For security reasons, events generated using DocumentEvent.createEvent("Event") MUST have a isTrusted attribute value of false. See trusted events for more details.

Exceptions: If the implementation does not support the Event interface requested, a DOMException of type NotSupportedError is thrown.

DOMString eventInterface

The eventInterface parameter specifies the name of the DOM Events interface to be supported by the created event object, e.g., "Event", "MouseEvent", "MutationEvent", and so on.

For backward compatibility, the following case-insensitive feature names are valid values for the parameter eventInterface:

Legacy feature name Resulting event interface
"Events" Event
"HTMLEvents" Event
"UIEvents" UIEvent
"MouseEvents" MouseEvent
"MutationEvents" MutationEvent

Events Module

Event Types

Each event MUST be associated with a type, called event type and available as the type attribute on the event object. The event type MUST be of type DOMString.

List of DOM3 Event Types

Depending on the level of DOM support, or the devices used for display (e.g., screen) or interaction (e.g., mouse, keyboard, touch screen, or voice), these event types can be generated by the implementation. When used with an [XML 1.0] or [HTML5] application, the specifications of those languages MAY restrict the semantics and scope (in particular the possible event targets) associated with an event type. Refer to the specification defining the language used in order to find those restrictions or to find event types that are not defined in this document.

The following table provides an informative summary of the event types defined in this specification.

Event Type Sync / Async Bubbling phase Trusted event target types DOM interface Cancelable Default Action
abort Sync No Element Event No None
beforeinput Sync Yes HTMLInputElement, HTMLTextAreaElement, Element InputEvent Yes None
blur Sync No Element FocusEvent No None
click Sync Yes Element MouseEvent Yes DOMActivate event
compositionstart Sync Yes Element CompositionEvent Yes Show a text composition system candidate window
compositionupdate Sync Yes Element CompositionEvent No None
compositionend Sync Yes Element CompositionEvent No None
dblclick Sync Yes Element MouseEvent No None
error Async No Element Event No None
focus Sync No Element FocusEvent No None
focusin Sync Yes Element FocusEvent No None
focusout Sync Yes Element FocusEvent No None
input Sync Yes HTMLInputElement, HTMLTextAreaElement, Element InputEvent No None
keydown Sync Yes Document, Element KeyboardEvent Yes Varies: beforeinput and input events; launch text composition system; blur and focus events; keypress event; DOMActivate event; other event
keyup Sync Yes Document, Element KeyboardEvent Yes None
load Async No Window, Document, Element Event No None
mousedown Sync Yes Element MouseEvent Yes Varies: start a drag/drop operation; start a text selection; start a scroll/pan interaction (in combination with the middle mouse button, if supported)
mouseenter Sync No Element MouseEvent No None
mouseleave Sync No Element MouseEvent No None
mousemove Sync Yes Element MouseEvent Yes None
mouseout Sync Yes Element MouseEvent Yes None
mouseover Sync Yes Element MouseEvent Yes None
mouseup Sync Yes Element MouseEvent Yes Invoke a context menu (in combination with the right mouse button, if supported)
resize Sync No Window, Document UIEvent No None
scroll Async No / Yes Window, Document, Element UIEvent No None
select Sync Yes Element Event No None
unload Sync No Window, Document, Element Event No None
wheel Async Yes Window, Document, Element WheelEvent Yes Scroll (or zoom) the document

For a list of events which are deprecated in this specification, see the Legacy Event Types appendix at the end of this document.

The following is one way to interpret the above tables: the load event will trigger event listeners attached on Element nodes for that event and on the capture and target phases. This event is not cancelable. If an event listener for the load event is attached to a node other than Window, Document, or Element nodes, or if it is attached to the bubbling phase only, this event listener would not be triggered.

Note: Don't interpret the above tables as definitive for the listed event types. For example, the load event is used in other specifications, for example, in XMLHttpRequest. Similarly, dispatchEvent can be used to dispatch untrusted events to listeners on any object that also implements EventTarget.

Note: The event objects associated with the event types described above contain additional context information--refer to the description of the DOM interfaces for further information.

Event Module Definitions

The DOM Event Model allows a DOM implementation to support multiple modules of events. The model has been designed to allow addition of new event modules in the future. This document does not attempt to define all possible events. For purposes of interoperability, the DOM defines a module of user interface events including lower level device dependent events and a module of document mutation events.

User Interface Event Types

The User Interface event module contains basic event types associated with user interfaces and document manipulation.

Interface UIEvent

Introduced in DOM Level 2

The UIEvent interface provides specific contextual information associated with User Interface events.

To create an instance of the UIEvent interface, use the DocumentEvent.createEvent("UIEvent") method call.

readonly attribute WindowProxy? view

The view attribute identifies the Window from which the event was generated.

The un-initialized value of this attribute MUST be null.

readonly attribute long detail

Specifies some detail information about the Event, depending on the type of event.

The un-initialized value of this attribute MUST be 0.

WindowProxy? view = null

Should be initialized to the Window object of the global environment in which this event will be dispatched. If this event will be dispatched to an element, the view property should be set to the Window object containing the element's ownerDocument.

long detail = 0

This value is initialized to a number that is application-specific.

The User Interface event types are listed below. Some of these events use the UIEvent interface if generated from a user interface, but the Event interface otherwise, as detailed in each event.

load
Type load
Interface UIEvent if generated from a user interface, Event otherwise.
Sync / Async Async
Bubbles No
Target Window, Document, Element
Cancelable No
Default action None
Context info

A user agent MUST dispatch this event when the DOM implementation finishes loading the resource (such as the document) and any dependent resources (such as images, style sheets, or scripts). Dependent resources that fail to load MUST NOT prevent this event from firing if the resource that loaded them is still accessible via the DOM. If this event type is dispatched, implementations are REQUIRED to dispatch this event at least on the Document node.

Note: For legacy reasons, load events for resources inside the document (e.g., images) do not include the Window in the propagation path in HTML implementations. See [HTML5] for more information.

unload
Type unload
Interface UIEvent if generated from a user interface, Event otherwise.
Sync / Async Sync
Bubbles No
Target Window, Document, Element
Cancelable No
Default action None
Context info

A user agent MUST dispatch this event when the DOM Implementation removes from the environment the resource (such as the document) or any dependent resources (such as images, style sheets, scripts). The document MUST be unloaded after the dispatch of this event type. If this event type is dispatched, implementations are REQUIRED to dispatch this event at least on the Document node.

abort
Type abort
Interface UIEvent if generated from a user interface, Event otherwise.
Sync / Async Sync
Bubbles No
Target Element
Cancelable No
Default action None
Context info

A user agent MUST dispatch this event when the loading of a resource has been aborted, such as by a user canceling the load while it is still in progress.

error
Type error
Interface UIEvent if generated from a user interface, Event otherwise.
Sync / Async Async
Bubbles No
Target Element
Cancelable No
Default action None
Context info

A user agent MUST dispatch this event when a resource failed to load, or has been loaded but cannot be interpreted according to its semantics, such as an invalid image, a script execution error, or non-well-formed XML.

select
Type select
Interface UIEvent if generated from a user interface, Event otherwise.
Sync / Async Sync
Bubbles Yes
Target Element
Cancelable No
Default action None
Context info

A user agent MUST dispatch this event when a user selects some text. This event is dispatched after the selection has occurred.

This specification does not provide contextual information to access the selected text. Where applicable, a host language SHOULD define rules for how a user MAY select content (with consideration for international language conventions), at what point the select event is dispatched, and how a content author MAY access the user-selected content.

Note: In order to access to user-selected content, content authors will use native capabilities of the host languages, such as the Document.getSelection() method of the HTML Editing APIs [HTML Editing].

Note: The select event might not be available for all elements in all languages. For example, in [HTML5], select events can be dispatched only on form input and textarea elements. Implementations can dispatch select events in any context deemed appropriate, including text selections outside of form controls, or image or markup selections such as in SVG.

resize
Type resize
Interface UIEvent
Sync / Async Sync
Bubbles No
Target Window
Cancelable No
Default action None
Context info

A user agent MUST dispatch this event when a document view has been resized. This event type is dispatched after all effects for that occurrence of resizing of that particular event target have been executed by the user agent.

User agents which support continuous reflow of the document's layout during user-initiated resizing MUST dispatch this event synchronously after each reflow of the document.

The Window object SHOULD always be resizable. A host language MAY define certain elements to be resizable, and under what conditions (e.g., specific elements like <iframe>, or elements with particular characteristics like width and height). However, this specification does not define the behavior for elements.

Note: The resize event is distinct from the SVG zoom event types, though both can occur at the same time, or as the consequence of the same user action. In particular, browser font zooming or page zooming will not necessarily trigger a resize event.

Note: In previous DOM Events specifications, the resize event type was defined to have a bubbling phase, but for performance reasons, this was not implemented in most user agents, and this specification removes the bubbling phase for this event.

scroll
Type scroll
Interface UIEvent
Sync / Async Async
Bubbles No / Yes
Target Window, Document, Element
Cancelable No
Default action None
Context info

A user agent MUST dispatch this event when a document view or an element has been scrolled. This event type is dispatched after the scroll has occurred.

When dispatched on the Document element, this event type MUST bubble to the Window object.

Focus Event Types

Note: This interface and its associated event types and focus event order were designed in accordance to the concepts and guidelines defined in User Agent Accessibility Guidelines 2.0 [UAAG 2.0], with particular attention on the focus mechanism and the terms defined in the glossary entry for focus.

Interface FocusEvent

Introduced in DOM Level 3

The FocusEvent interface provides specific contextual information associated with Focus events.

To create an instance of the FocusEvent interface, use the DocumentEvent.createEvent("FocusEvent") method call.

readonly attribute EventTarget? relatedTarget

Used to identify a secondary EventTarget related to a Focus event, depending on the type of event.

For security reasons with nested browsing contexts, when tabbing into or out of a nested context, the relevant EventTarget SHOULD be null.

The un-initialized value of this attribute MUST be null.

EventTarget? relatedTarget = null

The relatedTarget should be initialized to the element losing focus (in the case of a focus or focusin event) or the element gaining focus (in the case of a blur or focusout event).

EventTarget? relatedTarget = null

The relatedTarget should be initialized to the element whose bounds the mouse pointer just left (in the case of a mouseover or mouseenter event) or the element whose bounds the mouse pointer is entering (in the case of a mouseout or mouseleave or focusout event). For other events, this value need not be assigned (and will default to null).

Focus Event Order

The focus events defined in this specification occur in a set order relative to one another. The following is the typical sequence of events when a focus is shifted between elements (this order assumes that no element is initially focused):

User shifts focus
1. focusin Sent before first target element receives focus
2. focus Sent after first target element receives focus
User shifts focus
3. focusout Sent before first target element loses focus
4. focusin Sent before second target element receives focus
5. blur Sent after first target element loses focus
6. focus Sent after second target element receives focus

Note: This specification does not define the behavior of focus events when interacting with methods such as focus() or blur(). See the relevant specifications where those methods are defined for such behavior.

Document Focus and Focus Context

This event module includes event types for notification of changes in document focus. There are three distinct focus contexts that are relevant to this discussion:

  • The operating system focus context which MAY be on one of many different applications currently running on the computer. One of these applications with focus can be a browser.
  • When the browser has focus, the user can switch (such as with the tab key) the application focus context among the different browser user interface fields (e.g., the Web site location bar, a search field, etc.). One of these user interface fields can be the document being shown in a tab.
  • When the document itself has focus, the document focus context can be set to any of the focusable elements in the document.

The event types defined in this specification deal exclusively with document focus, and the event target identified in the event details MUST only be part of the document or documents in the window, never a part of the browser or operating system, even when switching from one focus context to another.

Normally, a document always has a focused element (even if it is the document element itself) and a persistent focus ring. When switching between focus contexts, the document's currently focused element and focus ring normally remain in their current state. For example, if a document has three focusable elements, with the second element focused, when a user changes operating system focus to another application and then back to the browser, the second element will still be focused within the document, and tabbing will change the focus to the third element. A host language MAY define specific elements which might receive focus, the conditions under which an element MAY receive focus, the means by which focus MAY be changed, and the order in which the focus changes. For example, in some cases an element might be given focus by moving a pointer over it, while other circumstances might require a mouse click. Some elements might not be focusable at all, and some might be focusable only by special means (clicking on the element), but not by tabbing to it. Documents MAY contain multiple focus rings. Other specifications MAY define a more complex focus model than is described in this specification, including allowing multiple elements to have the current focus.

The Focus event types are listed below.

blur
Type blur
Interface FocusEvent
Sync / Async Sync
Bubbles No
Target Element
Cancelable No
Default action None
Context info

A user agent MUST dispatch this event when an event target loses focus. The focus MUST be taken from the element before the dispatch of this event type. This event type is similar to focusout, but is dispatched after focus is shifted, and does not bubble.

focus
Type focus
Interface FocusEvent
Sync / Async Sync
Bubbles No
Target Element
Cancelable No
Default action None
Context info

A user agent MUST dispatch this event when an event target receives focus. The focus MUST be given to the element before the dispatch of this event type. This event type is similar to focusin, but is dispatched after focus is shifted, and does not bubble.

focusin
Type focusin
Interface FocusEvent
Sync / Async Sync
Bubbles Yes
Target Element
Cancelable No
Default action None
Context info

A user agent MUST dispatch this event when an event target is about to receive focus. This event type MUST be dispatched before the element is given focus. The event target MUST be the element which is about to receive focus. This event type is similar to focus, but is dispatched before focus is shifted, and does bubble.

Note: When using this event type, the content author can use the event's FocusEvent.relatedTarget attribute (or a host-language-specific method or means) to get the currently focused element before the focus shifts to the next focus event target, thus having access to both the element losing focus and the element gaining focus without the use of the blur or focusout event types.

focusout
Type focusout
Interface FocusEvent
Sync / Async Sync
Bubbles Yes
Target Element
Cancelable No
Default action None
Context info

A user agent MUST dispatch this event when an event target is about to lose focus. This event type MUST be dispatched before the element loses focus. The event target MUST be the element which is about to lose focus. This event type is similar to blur, but is dispatched before focus is shifted, and does bubble.

Mouse Event Types

The mouse event module originates from the [HTML 4.01] onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, and onmouseout attributes. This event module is specifically designed for use with pointing input devices, such as a mouse or a trackball.

Interface MouseEvent

Introduced in DOM Level 2, modified in DOM Level 3

The MouseEvent interface provides specific contextual information associated with Mouse events.

In the case of nested elements, mouse events are always targeted at the most deeply nested element.

Note: Ancestors of the targeted element can use event bubbling to obtain notifications of mouse events which occur within their descendent elements.

To create an instance of the MouseEvent interface, use the DocumentEvent.createEvent("MouseEvent") method call.

Note: When initializing MouseEvent objects using initMouseEvent, implementations can use the client coordinates clientX and clientY for calculation of other coordinates (such as target coordinates exposed by DOM Level 0 implementations or other proprietary attributes, e.g., pageX).

readonly attribute long screenX

The horizontal coordinate at which the event occurred relative to the origin of the screen coordinate system.

The un-initialized value of this attribute MUST be 0.

readonly attribute long screenY

The vertical coordinate at which the event occurred relative to the origin of the screen coordinate system.

The un-initialized value of this attribute MUST be 0.

readonly attribute long clientX

The horizontal coordinate at which the event occurred relative to the viewport associated with the event.

The un-initialized value of this attribute MUST be 0.

readonly attribute long clientY

The vertical coordinate at which the event occurred relative to the viewport associated with the event.

The un-initialized value of this attribute MUST be 0.

readonly attribute boolean ctrlKey

Refer to the KeyboardEvent.ctrlKey attribute.

The un-initialized value of this attribute MUST be false.

readonly attribute boolean shiftKey

Refer to the KeyboardEvent.shiftKey attribute.

The un-initialized value of this attribute MUST be false.

readonly attribute boolean altKey

Refer to the KeyboardEvent.altKey attribute.

The un-initialized value of this attribute MUST be false.

readonly attribute boolean metaKey

Refer to the KeyboardEvent.metaKey attribute.

The un-initialized value of this attribute MUST be false.

readonly attribute short button

During mouse events caused by the depression or release of a mouse button, button MUST be used to indicate which pointer device button changed state.

The value of the MouseEvent.button attribute MUST be as follows:

  • 0 MUST indicate the primary button of the device (in general, the left button or the only button on single-button devices, used to activate a user interface control or select text) or the un-initialized value.
  • 1 MUST indicate the auxiliary button (in general, the middle button, often combined with a mouse wheel).
  • 2 MUST indicate the secondary button (in general, the right button, often used to display a context menu).

Some pointing devices provide or simulate more button states, and values higher than 2 or lower than 0 MAY be used to represent such buttons.

Note: The value of button is not updated for events not caused by the depression/release of a mouse button. In these scenarios, take care not to interpret the value 0 as the left button, but rather as the un-initialized value.

Authoring Note: Some default actions related to events such as mousedown and mouseup depend on the specific mouse button in use.

The un-initialized value of this attribute MUST be 0.

readonly attribute EventTarget? relatedTarget

Used to identify a secondary EventTarget related to a UI event, depending on the type of event.

The un-initialized value of this attribute MUST be null.

// Introduced in DOM Level 3
readonly attribute unsigned short buttons

During any mouse events, buttons MUST be used to indicate which combination of mouse buttons are currently being pressed, expressed as a bitmask.

Note: Though similarly named, the values for the buttons attribute and the button attribute are very different. The value of button is assumed to be valid during mousedown / mouseup event handlers, whereas the buttons attribute reflects the state of the mouse's buttons for any trusted MouseEvent object (while it is being dispatched), because it can represent the "no button currently active" state (0).

The value of the MouseEvent.buttons attribute MUST be as follows:

  • 0 MUST indicate no button is currently active.
  • 1 MUST indicate the primary button of the device (in general, the left button or the only button on single-button devices, used to activate a user interface control or select text).
  • 2 MUST indicate the secondary button (in general, the right button, often used to display a context menu), if present.
  • 4 MUST indicate the auxiliary button (in general, the middle button, often combined with a mouse wheel).

Some pointing devices provide or simulate more buttons. To represent such buttons, the value MUST be doubled for each successive button (in the binary series 8, 16, 32, ... ).

Note: Because the sum of any set of button values is a unique number, a content author can use a bitwise operation to determine how many buttons are currently being pressed and which buttons they are, for an arbitrary number of mouse buttons on a device. For example, the value 3 indicates that the left and right button are currently both pressed, while the value 5 indicates that the left and middle button are currently both pressed.

Authoring Note: Some default actions related to events such as mousedown and mouseup depend on the specific mouse button in use.

The un-initialized value of this attribute MUST be 0.

boolean getModifierState()

Introduced in DOM Level 3

Queries the state of a modifier using a key value. See also Modifier keys.

Returns true if it is a modifier key and the modifier is activated, false otherwise.

DOMString keyArg

Refer to the KeyboardEvent.getModifierState() method for a description of this parameter.

long screenX = 0

See screenY (substituting "horizontal" for "veritcal").

long screenY = 0

Initializes the screenY attribute of the MouseEvent object to the desired vertical relative position of the mouse pointer on the user's screen.

Initializing the event object to the given mouse position must not move the user's mouse pointer to the initialized position.

long clientX = 0

See clientY (substituting "horizontal" for "vertical").

long clientY = 0

Initializes the clientY attribute of the MouseEvent object to the desired vertical position of the mouse pointer relative to the client window of the user's browser.

Initializing the event object to the given mouse position must not move the user's mouse pointer to the initialized position.

boolean ctrlKey = false

Initializes the ctrlKey attribute of the MouseEvent object to true if the ctrlKey modifier key is to be considered depressed, false otherwise.

boolean shiftKey = false

Initializes the shiftKey attribute of the MouseEvent object to true if the shiftKey modifier key is to be considered depressed, false otherwise.

boolean altKey = false

Initializes the altKey attribute of the MouseEvent object to true if the altKey modifier key is to be considered depressed, false otherwise.

boolean metaKey = false

Initializes the metaKey attribute of the MouseEvent object to true if the metaKey modifier key is to be considered depressed, false otherwise.

short button = 0

Initializes the button attribute of the MouseEvent object to a number representing the desired state of the button(s) of the mouse.

Note: The value 0 is used to represent the primary mouse button, 1 is used to represent the auxillery/ middle mouse button, and 2 to represent the right mouse button. Numbers greater than 2 are also possible, but not well-defined in DOM Level 3 Events [[DOM-LEVEL-3-EVENTS]].

unsigned short buttons = 0

Initializes the buttons attribute of the MouseEvent object to a number representing one or more of the button(s) of the mouse that are to be considered active.

Note: The buttons attribute is a bit-field. To apply a value according to the definition in DOM Level 3 Events [[DOM-LEVEL-3-EVENTS]], first, determine the buttons that are to be considered active, then apply a bit-wise OR operation the the result set. The value 1 is used to represent the primary mouse button, 2 to represent the right mouse button, and 4 to represent the auxillery/middle button. Numbers greater than 4 are also possible and should be subsequent powers of 2 (8, 16, etc.), but these additional values are not well-defined in DOM Level 3 Events.

In JavaScript, to initialize the buttons attribute as if the right (2) and middle button (4) were being pressed simultaneously, the buttons value can be assigned as either:
{ buttons: 2 | 4 }
or:
{ buttons: 6 }

EventTarget? relatedTarget = null

The relatedTarget should be initialized to the element whose bounds the mouse pointer just left (in the case of a mouseover or mouseenter event) or the element whose bounds the mouse pointer is entering (in the case of a mouseout or mouseleave or focusout event). For other events, this value need not be assigned (and will default to null).

Implementations MUST maintain the current click count when generating mouse events. This MUST be a non-negative integer indicating the number of consecutive clicks of a pointing device button within a specific time. The delay after which the count resets is specific to the environment configuration.

Mouse Event Order

Certain mouse events defined in this specification MUST occur in a set order relative to one another. The following shows the event sequence that MUST occur when a pointing device's cursor is moved over an element:

Event Name Element Notes
1. mousemove
Pointing device is moved into element A...
2. mouseover A
3. mouseenter A
4. mousemove A Multiple events
Pointing device is moved out of element A...
5. mouseout A
6. mouseleave A

When a pointing device is moved into an element A, and then into a nested element B and then back out again, the following sequence of events MUST occur:

Event Name Element Notes
1. mousemove
Pointing device is moved into element A...
2. mouseover A
3. mouseenter A
4. mousemove A Multiple events
Pointing device is moved into nested element B...
5. mouseout A
6. mouseover B
7. mouseenter B
8. mousemove B Multiple events
Pointing device is moved from element B into A...
9. mouseout B
10. mouseleave B
11. mouseover A
12. mousemove A Multiple events
Pointing device is moved out of element A...
13. mouseout A
14. mouseleave A

Sometimes elements can be visually overlapped using CSS. In the following example, three elements labeled A, B, and C all have the same dimensions and absolute position on a web page. Element C is a child of B, and B is a child of A in the DOM:

Graphical representation of three stacked elements all on top of each other, with the pointing device moving over the stack.

When the pointing device is moved from outside the element stack to the element labeled C and then moved out again, the following series of events MUST occur:

Event Name Element Notes
1. mousemove
Pointing device is moved into element C, the topmost element in the stack
2. mouseover C
3. mouseenter A
4. mouseenter B
5. mouseenter C
6. mousemove C Multiple events
Pointing device is moved out of element C...
7. mouseout C
8. mouseleave C
9. mouseleave B
10. mouseleave A

Note: The mouseover/mouseout events are only fired once, while mouseenter/mouseleave events are fired three times (once to each element).

The following is the typical sequence of events when a button associated with a pointing device (e.g., a mouse button or trackpad) is pressed and released over an element:

Event Name Notes
1. mousedown
2. mousemove OPTIONAL, multiple events, some limits
3. mouseup
4. click
5. mousemove OPTIONAL, multiple events, some limits
6. mousedown
7. mousemove OPTIONAL, multiple events, some limits
8. mouseup
9. click
10. dblclick

Note: The lag time, degree, distance, and number of mousemove events allowed between the mousedown and mouseup events while still firing a click or dblclick event will be implementation-, device-, and platform-specific. This tolerance can aid users that have physical disabilities like unsteady hands when these users interact with a pointing device.

Each implementation will determine the appropriate hysteresis tolerance, but in general SHOULD fire click and dblclick events when the event target of the associated mousedown and mouseup events is the same element with no mouseout or mouseleave events intervening, and SHOULD fire click and dblclick events on the nearest common ancestor when the event targets of the associated mousedown and mouseup events are different.

If the event target (e.g. the target element) is removed from the DOM during the mouse events sequence, the remaining events of the sequence MUST NOT be fired on that element.

If the target element is removed from the DOM as the result of a mousedown event, no events for that element will be dispatched for mouseup, click, or dblclick, nor any default activation events. However, the mouseup event will still be dispatched on the element that is exposed to the mouse after the removal of the initial target element. Similarly, if the target element is removed from the DOM during the dispatch of a mouseup event, the click and subsequent events will not be dispatched.

The Mouse event types are listed below. In the case of nested elements, mouse event types are always targeted at the most deeply nested element. Ancestors of the targeted element MAY use bubbling to obtain notification of mouse events which occur within its descendent elements.

click
Type click
Interface MouseEvent
Sync / Async Sync
Bubbles Yes
Target Element
Cancelable Yes
Default action Varies
Context info

The click event type MUST be dispatched on the topmost event target indicated by the pointer, when the user presses down and releases the primary pointer button, or otherwise activates the pointer in a manner that simulates such an action. The actuation method of the mouse button depends upon the pointer device and the environment configuration, e.g., it MAY depend on the screen location or the delay between the press and release of the pointing device button.

Note: The click event should only be fired for the primary pointer button (i.e., when MouseEvent.button value is 0, MouseEvent.buttons value is 1). Secondary buttons (like the middle or right button on a standard mouse) MUST NOT fire click events.

The click event MAY be preceded by the mousedown and mouseup events on the same element, disregarding changes between other node types (e.g., text nodes). Depending upon the environment configuration, the click event MAY be dispatched if one or more of the event types mouseover, mousemove, and mouseout occur between the press and release of the pointing device button. The click event MAY also be followed by the dblclick event.

If a user mouses down on a text node child of a <p> element which has been styled with a large line-height, shifts the mouse slightly such that it is no longer over an area containing text but is still within the containing block of that <p> element (i.e., the pointer is between lines of the same text block, but not over the text node per se), then subsequently mouses up, this will likely still trigger a click event (if it falls within the normal temporal hysteresis for a click), since the user has stayed within the scope of the same element. Note that user-agent-generated mouse events are not dispatched on text nodes.

In addition to being associated with pointer devices, the click event type MUST be dispatched as part of an element activation, as described in Activation triggers and behavior.

Note: For maximum accessibility, content authors are encouraged to use the click event type when defining activation behavior for custom controls, rather than other pointing-device event types such as mousedown or mouseup, which are more device-specific. Though the click event type has its origins in pointer devices (e.g., a mouse), subsequent implementation enhancements have extended it beyond that association, and it can be considered a device-independent event type for element activation.

The default action of the click event type varies based on the event target of the event and the value of the MouseEvent.button or MouseEvent.buttons attributes. Typical default actions of the click event type are as follows:

dblclick
Type dblclick
Interface MouseEvent
Sync / Async Sync
Bubbles Yes
Target Element
Cancelable Yes
Default action None
Context info

A user agent MUST dispatch this event when the primary button of a pointing device is clicked twice over an element. The definition of a double click depends on the environment configuration, except that the event target MUST be the same between mousedown, mouseup, and dblclick. This event type MUST be dispatched after the event type click if a click and double click occur simultaneously, and after the event type mouseup otherwise.

Note: As with the click event, the dblclick event should only be fired for the primary pointer button. Secondary buttons MUST NOT fire dblclick events.

Note: Canceling the click event does not affect the firing of a dblclick event.

As with the click event type, the default action of the dblclick event type varies based on the event target of the event and the value of the MouseEvent.button or MouseEvent.buttons attributes. Normally, the typical default actions of the dblclick event type match those of the click event type, with the following additional behavior:

  • If the event target is selectable, the default action MUST be to select part or all of the selectable content. Subsequent clicks MAY select additional selectable portions of that content.
mousedown
Type mousedown
Interface MouseEvent
Sync / Async Sync
Bubbles Yes
Target Element
Cancelable Yes
Default action Varies: Start a drag/drop operation; start a text selection; start a scroll/pan interaction (in combination with the middle mouse button, if supported)
Context info

A user agent MUST dispatch this event when a pointing device button is pressed over an element.

Note: Many implementations use the mousedown event to begin a variety of contextually dependent default actions. These default actions can be prevented if this event is canceled. Some of these default actions could include: beginning a drag/drop interaction with an image or link, starting text selection, etc. Additionally, some implementations provide a mouse-driven panning feature that is activated when the middle mouse button is pressed at the time the mousedown event is dispatched.

mouseenter
Type mouseenter
Interface MouseEvent
Sync / Async Sync
Bubbles No
Target Element
Cancelable No
Default action None
Context info

A user agent MUST dispatch this event when a pointing device is moved onto the boundaries of an element or one of its descendent elements. This event type is similar to mouseover, but differs in that it does not bubble, and MUST NOT be dispatched when the pointer device moves from an element onto the boundaries of one of its descendent elements.

Note: There are similarities between this event type and the CSS :hover pseudo-class [CSS2.1]. See also the mouseleave event type.

mouseleave
Type mouseleave
Interface MouseEvent
Sync / Async Sync
Bubbles No
Target Element
Cancelable No
Default action None
Context info

A user agent MUST dispatch this event when a pointing device is moved off of the boundaries of an element and all of its descendent elements. This event type is similar to mouseout, but differs in that does not bubble, and that it MUST NOT be dispatched until the pointing device has left the boundaries of the element and the boundaries of all of its children.

Note: There are similarities between this event type and the CSS :hover pseudo-class [CSS2.1]. See also the mouseenter event type.

mousemove
Type mousemove
Interface MouseEvent
Sync / Async Sync
Bubbles Yes
Target Element
Cancelable Yes
Default action None
Context info

A user agent MUST dispatch this event when a pointing device is moved while it is over an element. The frequency rate of events while the pointing device is moved is implementation-, device-, and platform-specific, but multiple consecutive mousemove events SHOULD be fired for sustained pointer-device movement, rather than a single event for each instance of mouse movement. Implementations are encouraged to determine the optimal frequency rate to balance responsiveness with performance.

Authoring Note: In some implementation environments, such as a browser, mousemove events can continue to fire if the user began a drag operation (e.g., a mouse button is pressed) and the pointing device has left the boundary of the user agent.

mouseout
Type mouseout
Interface MouseEvent
Sync / Async Sync
Bubbles Yes
Target Element
Cancelable Yes
Default action None
Context info

A user agent MUST dispatch this event when a pointing device is moved off of the boundaries of an element. This event type is similar to mouseleave, but differs in that does bubble, and that it MUST be dispatched when the pointer device moves from an element onto the boundaries of one of its descendent elements.

Note: See also the mouseover event type.

mouseover
Type mouseover
Interface MouseEvent
Sync / Async Sync
Bubbles Yes
Target Element
Cancelable Yes
Default action None
Context info

A user agent MUST dispatch this event when a pointing device is moved onto the boundaries of an element. This event type is similar to mouseenter, but differs in that it bubbles, and that it MUST be dispatched when the pointer device moves onto the boundaries of an element whose ancestor element is the event target for the same event listener instance.

Note: See also the mouseout event type.

mouseup
Type mouseup
Interface MouseEvent
Sync / Async Sync
Bubbles Yes
Target Element
Cancelable Yes
Default action Invoke a context menu (in combination with the right mouse button, if supported)
Context info

A user agent MUST dispatch this event when a pointing device button is released over an element.

Note: Many implementations will invoke a context menu as the default action of this event if the right mouse button is being released.

Authoring Note: In some implementation environments, such as a browser, a mouseup event can be dispatched even if the pointing device has left the boundary of the user agent, e.g., if the user began a drag operation with a mouse button pressed).

Wheel Event Types

Wheels are devices that can be rotated in one or more spatial dimensions, and which can be associated with a pointer device. The coordinate system depends on the environment configuration.

The user's environment might be configured to associate vertical scrolling with rotation along the y-axis, horizontal scrolling with rotation along the x-axis, and zooming with rotation along the z-axis.

The deltaX, deltaY, and deltaZ attributes of WheelEvent objects indicate a measurement along their respective axes in units of pixels, lines, or pages. The reported measurements are provided after an environment-specific algorithm translates the actual rotation/movement of the wheel device into the appropriate values and units.

Authoring Note: A user's environment settings can be customized to interpret actual rotation/movement of a wheel device in different ways. One movement of a common dented mouse wheel can produce a measurement of 162 pixels (162 is just an example value, actual values can depend on the current screen dimensions of the user-agent). But a user can change their default environment settings to speed-up their mouse wheel, increasing this number. Furthermore, some mouse wheel software can support acceleration (the faster the wheel is rotated/moved, the greater the delta of each measurement) or even sub-pixel rotation measurements. Because of this, authors can not assume a given rotation amount in one user agent will produce the same delta value in all user agents.

The sign (positive or negative) of the values of the deltaX, deltaY, and deltaZ attributes MUST be consistent between multiple dispatches of the wheel event while the motion of the actual wheel device is rotating/moving in the same direction. If a user agent scrolls as the default action of the wheel event then the sign of the delta SHOULD be given by a right-hand coordinate system where positive X, Y, and Z axes are directed towards the right-most edge, bottom-most edge, and farthest depth (away from the user) of the document, respectively.

Note: Individual user agents can (depending on their environment and hardware configuration) interpret the same physical user interaction on the wheel differently. For example, a vertical swipe on the edge of a trackpad from top to bottom can be interpreted as a wheel action intended to either scroll the page down or to pan the page up (i.e., resulting in either a positive or negative deltaY value respectively).

Interface WheelEvent

Introduced in DOM Level 3

The WheelEvent interface provides specific contextual information associated with wheel events.

To create an instance of the WheelEvent interface, use the DocumentEvent.createEvent("WheelEvent") method call.

// DeltaModeCode
const unsigned long DOM_DELTA_PIXEL = 0x00

The units of measurement for the delta MUST be pixels. This is the most typical case in most operating system and implementation configurations.

const unsigned long DOM_DELTA_LINE = 0x01

The units of measurement for the delta MUST be individual lines of text. This is the case for many form controls.

const unsigned long DOM_DELTA_PAGE = 0x02

The units of measurement for the delta MUST be pages, either defined as a single screen or as a demarcated page.

readonly attribute double deltaX

In user agents where the default action of the wheel event is to scroll, the value MUST be the measurement along the x-axis (in pixels, lines, or pages) to be scrolled in the case where the event is not cancelled. Otherwise, this is an implementation-specific measurement (in pixels, lines, or pages) of the movement of a wheel device around the x-axis.

The un-initialized value of this attribute MUST be 0.

readonly attribute double deltaY

In user agents where the default action of the wheel event is to scroll, the value MUST be the measurement along the y-axis (in pixels, lines, or pages) to be scrolled in the case where the event is not cancelled. Otherwise, this is an implementation-specific measurement (in pixels, lines, or pages) of the movement of a wheel device around the y-axis.

The un-initialized value of this attribute MUST be 0.

readonly attribute double deltaZ

In user agents where the default action of the wheel event is to scroll, the value MUST be the measurement along the z-axis (in pixels, lines, or pages) to be scrolled in the case where the event is not cancelled. Otherwise, this is an implementation-specific measurement (in pixels, lines, or pages) of the movement of a wheel device around the z-axis.

The un-initialized value of this attribute MUST be 0.

readonly attribute unsigned long deltaMode

The deltaMode attribute contains an indication of the units of measurement for the delta values. The default value is DOM_DELTA_PIXEL (pixels).

This attribute MUST be set to one of the DOM_DELTA constants to indicate the units of measurement for the delta values. The precise measurement is specific to device, operating system, and application configurations.

The un-initialized value of this attribute MUST be 0.

double deltaX = 0.0

See deltaZ attribute.

double deltaY = 0.0

See deltaZ attribute.

double deltaZ = 0.0

Initializes the deltaZ attribute of the WheelEvent object. Relative positive values for this attribute (as well as the deltaX and deltaY attributes) are given by a right-hand coordinate system where the X, Y, and Z axes are directed towards the right-most edge, bottom-most edge, and farthest depth (away from the user) of the document, respectively. Negative relative values are in the respective opposite directions.

unsigned long deltaMode = 0

Initializes the deltaMode attribute on the WheelEvent object to the enumerated values 0, 1, or 2, which represent the amount of pixels scrolled (DOM_DELTA_PIXEL), lines scrolled (DOM_DELTA_LINE), or pages scrolled (DOM_DELTA_PAGE) if the rotation of the wheel would have resulted in scrolling.

The Wheel event types are listed below.

wheel
Type wheel
Interface WheelEvent
Sync / Async Async
Bubbles Yes
Target Window, Document, Element
Cancelable Yes
Default action Scroll (or zoom) the document
Context info
  • Event.target: topmost event target
  • UIEvent.view: Window
  • UIEvent.detail: 0
  • MouseEvent.screenX: if the wheel is associated with a pointing device, the value based on the pointer position on the screen, otherwise 0
  • MouseEvent.screenY: if the wheel is associated with a pointing device, the value based on the pointer position on the screen, otherwise 0
  • MouseEvent.clientX: if the wheel is associated with a pointing device, the value based on the pointer position within the viewport, otherwise 0
  • MouseEvent.clientY : if the wheel is associated with a pointing device, the value based on the pointer position within the viewport, otherwise 0
  • MouseEvent.altKey: true if 'Alt' modifier was active, otherwise false
  • MouseEvent.ctrlKey: true if 'Control' modifier was active, otherwise false
  • MouseEvent.shiftKey: true if 'Shift' modifier was active, otherwise false
  • MouseEvent.metaKey: true if 'Meta' modifier was active, otherwise false
  • MouseEvent.button: if wheel is associated with a pointing device, value based on current button pressed, otherwise 0
  • MouseEvent.buttons: if wheel is associated with a pointing device, value based on all buttons current depressed, 0 if no buttons pressed
  • MouseEvent.relatedTarget: indicates the event target the pointing device is pointing at, if any.
  • WheelEvent.deltaX: expected amount that the page will scroll along the x-axis according to the deltaMode units; or an implemenation-specific value of movement of a wheel around the x-axis
  • WheelEvent.deltaY: expected amount that the page will scroll along the y-axis according to the deltaMode units; or an implemenation-specific value of movement of a wheel around the y-axis
  • WheelEvent.deltaZ: expected amount that the page will scroll along the z-axis according to the deltaMode units; or an implemenation-specific value of movement of a wheel around the z-axis
  • WheelEvent.deltaMode: unit indicator (pixels, lines, or pages) for the deltaX, deltaY, and deltaZ attributes

A user agent MUST dispatch this event when a mouse wheel has been rotated around any axis, or when an equivalent input device (such as a mouse-ball, certain tablets or touchpads, etc.) has emulated such an action. Depending on the platform and input device, diagonal wheel deltas MAY be delivered either as a single wheel event with multiple non-zero axes or as separate wheel events for each non-zero axis.

The typical default action of the wheel event type is to scroll (or in some cases, zoom) the document by the indicated amount. If this event is canceled, the implementation MUST NOT scroll or zoom the document (or perform whatever other implementation-specific default action is associated with this event type).

Note: In some user agents, or with some input devices, the speed that the wheel has been turned can affect the delta values, with a faster speed producing a higher delta value.

Input Event Types

Input events are sent as notifications whenever the DOM is being updated.

Interface InputEvent

Introduced in DOM Level 3

readonly attribute DOMString data

data holds the value of the characters generated by an input method. This MAY be a single Unicode character or a non-empty sequence of Unicode characters [Unicode]. Characters SHOULD be normalized as defined by the Unicode normalization form NFC, defined in [UAX #15]. This attribute MAY be null or contain the empty string.

The un-initialized value of this attribute MUST be "" (the empty string).

readonly attribute boolean isComposing

true if the input event occurs as part of a composition session, i.e., after a compositionstart event and before the corresponding compositionend event.

The un-initialized value of this attribute MUST be false.

DOMString data = ""

Initializes the data attribute of the InputEvent object.

boolean isComposing = false

Initializes the isComposing attribute of the InputEvent object.

Input Event Order

The input events defined in this specification MUST occur in a set order relative to one another.

1. beforeinput
DOM element is updated
2. input

The Input event types are listed below.

beforeinput
Type beforeinput
Interface InputEvent
Sync / Async Sync
Bubbles Yes
Target HTMLInputElement, HTMLTextAreaElement or any Element with contentEditable<=true.
Cancelable Yes
Default action Update the DOM element
Context info

A user agent MUST dispatch this event when the DOM is about to be updated.

input
Type input
Interface InputEvent
Sync / Async Sync
Bubbles Yes
Target HTMLInputElement, HTMLTextAreaElement or any Element with contentEditable<=true.
Cancelable No
Default action None
Context info

A user agent MUST dispatch this event immediately after the DOM has been updated.

Keyboard Event Types

Keyboard events are device dependent, i.e., they rely on the capabilities of the input devices and how they are mapped in the operating systems. Refer to Keyboard events and key values for more details, including examples on how Keyboard Events are used in combination with Composition Events. Depending on the character generation device, keyboard events might not be generated.

Authoring Note: Keyboard events are only one modality of providing textual input. For editing scenarios, consider also using the InputEvent as an alternate to (or in addition to) keyboard events.

Interface KeyboardEvent

Introduced in DOM Level 3

The KeyboardEvent interface provides specific contextual information associated with keyboard devices. Each keyboard event references a key using a value. Keyboard events are commonly directed at the element that has the focus.

The KeyboardEvent interface provides convenient attributes for some common modifiers keys: KeyboardEvent.ctrlKey, KeyboardEvent.shiftKey, KeyboardEvent.altKey, KeyboardEvent.metaKey. These attributes are equivalent to using the method KeyboardEvent.getModifierState(keyArg) with 'Control', 'Shift', 'Alt', or 'Meta' respectively.

To create an instance of the KeyboardEvent interface, use the DocumentEvent.createEvent("KeyboardEvent") method call.

// KeyLocationCode
const unsigned long DOM_KEY_LOCATION_STANDARD = 0x00

The key activation MUST NOT be distinguished as the left or right version of the key, and (other than the 'NumLock'key) did not originate from the numeric keypad (or did not originate with a virtual key corresponding to the numeric keypad).

The 'Q' key on a PC 101 Key US keyboard.

The 'NumLock' key on a PC 101 Key US keyboard.

The '1' key on a PC 101 Key US keyboard located in the main section of the keyboard.

const unsigned long DOM_KEY_LOCATION_LEFT = 0x01

The key activated originated from the left key location (when there is more than one possible location for this key).

The left 'Control' key on a PC 101 Key US keyboard.

const unsigned long DOM_KEY_LOCATION_RIGHT = 0x02

The key activation originated from the right key location (when there is more than one possible location for this key).

The right 'Shift' key on a PC 101 Key US keyboard.

const unsigned long DOM_KEY_LOCATION_NUMPAD = 0x03

The key activation originated on the numeric keypad or with a virtual key corresponding to the numeric keypad (when there is more than one possible location for this key). Note that the 'NumLock'key should always be encoded with a location of DOM_KEY_LOCATION_STANDARD.

The '1' key on a PC 101 Key US keyboard located on the numeric pad.

readonly attribute DOMString key

key holds the key value of the key pressed. If the value is has a printed representation, it MUST be a non-empty Unicode character string, conforming to the algorithm for determining the key value defined in this specification. If the value is a control key which has no printed representation, it MUST be one of the key values defined in the key values set, as determined by the algorithm for determining the key value. Implementations that are unable to identify a key MUST use the key value 'Unidentified'.

Note: The key attribute is not related to the legacy keyCode attribute and does not have the same set of values.

The un-initialized value of this attribute MUST be "" (the empty string).

readonly attribute DOMString code

code holds a string that identifies the physical key being pressed. The value is not affected by the current keyboard layout or modifier state, so a particular key will always return the same value.

The un-initialized value of this attribute must be "" (the empty string).

readonly attribute unsigned long location

The location attribute contains an indication of the location of the key on the device.

This attribute MUST be set to one of the DOM_KEY_LOCATION constants to indicate the location of a key on the device. In case a DOM implementation wishes to provide a new location value, a value different from the defined constant values MUST be used.

The un-initialized value of this attribute MUST be 0.

readonly attribute boolean ctrlKey

true if the 'Control' (control) key modifier was active.

The un-initialized value of this attribute MUST be false.

readonly attribute boolean shiftKey

true if the shift (Shift) key modifier was active.

The un-initialized value of this attribute MUST be false.

readonly attribute boolean altKey

true if the 'Alt' (alternative) or Option key modifier was active.

The un-initialized value of this attribute MUST be false.

readonly attribute boolean metaKey

true if the meta (Meta) key modifier was active.

Note: The 'Command' key modifier on Macintosh systems is represented using this key modifier.

The un-initialized value of this attribute MUST be false.

readonly attribute boolean repeat

true if the key has been pressed in a sustained manner. Holding down a key MUST result in the repeating the events keydown, beforeinput, input in this order, at a rate determined by the system configuration. For mobile devices which have long-key-press behavior, the first key event with a repeat attribute value of 'true' MUST serve as an indication of a long-key-press. The length of time that the key MUST be pressed in order to begin repeating is configuration-dependent.

The un-initialized value of this attribute MUST be false.

readonly attribute boolean isComposing

true if the key event occurs as part of a composition session, i.e., after a compositionstart event and before the corresponding compositionend event.

The un-initialized value of this attribute MUST be false.

boolean getModifierState()

Queries the state of a modifier using a key value. See also Modifier keys.

DOMString keyArg

A modifier key value. Modifier keys defined in this specification are given in the Modifier Keys table.

Returns true if it is a modifier key and the modifier is activated, false otherwise.

Note: If an application wishes to distinguish between right and left modifiers, this information could be deduced using keyboard events and KeyboardEvent.location.

DOMString key = ""

Initializes the key attribute of the KeyboardEvent object to the unicode character string representing the meaning of a key after taking into account all keyboard modifications (such as shift-state). This value is the final effective value of the key. If the key is not a printable character, then it should be one of the key values defined in the Keyboard Event key Value Tables.

DOMString code = ""

Initializes the code attribute of the KeyboardEvent object to the unicode character string representing the key that was pressed, ignoring any keyboard modifications such as keyboard layout. This value should be one of the code values defined in the Keyboard Events code Value Tables.

unsigned long location = 0

Initializes the location attribute of the KeyboardEvent object to one of the following location numerical constants:

  • KeyboardEvent.DOM_KEY_LOCATION_STANDARD (numerical value 0)
  • KeyboardEvent.DOM_KEY_LOCATION_LEFT (numerical value 1)
  • KeyboardEvent.DOM_KEY_LOCATION_RIGHT (numerical value 2)
  • KeyboardEvent.DOM_KEY_LOCATION_NUMPAD (numerical value 3)
boolean ctrlKey = false

Initializes the ctrlKey attribute of the KeyboardEvent object. This attribute should be set to true if the ctrlKey modifier key is to be considered depressed, false otherwise.

boolean shiftKey = false

Initializes the shiftKey attribute of the KeyboardEvent object. This attribute should be set to true if the shiftKey modifier key is to be considered depressed, false otherwise.

boolean altKey = false

Initializes the altKey attribute of the KeyboardEvent object. This attribute should be set to true if the altKey modifier key is to be considered depressed, false otherwise.

boolean metaKey = false

Initializes the metaKey attribute of the KeyboardEvent object. This attribute should be set to true if the metaKey modifier key is to be considered depressed, false otherwise.

boolean repeat = false

Initializes the repeat attribute of the KeyboardEvent object. This attribute should be set to true if the the current KeyboardEvent is considered part of a repeating sequence of similar events caused by the long depression of any single key, false otherwise.

boolean isComposing = false

Initializes the isComposing attribute of the KeyboardEvent object. This attribute should be set to true if the event being constructed occurs as part of a composition sequence, false otherwise.

Warning!

Legacy keyboard event implementations include three additional attributes, keyCode, charCode, and which. The keyCode attribute indicates a numeric value associated with a particular key on a computer keyboard, while the charCode attribute indicates the ASCII value of the character associated with that key (which might be the same as the keyCode value) and is applicable only to keys that produce a character value.

In practice, keyCode and charCode are inconsistent across platforms and even the same implementation on different operating systems or using different localizations. DOM Level 3 Events does not define values for either keyCode or charCode, or behavior for charCode. In conforming DOM Level 3 Events implementations, content authors can instead use KeyboardEvent.key and KeyboardEvent.code.

For more information, see the informative appendix on Legacy key attributes.

Note: For compatibility with existing content, virtual keyboards, such as software keyboards on screen-based input devices, are expected to produce the normal range of keyboard events, even though they do not possess physical keys.

Note: In some implementations or system configurations, some key events, or their values, might be suppressed by the IME in use.

Keyboard Event Order

The keyboard events defined in this specification occur in a set order relative to one another, for any given key:

1. keydown
2. beforeinput (only for keys which produce a character value)
Any default actions related to this key, such as inserting a character in to the DOM.
3. input (only for keys which have updated the DOM)
Any events as a result of the key being held for a sustained period (see below).
4. keyup

If the key is depressed for a sustained period, the following events MAY repeat at an environment-dependent rate:

1. keydown (with repeat attribute set to true)
2. beforeinput (only for keys which produce a character value)
Any default actions related to this key, such as inserting a character in to the DOM.
3. input (only for keys which have updated the DOM)

Note: Typically, any default actions associated with any particular key are completed before the keyup event is dispatched. This might delay the keyup event slightly (though this is not likely to be a perceptible delay).

The event target of a key event is the currently focused element which is processing the keyboard activity. This is often an HTML input element or a textual element which is editable, but MAY be an element defined by the host language to accept keyboard input for non-text purposes, such as the activation of a hotkey or trigger of some other behavior. If no suitable element is in focus, the event target will be the root element.

Note: The event target might change between different key events. For example, a keydown event for the 'Tab' key will likely have a different event target than the keyup event on the same keystroke.

The keyboard event types are listed below.

keydown
Type keydown
Interface KeyboardEvent
Sync / Async Sync
Bubbles Yes
Target Document, Element
Cancelable Yes
Default action Varies: beforeinput and input events; launch text composition system; blur and focus events; keypress event; DOMActivate event; other event
Context info

A user agent MUST dispatch this event when a key is pressed down. The keydown event type is device dependent and relies on the capabilities of the input devices and how they are mapped in the operating system. This event type MUST be generated after the key mapping. This event type MUST be dispatched before the beforeinput, input, and keyup events associated with the same key.

The default action of the keydown event depends upon the key:

  • If the key is associated with a character, the default action MUST be to dispatch a beforeinput event followed by an input event. In the case where the key which is associated with multiple characters (such as with a macro or certain sequences of dead keys), the default action MUST be to dispatch one set of beforeinput / input events for each character
  • If the key is associated with a text composition system, the default action MUST be to launch that system
  • If the key is the 'Tab' key, the default action MUST be to shift the document focus from the currently focused element (if any) to the new focused element, as described in Focus Event Types
  • If the key is the 'Enter' or ' ' key and the current focus is on a state-changing element, the default action MUST be to dispatch a click event, and a DOMActivate event if that event type is supported by the user agent (refer to activation triggers and behavior for more details)

If this event is canceled, the associated event types MUST NOT be dispatched, and the associated actions MUST NOT be performed.

Note: The keydown and keyup events are traditionally associated with detecting any key, not just those which produce a character value.

keyup
Type keyup
Interface KeyboardEvent
Sync / Async Sync
Bubbles Yes
Target Document, Element
Cancelable Yes
Default action None
Context info

A user agent MUST dispatch this event when a key is released. The keyup event type is device dependent and relies on the capabilities of the input devices and how they are mapped in the operating system. This event type MUST be generated after the key mapping. This event type MUST be dispatched after the keydown, beforeinput, and input events associated with the same key.

Note: the keydown and keyup events are traditionally associated with detecting any key, not just those which produce a character value.

Composition Event Types

Composition Events provide a means for inputing text in a supplementary or alternate manner than by Keyboard Events, in order to allow the use of characters that might not be commonly available on keyboard. For example, Composition Events might be used to add accents to characters despite their absence from standard US keyboards, to build up logograms of many Asian languages from their base components or categories, to select word choices from a combination of key presses on a mobile device keyboard, or to convert voice commands into text using a speech recognition processor. Refer to Keyboard events and key values for examples on how Composition Events are used in combination with keyboard events.

Conceptually, a composition session consists of one compositionstart event, one or more compositionupdate events, and one compositionend event, with the value of the data attribute persisting between each stage of this event chain during each session.

Note: While a composition session is active, keyboard events can be dispatched to the DOM if the keyboard is the input device used with the composition session. See the compositionstart event details and IME section for relevent event ordering.

Not all IME systems or devices expose the necessary data to the DOM, so the active composition string (the Reading Window or candidate selection menu option) might not be available through this interface, in which case the selection MAY be represented by the empty string.

Interface CompositionEvent

Introduced in DOM Level 3

The CompositionEvent interface provides specific contextual information associated with Composition Events.

To create an instance of the CompositionEvent interface, use the DocumentEvent.createEvent("CompositionEvent") method call.

readonly attribute DOMString? data

data holds the value of the characters generated by an input method. This MAY be a single Unicode character or a non-empty sequence of Unicode characters [Unicode]. Characters SHOULD be normalized as defined by the Unicode normalization form NFC, defined in [UAX #15]. This attribute MAY be null or contain the empty string.

The un-initialized value of this attribute MUST be "" (the empty string).

DOMString? data = ""

Initializes the data attribute of the CompositionEvent object to the characters generated by the IME composition.

Composition Event Order

The Composition Events defined in this specification MUST occur in the following set order relative to one another:

1. compositionstart
2. compositionupdate Multiple events
3. compositionend

Handwriting Recognition Systems

The following example describes a possible sequence of events when composing a text passage text with a handwriting recognition system, such as on a pen tablet, as modeled using Composition Events.

1. compositionstart
User writes word on tablet surface
2. compositionupdate 'test'
User rejects first word-match suggestion, selects different match
3. compositionupdate 'text'
4. compositionend 'text'

Canceling Composition Events

If a keydown event is canceled then any Composition Events that would have fired as a result of that keydown SHOULD not be dispatched:

1. keydown The default action is prevented, e.g., by invoking Event.preventDefault().
No Composition Events are dispatched
2. keyup

If the initial compositionstart event is canceled then the text composition session SHOULD be terminated. Regardless of whether or not the composition session is terminated, the compositionend event MUST be sent.

1. keydown
2. compositionstart The default action is prevented, e.g., by invoking Event.preventDefault().
No Composition Events are dispatched
3. compositionend
4. keyup

Key Events During Composition

During the composition session, all keydown and keyup events SHOULD be suppressed.

Including Key Events During Composition

If a user agent does not suppress these events during composition, then it MUST set the key event's isComposing attribute to true for any events that occur during a composition session.

Event Name KeyboardEvent
isComposing
Notes
1. keydown false This is the key event that initiates the composition.
2. compositionstart
3. compositionupdate
4. keyup true
... Any key events sent during the composition session MUST have isComposing set to true.
5. keydown true This is the key event that exits the composition.
6. compositionend
7. keyup false

Suppressing Key Events During Composition

If key events are suppressed between compositionstart and compositionend, then the first or last key pressed might result in unmatched keydown and keyup events. If a user agent suppresses key events during composition, then it MUST ensure that all keydown and keyup events occur in matching pairs.

To ensure that the initial keydown has a matching keyup, a user agent might insert an extra keyup to match the keydown that initiated a composition session, as shown in the following example:

Event Name KeyboardEvent
isComposing
Notes
1. keydown false This is the key event that initiates the composition.
2. compositionstart
3. compositionupdate
4. keyup true This event would normally be suppressed because of the ongoing composition session, but it is sent to match the previously sent keydown event.
... Any other key events that occur during the composition session are suppressed.
5. compositionend

To ensure that the composition session doesn't end with a dangling keyup event, a user agent can choose either (A) to suppress this keyup event, or (B) to insert an extra keydown event.

An example event sequence where both the keydown and keyup events have been suppressed:

Event Name KeyboardEvent
isComposing
Notes
Keydown for key that exits IME suppressed during composition session
1. compositionend
A keyup event would normally be sent at this time, but it is suppressed to avoid generating an unmatched keyup event.

An example event sequence where a keydown has been inserted:

Event Name KeyboardEvent
isComposing
Notes
Keydown for key that exits IME suppressed during composition session
1. compositionend
2. keydown false This is key event that was suppressed earlier. It is sent now to match the upcoming keyup.
3. keyup false

Input Events During Composition

During the composition session, the compositionupdate MUST be dispatched before the beforeinput and input events are sent.

Event Name Notes
1. compositionupdate
2. beforeinput
Any DOM updates occur at this point.
3. input

Note: Most IMEs do not support canceling updates during a composition session.

When a composition session is finished, any beforeinput and input events MUST be dispatched after the compositionend event.

Event Name Notes
1. compositionend
2. beforeinput Sent only if we’re about to update the DOM (i.e., the composition was not canceled). Canceling this will prevent the DOM update and the input event.
Any DOM updates occur at this point.
3. input Sent only if the DOM was updated.

Note: Some IMEs update the DOM before the compositionend event is dispatched. In this case, canceling the beforeinput event will have no effect (i.e., the input input will still fire).

Composition Event Types

The composition event types are listed below.

compositionstart
Type compositionstart
Interface CompositionEvent
Sync / Async Sync
Bubbles Yes
Target Element
Cancelable Yes
Default action Start a new composition session when a text composition system is enabled
Context info

A user agent MUST dispatch this event when a text composition system is enabled and a new composition session is about to begin (or has begun, depending on the text composition system) in preparation for composing a passage of text. This event type is device-dependent, and MAY rely upon the capabilities of the text conversion system and how it is mapped into the operating system. When a keyboard is used to feed an input method editor, this event type is generated after a keydown event, but speech or handwriting recognition systems MAY send this event type without keyboard events. Some implementations MAY populate the data attribute of the compositionstart event with the text currently selected in the document (for editing and replacement). Otherwise, the value of the data attribute MUST be the empty string.

This event MUST be dispatched immediately before a text composition system begins a new composition session, and before the DOM is modified due to the composition process. The default action of this event is for the text composition system to start a new composition session. If this event is canceled, the text composition system SHOULD discard the current composition session.

Note: Canceling the compositionstart event type is distinct from canceling the text composition system itself (e.g., by hitting a cancel button or closing an IME window).

Note: Some IMEs do not support cancelling an in-progress composition session (e.g., such as GTK which doesn't presently have such an API). In these cases, calling preventDefault will not stop this event's default action.

compositionupdate
Type compositionupdate
Interface CompositionEvent
Sync / Async Sync
Bubbles Yes
Target Element
Cancelable No
Default action None
Context info

A user agent SHOULD dispatch this event during a composition session when a text composition system updates its active text passage with a new character, which is reflected in the string in CompositionEvent.data.

In text composition systems which keep the ongoing composition in sync with the input control, the compositionupdate event MUST be dispatched before the control is updated.

Some text composition systems might not expose this information to the DOM, in which case this event will not fire during the composition process.

If the composition session is canceled, this event will be fired immediately before the compositionend event, and the CompositionEvent.data attribute will be set to the empty string.

compositionend
Type compositionend
Interface CompositionEvent
Sync / Async Sync
Bubbles Yes
Target Element
Cancelable No
Default action None
Context info

A user agent MUST dispatch this event when a text composition system completes or cancels the current composition session, and the compositionend event MUST be dispatched after the control is updated.

This event is dispatched immediately after the text composition system completes the composition session (e.g., the IME is closed, minimized, switched out of focus, or otherwise dismissed, and the focus switched back to the user agent).

Keyboard events and key values

This section contains necessary information regarding keyboard events:

Note: This section uses Serbian and Kanji characters which could be misrepresented or unavailable in the PDF version or printed version of this specification.

Keyboard Input

This section is informative

The relationship of each key to the complete keyboard has three separate aspects, each of which vary among different models and configurations of keyboards, particularly for locale-specific reasons:

This specification only defines the functional mapping, in terms of key values and code values, but briefly describes keyboard layout and key legends for background.

Key Legends

This section is informative

The key legend is the visual marking that is printed or embossed on the key cap (the rectangular 'cap' that covers the mechanical switch for the key). These markings normally consist of one or more characters that a keystroke on that key will produce (such as 'F', '8', or 'ш'), or names or symbols which indicate that key's function (such as an upward-pointing arrow indicating 'Shift', or the string 'Enter'). Keys are often referred to by this marking (e.g., Press the 'Shift' and 'F' keys.). Note, however, that the visual appearance of the key has no bearing on its digital representation, and in many configurations may be completely inaccurate. Even the control and function keys, such as 'Enter', MAY be mapped to different functionality, or even mapped as character keys.

For historical reasons, the character keys are typically marked with the capital-letter equivalents of the character value they produce, e.g., the 'F' key (the key marked with the glyph 'F'), will produce the character value 'f' when pressed without an active modifier key ('Shift') or modifier state ('CapsLock').

Note: Many keyboards contain keys that do not normally produce any characters, even though the symbol might have a Unicode equivalent. For example, the 'Shift' key might bear the symbol , which has the Unicode code point '\u21E7', but pressing the 'Shift' key will not produce this character value, and there is no Unicode code point for 'Shift'.

Keyboard Layout

This section is informative

Alphanumeric keyboards are the most common way for users to generate keyboard events. This section provides an overview of standard keyboards and their physical layouts.

Standard Keyboard Layouts

This section describes the physical layouts found on commonly available keyboards.

Keyboard Sections

When discussing keyboard layouts, it is convenient to divide the standard keyboard into distinct sections and to label each row.

The five general sections of a standard keyboard

These keyboard sections are:

  • The Alphanumeric section is the main part of the keyboard and is where most of the keyboard variation occurs. When a user selects a keyboard layout, it is the keys in this sections that are most affected.
  • The Control Pad and Arrow Pad sections contain the arrow keys and other editing keys.
  • The Numpad (also known as the "numeric keypad" or "number pad") contains number and math keys to make it easier to enter numeric data.
  • And finally, the Function section contains miscellaneous function keys and special keys like Escape.

To make it easier to identify keys, the rows on the keyboard are named starting with "A" for the bottom row up to "E" for the top row. The row of keys in the Function section are considered to be in row "K". These row names are consistent with those given in the ISO/IEC 9995-1 specification.

Note that many keyboards (both modern and legacy) have extra keys that do not fit neatly into the above sections. Some of these keys are covered in the Media Keys section. Keys not covered in this document should be handled in the same manner as described in the Other Devices section.

Standard "101" Keyboard Layout

The standard "101" keyboard (commonly referred to as the "US layout") is the only layout that uses the 'Backslash' code. All the other layouts omit this key and expand the 'Enter' key to occupy two-rows.

Standard '101' keyboard layout showing unmodified US key values

Modern standard "101"-layout keyboards actually contain 104 keys: 61 keys in the alphanumeric section and 43 keys in the numpad, control pad, arrow pad and function sections. The "101" name for this keyboard layout dates to the time when this standard keyboard did in fact contain 101 keys. The two 'OS' keys, and the 'Menu' key were added later to bring the total to 104 keys.

Alternate "101" Keyboard Layout

The alternate "101" keyboard removes the 'Backslash' key to create a large 'Enter' key and shrinks the 'Backspace' key to make room for the 'IntlYen' key (The 'IntlYen' name comes from the Japanese layout — in the Russian layout shown above this key maps to a '\'.

Alternate '101' keyboard layout showing unmodified Russian key values

Modern alternate "101"-layout keyboards contain 104 keys: 61 keys in the alphanumeric section and 43 keys in the numpad, control pad, arrow pad and function sections.

Standard "102" Keyboard Layout

The standard "102" keyboard is common throughout Europe and adds two keys that don't exist on the "101" layouts: The 'IntlBackslash' key next to the left shift key, and the 'IntlHash' key which is partially tucked under the 'Enter' key.

Standard '102' keyboard layout showing unmodified French key values

Modern "102"-layout keyboards contain 105 keys: 62 keys in the alphanumeric section and 43 keys in the numpad, control pad, arrow pad and function sections.

Korean "103" Keyboard Layout

The Korean "103" keyboard is based on the alternate 101 layout and adds two additional keys (one on each side of the spacebar) to handle Korean-specific input modes. These keys are 'Hanja' (labelled 한자 hanja) and 'HangulMode' (labelled 한/영 han/yeong).

Korean '103' keyboard layout showing unmodified Korean key values

Modern "103"-layout keyboards contain 106 keys: 63 keys in the alphanumeric section and 43 keys in the numpad, control pad, arrow pad and function sections.

Brazilian "104" Keyboard Layout

The "104" layout used in Brazil adds 4 new keys: the two non-US keys from the "102" layout ('IntlHash' and 'IntlBackslash') plus the 'IntlRo' key (next to the right shift key) and an extra key on the numeric keypad. This new keypad key is called 'KeypadComma' because it represents the thousands separator. On the Brazilian key layout, this key has a keycap of . and the 'KeypadPeriod' key has a keycap of ,.

Standard '104' keyboard layout showing unmodified Brazilian key values

Modern "104"-layout keyboards contain 107 keys: 63 keys in the alphanumeric section and 44 keys in the numpad, control pad, arrow pad and function sections. Some Brazilian keyboards lack the extra keypad key and have only 106 keys.

Japanese "106" Keyboard Layout

The Japanese "106" keyboard layout adds 3 new keys: 'IntlYen', 'IntlHash' and 'IntlRo'. It also shrinks the 'Space' key to make room for 3 input mode keys: 'NoConvert' (labelled 無変換 muhenkan), 'Convert' (labelled 変換 henkan), 'KanaMode' (labelled カタカナ/ひらがな/ローマ字 katakana/hiragana/romaji).

Standard '106' keyboard layout showing unmodified Japanese key values

Modern "106"-layout keyboards contain 109 keys: 66 keys in the alphanumeric section and 43 keys in the numpad, control pad, arrow pad and function sections.

Apple Keyboard Layout

In general, Apple keyboards follow the same layout as PC keyboards, but there are some differences as noted in the following figure.

Apple extended keyboard layout showing unmodified English key values

In this figure, the green keys are those that have been moved to a new location while the blue keys indicate keys that have been added.

Laptop Keyboard Layouts

The limited space available on laptop keyboards often means that the physical key layout needs to be adjusted to fit all the required keys. The writing system keys in the Alphanumeric section tend to remain intact, but the other keyboard sections are usually combined with other keys or removed altogether.

Apple laptop keyboard layout

In this Apple laptop keyboard, the right control key has been removed to make room for half-height arrow keys and a 'Fn' key is added on the left.

Sample PC laptop keyboard layout

PC laptop keyboards vary considerably, but this sample keyboard demonstrates some commonly found aspects. The control pad keys are added along the right-hand side with the arrow keys tucked in along the bottom. The right shift key is often shrunk to make room for the up arrow key and the right OS key is typically removed altogether.

Mobile Keypads

In the case where a content author wishes to rely on the mechanical layout of a mobile keypad, this specification suggests the keyboard configuration specified in ISO/IEC 9995-8:2006 [ISO-9995-8], which defines a numeric keypad layout and secondary assignment of Unicode characters in the range '\u0061'..'\u007A' to the number keys 2 through 9, as a common layout appropriate to some international uses.

Note: This keypad layout, and in particular the distribution of letters is for English devices, and will not match the keypads or configurations of many users. Content authors cannot rely upon any particular configuration, and are expected to create content in an internationalized and localizable manner.

A graphical depiction of an ISO standard defining layouts of numeric keypads, with distribution of letters on the keys, ISO/IEC 9995-8:2006.

Media Remote Controls

Many keyboards contain special keys to control media functions. Increasingly, many media devices, especially televisions, are Web-enabled. Hybrid keyboard/remote-control devices are becoming more common. To meet the needs of these hybrid Web/media devices, this specification defines keys that are common as remote control buttons, in addition to traditional keyboard keys.

Because of the smaller form factor, keys (or buttons) on a remote control will often be modal, with one key performing different functions based on the context of the on-screen content. Additionally, many keys serve as toggles, to change back and forth between two or more states (see toggling keys). These remote control buttons typically do not have modifier states so each button is assigned a single function (like "Play", "Pause", "Up", "Menu" or "Exit").

A graphical depiction of a media remote control, with buttons mapped to specific keys values.

Virtual Keyboards and Chording Keyboards

Virtual keyboards are software-based sets of keys, in a variety of different arrangements, commonly found on touch-screen devices. They are often modal, with the ability to switch between different dynamic sets of keys, such as alphabetic, numeric, or symbolic keys. Because of the lack of physical constraints, these keyboards MAY present the widest range of characters, including emoticons and other symbols, and MAY have keys not represented by Unicode [Unicode] or by the key values defined in this specification. Wherever possible, however, virtual keyboards SHOULD produce the normal range of keyboard events and values, for ease of authoring and compatibility with existing content.

Chording keyboards, also know as chorded keysets or chord keyboards, are key input devices which produce values by pressing several keys in combination or sequence, normally to simulate a full range of characters or commands on a reduced set of keys, often for single-handed use. A chording keyboard MAY have additional mode keys to switch between key values, and the number and type of keys pressed to produce a key value will vary, but the final key values produced by such keyboards SHOULD match the range of key values described in this specification.

For these and other alternative modal keyboards, the key values 'Alphanumeric', 'CapsLock', 'NumLock', and 'SymbolLock' are RECOMMENDED for the keys which switch between different modes.

Key codes

A key code is an attribute of a keyboard event that can be used to identify the physical key associated with the keyboard event. It is similar to USB Usage IDs in that it provides a low-level value (similar to a scancode) that is vendor-neutral.

The primary purpose of the code attribute is to provide a consistent and coherent way to identify keys based on their physical location. In addition, it also provides a stable name (unaffected by the current keyboard state) that uniquely identifies each key on the keyboard.

Motivation for Adding the code Attribute

As discussed in more detail later in this document, the standard PC keyboard has a set of keys (which we refer to as writing system keys) that generate different key values based on the current keyboard layout selected by the user. This situation makes it difficult to write code that detects keys based on their physical location since the code would need to know which layout is in effect in order to know which key values to check for. A real-world example of this is a game that wants to use the 'W', 'A', 'S' and 'D' keys to control player movement. The code attribute solves this problem by providing a stable value to check that is not affected by the current keyboard layout.

In addition, the values in the key attribute depend as well on the current keyboard state. Because of this, the order in which keys are pressed and released in relation to modifier keys can affect the values stored in the key attribute. The code attribute solves this problem by providing a stable value that is not affected by the current keyboard state.

The Relationship Between key and code

key
The key attribute is intended for users who are interested in the meaning of the key being pressed, taking into account the current keyboard layout (and IME and dead keys). Example use case: Detecting modified keys or bare modifier keys (e.g., to perform an action in response to a keyboard shortcut).
code
The code attribute is intended for users who are interested in the key that was pressed by the user, without any layout modifications applied. Example use case: Detecting WASD keys (e.g., for movement controls in a game) or trapping all keys (e.g., in a remote desktop client to send all keys to the remote host).

code Examples

Handling the Left and Right Alt Keys

Keyboard LayoutkeycodeNotes
US'Alt''AltLeft'DOM_KEY_LOCATION_LEFT
French'Alt''AltLeft'DOM_KEY_LOCATION_LEFT
US'Alt''AltRight'DOM_KEY_LOCATION_RIGHT
French'AltGr''AltRight'DOM_KEY_LOCATION_RIGHT

In this example, checking the key attribute permits matching 'Alt' without worrying about which Alt key (left or right) was pressed. Checking the code attribute permits matching the right Alt key ('AltRight') without worrying about which layout is currently in effect.

Note that, in the French example, the 'Alt' and 'AltGr' keys retain their left and right location, even through there is only one of each key.

Handling the Single Quote Key

Keyboard LayoutkeycodeNotes
US''''Quote'
Japanese':''Quote'
US Intl'DeadAcute''Quote'

This example shows how dead key values are encoded in the attributes. The char and key values vary based on the current locale, whereas the code attribute returns a consistent value.

Handling the '2' Key (with and without Shift pressed)

Keyboard LayoutkeycodeNotes
US'2''Digit2'
US'@''Digit2'shiftKey
UK'2''Digit2'
UK'"''Digit2'shiftKey
French'é''Digit2'
French'2''Digit2'shiftKey

Regardless of the current locale or the modifier key state, pressing the key labelled 2 on a US keyboard always results in 'Digit2' in the code attribute.

Sequence of Keyboard Events : Shift and '2'

Compare the attribute values in the following two key event sequences. They both produce the '@' character on a US keyboard, but differ in the order in which the keys are released. In the first sequence, the order is Shift (down), 2 (down), 2 (up), Shift (up).

Keyboard LayoutEventkeycodeNotes
USkeydown'Shift''ShiftLeft'DOM_KEY_LOCATION_LEFT
USkeydown'@''Digit2'shiftKey
USkeypress'@'''
USkeyup'@''Digit2'shiftKey
USkeyup'Shift''ShiftLeft'DOM_KEY_LOCATION_LEFT

In the second sequence, the Shift is released before the 2, resulting in the following event order: Shift (down), 2 (down), Shift (up), 2 (up).

Keyboard LayoutEventkeycodeNotes
USkeydown'Shift''ShiftLeft'DOM_KEY_LOCATION_LEFT
USkeydown'@''Digit2'shiftKey
USkeypress'@'''
USkeyup'Shift''ShiftLeft'DOM_KEY_LOCATION_LEFT
USkeyup'2''Digit2'

Note that the values contained in the key attribute does not match between the keydown and keyup events for the '2' key. The code attribute provides a consistent value that is not affected by the current modifier state.

code and Virtual Keyboards

The usefulness of the code attribute is less obvious for virtual keyboards (and also for remote controls and chording keyboards). In general, if a virtual (or remote control) keyboard is mimicking the layout and functionality of a standard keyboard, then it MUST also set the code attribute as appropriate. For keyboards which are not mimicking the layout of a standard keyboard, then the code attribute MAY be set to the closest match on a standard keyboard or it MAY be left undefined.

For virtual keyboards with keys that produce different values based on some modifier state, the code value should be the key value generated when the button is pressed while the device is in its factory-reset state.

Keyboard Event code Value Tables

This section defines a list of code values which implementations MUST support.

Key Codes for Standard Keyboards

This section describes the various keyboard sections in more detail and defines the code values that should be used for each key.

Alphanumeric Section

The Alphanumeric section keys fall into two general categories: "writing system" keys whose meaning changes based on the current keyboard layout, and "functional" keys which are (mostly) the same for all layouts.

Writing System Keys

The "writing system" keys are those that change meaning based on the current keyboard layout.

The writing system keys in the alphanumeric section

This figure shows a hypothetical keyboard that combines all the writing system keys (shown in blue and green) found on the various keyboards. Blue keys are present on all standard keyboards while green keys are only available on some keyboards.

The name shown on each key is the code assigned to that key. Wherever possible, the code names are based on the name for the US key in that position (i.e., they are based on the US keyboard layout). For keys that don't exist on the US keyboard, names from the UK or Japanese layouts are used instead.

List of code values for writing system keys in the Alphanumeric section.
Code ValueUSB Usage ID
Page 0x07
(Informative)
Notes (Informative)
'Backquote' 0x35` and ~ on a US keyboard. This is the 半角/全角/漢字 (hankaku/zenkaku/kanji) key on Japanese keyboards
'Backslash' 0x31\ and | on a US keyboard. Found only on standard 101-key layouts.
'Backspace' 0x2aLabelled Delete on Macintosh keyboards.
'BracketLeft' 0x2f[ and { on a US keyboard.
'BracketRight' 0x30] and } on a US keyboard.
'Comma' 0x36, and < on a US keyboard.
'Digit0' 0x270 and ) on a US keyboard.
'Digit1' 0x1e1 and ! on a US keyboard.
'Digit2' 0x1f2 and @ on a US keyboard.
'Digit3' 0x203 and # on a US keyboard.
'Digit4' 0x214 and $ on a US keyboard.
'Digit5' 0x225 and % on a US keyboard.
'Digit6' 0x236 and ^ on a US keyboard.
'Digit7' 0x247 and & on a US keyboard.
'Digit8' 0x258 and * on a US keyboard.
'Digit9' 0x269 and ( on a US keyboard.
'Equal' 0x2e= and + on a US keyboard.
'IntlBackslash' 0x64Located between the 'ShiftLeft' and 'KeyZ' keys. The \ and | key on a UK keyboard.
'IntlHash' 0x32Located between the 'Quote' and 'Enter' keys on row E of the keyboard. The # and ~ key on a UK keyboard.
'IntlRo' 0x87Located between the 'Slash' and 'ShiftRight' keys. The \ and (ro) key on a Japanese keyboard.
'IntlYen' 0x89Located between the 'Equal' and 'Backspace' keys. The ¥ (yen) key on a Japanese keyboard. The \ and / key on a Russian keyboard.
'KeyA' 0x04a on a US keyboard. Labelled q on an AZERTY (e.g., French) keyboard.
'KeyB' 0x05b on a US keyboard.
'KeyC' 0x06c on a US keyboard.
'KeyD' 0x07d on a US keyboard.
'KeyE' 0x08e on a US keyboard.
'KeyF' 0x09f on a US keyboard.
'KeyG' 0x0ag on a US keyboard.
'KeyH' 0x0bh on a US keyboard.
'KeyI' 0x0ci on a US keyboard.
'KeyJ' 0x0dj on a US keyboard.
'KeyK' 0x0ek on a US keyboard.
'KeyL' 0x0fl on a US keyboard.
'KeyM' 0x10m on a US keyboard.
'KeyN' 0x11n on a US keyboard.
'KeyO' 0x12o on a US keyboard.
'KeyP' 0x13p on a US keyboard.
'KeyQ' 0x14q on a US keyboard. Labelled a on an AZERTY (e.g., French) keyboard.
'KeyR' 0x15r on a US keyboard.
'KeyS' 0x16s on a US keyboard.
'KeyT' 0x17t on a US keyboard.
'KeyU' 0x18u on a US keyboard.
'KeyV' 0x19v on a US keyboard.
'KeyW' 0x1aw on a US keyboard. Labelled z on an AZERTY (e.g., French) keyboard.
'KeyX' 0x1bx on a US keyboard.
'KeyY' 0x1cy on a US keyboard. Labelled z on a QWERTZ (e.g., German) keyboard.
'KeyZ' 0x1dz on a US keyboard. Labelled w on an AZERTY (e.g., French) keyboard, and y on a QWERTZ (e.g., German) keyboard.
'Minus' 0x2d- and _ on a US keyboard.
'Period' 0x37. and > on a US keyboard.
'Quote' 0x34' and " on a US keyboard.
'Semicolon' 0x33; and : on a US keyboard.
'Slash' 0x38/ and ? on a US keyboard.

Functional Keys

The Functional keys (not to be confused with the Function keys described later) are those keys in the Alphanumeric section that provide general editing functions that are common to all locales (like Shift, Tab, Enter and Backspace). With a few exceptions, these keys do not change meaning based on the current keyboard layout.

The standard set of functional keys in the alphanumeric section
List of code values for functional keys in the Alphanumeric section.
Code ValueUSB Usage ID
Page 0x07
(Informative)
Notes (Informative)
'AltLeft' 0xe2Labelled Alt or Option.
'AltRight' 0xe6Labelled Alt or Option. This is the AltGr key on many keyboard layouts.
'CapsLock' 0x39
'ContextMenu' 0x65The application context menu key, which is typically found between the right OS key and the right Control key.
'ControlLeft' 0xe0
'ControlRight' 0xe4
'Enter' 0x28Labelled Enter and Return on Macintosh keyboards.
'OSLeft' 0xe3The Windows, , Command or other OS symbol key.
'OSRight' 0xe7The Windows, , Command or other OS symbol key.
'ShiftLeft' 0xe1
'ShiftRight' 0xe5
'Space' 0x2cThe   key.
'Tab' 0x2b

On some keyboards (notably Japanese and Korean) the spacebar is reduced in size to make room for extra keys on the bottom row. These keys typically allow the users to change the current input mode. Note that even though some of these Japanese and Korean keys occupy the same physical location on the keyboard, they use different code values.

Comparison of the lower row of functional keys on different keyboards
List of code values for functional keys found on Japanese and Korean keyboards.
Code ValueUSB Usage ID
Page 0x07
(Informative)
Notes (Informative)
'Convert' 0x8aJapanese: 変換 (henkan)
'KanaMode' 0x88Japanese: カタカナ/ひらがな/ローマ字 (katakana/hiragana/romaji)
'Lang1' 0x90 Korean: 한/영 (han/yeong)
Japanese (Mac keyboard): かな (kana)
'Lang2' 0x91 Korean: 한자 (hanja)
Japanese (Mac keyboard): 英数 (eisu)
'Lang3' 0x92 Japanese (word-processing keyboard): Katakana
'Lang4' 0x93 Japanese (word-processing keyboard): Hiragana
'Lang5' 0x94 Japanese (word-processing keyboard): Zenkaku/Hankaku
'NoConvert' 0x8bJapanese: 無変換 (muhenkan)

On Apple keyboards, some keys on the bottom row are omitted and others are arranged in a different order.

Control Pad Section

The Control Pad contains keys for navigating and editing documents.

Standard Control Pad layouts
List of code values for keys in the ControlPad section.
Code ValueUSB Usage ID
Page 0x07
(Informative)
Notes (Informative)
'Delete' 0x4c
'End' 0x4d
'Help' 0x75Not present on standard PC keyboards.
'Home' 0x4a
'Insert' 0x49Not present on Apple keyboards.
'PageDown' 0x4e
'PageUp' 0x4b

Note: The code for the 'Fn' key (found on some Apple keyboards) is defined below in the Function Section.

Arrow Pad Section

The Arrow Pad section contains the 4 arrow keys.

Standard Arrow Pad layout
List of code values for keys in the ArrowPad section.
Code ValueUSB Usage ID
Page 0x07
(Informative)
Notes (Informative)
'ArrowDown' 0x51
'ArrowLeft' 0x50
'ArrowRight' 0x4f
'ArrowUp' 0x52

Numpad Section

The Numpad Section contains numeric and mathematical operator keys arranged in a calculator-grid to facilitate numeric data entry.

Standard Numpad layouts

The standard Numpad is sometimes extended with additional keys for parentheses, operators, hexadecimal symbols, or calculator functions (like backspace). Some of the commonly added keys are listed in the table below.

List of code values for keys in the Numpad section.
Code ValueUSB Usage ID
Page 0x07
(Informative)
Notes (Informative)
'NumLock' 0x53
'Numpad0' 0x620 and Insert
'Numpad1' 0x591 and End
'Numpad2' 0x5a2 and ArrowDown
'Numpad3' 0x5b3 and PageDown
'Numpad4' 0x5c4 and ArrowLeft
'Numpad5' 0x5d5
'Numpad6' 0x5e6 and ArrowRight
'Numpad7' 0x5f7 and Home
'Numpad8' 0x608 and ArrowUp
'Numpad9' 0x619 and PageUp
'NumpadAdd' 0x57+
'NumpadBackspace' 0xbbFound on the Microsoft Natural Keyboard.
'NumpadClear' 0xd8
'NumpadClearEntry' 0xd9
'NumpadComma' 0x85, (thousands separator). For locales where the thousands separator is a '.' (e.g., Brazil), this key may generate a '.'.
'NumpadDecimal' 0x63. (decimal separator) and Delete. For locales where the decimal separator is ',' (e.g., Brazil), this key may generate a ','.
'NumpadDivide' 0x54/
'NumpadEnter' 0x58
'NumpadEqual' 0x67=
'NumpadMemoryAdd' 0xd3
'NumpadMemoryClear' 0xd2
'NumpadMemoryRecall' 0xd1
'NumpadMemoryStore' 0xd0
'NumpadMemorySubtract' 0xd4
'NumpadMultiply' 0x55*
'NumpadParenLeft' 0xb6( Found on the Microsoft Natural Keyboard.
'NumpadParenRight' 0xb7) Found on the Microsoft Natural Keyboard.
'NumpadSubtract' 0x56-

For Numpads that provide keys not listed here, a code value string should be created by starting with 'Numpad' and appending an appropriate description of the key.

Function Section

The Function section runs along the top of the keyboard and contains the function keys and a few additional special keys (for example, 'Escape' and 'PrintScreen').

On some keyboards (especially those found on laptops or other portable computers), the function keys ('F1' ... 'F12') are defined to have other primary functions (like controlling display brightness or audio volume) and require that a separate 'Fn' key be pressed to make them act as function keys. Unfortunately, the primary functions assigned to these keys varies widely from one manufacturer to the next. Because of this, the code is always set to the function key name.

List of code values for keys in the Function section.
Code ValueUSB Usage ID
Page 0x07
(Informative)
Notes (Informative)
'Escape' 0x29
'F1' 0x3a
'F2' 0x3b
'F3' 0x3c
'F4' 0x3d
'F5' 0x3e
'F6' 0x3f
'F7' 0x40
'F8' 0x41
'F9' 0x42
'F10' 0x43
'F11' 0x44
'F12' 0x45
'Fn' This is typically a hardware key that does not generate a separate code. Most keyboards do not place this key in the Function section, but it is included here to keep with related keys.
'FLock' Found on the Microsoft Natural Keyboard.
'PrintScreen' 0x46PrintScreen and SysReq
'ScrollLock' 0x47
'Pause' 0x48Pause and Break

For keyboards that provide more than 12 function keys, the code value follows the pattern shown above with 'F' followed by the function key number - 'F13', 'F14', 'F15', and so on.

Note: Apple keyboards may have 'Eject' or 'Power' keys in the Function section. The code values for these keys are defined in the Media Keys section.

Media Keys

Keys that fall outside the sections listed above are referred to as "media keys" since they commonly provide "media" functions like play, pause or volume control.

These are extra keys that many keyboard manufacturers add, but do not have a consistent location. These keys are often distinct from normal typing keys in appearance and may be recessed in the keyboard.

On laptop keyboards, these keys are often merged with the Function keys, with the "media" interpretation being the primary function of the key and the "function key" interpretation requiring the 'Fn' key to be pressed at the same time. In this configuration the code should be set to match the function key ('F1' ... 'F12'). When the keys are merged in this fashion, the code values are taken from the function key value since the "media" value is not consistent across keyboards.

List of code values for media keys.
Code ValueNotes (Informative)
'BrowserBack' Some laptops place this key to the left of the 'ArrowUp' key.
'BrowserFavorites'
'BrowserForward' Some laptops place this key to the right of the 'ArrowUp' key.
'BrowserHome'
'BrowserRefresh'
'BrowserSearch'
'BrowserStop'
'Eject' This key is placed in the Function section on some Apple keyboards.
'LaunchApp1' Sometimes labelled My Computer on the keyboard
'LaunchApp2' Sometimes labelled Calculator on the keyboard
'LaunchMail'
'MediaNextTrack'
'MediaPlayPause'
'MediaPreviousTrack'
'MediaSelect'
'MediaStop'
'Power' This key is placed in the Function section on some Apple keyboards, replacing the 'Eject' key.
'Sleep'
'VolumeDown'
'VolumeMute'
'VolumeUp'
'WakeUp'

Legacy Keys and Non-Standard Keys

These keys are not found on modern standard keyboards. They are listed here for reference purposes.

List of code values for legacy keys.
Code ValueNotes (Informative)
'Abort'
'Hyper'
'Meta' Do not use 'Meta' as a key code. The key labelled Meta should be encoded as 'OSLeft'.
'Resume'
'Super'
'Suspend'
'Turbo'

The following keys may be found on non-standard international keyboards.

List of code values for keys found on international keyboards.
Code ValueNotes (Informative)
'Hiragana' Use for dedicated ひらがな key found on some Japanese word processing keyboards.
'Katakana' Use for dedicated カタカナ key found on some Japanese word processing keyboards.

Keyboard Event key Values

A key value is a DOMString that can be used to indicate any given key on a keyboard, regardless of position or state, by the value it produces. These key values MAY be used as return values for keyboard events generated by the implementation, or as input values by the content author to specify desired input (such as for keyboard shortcuts). This specification defines a set of common key values (defined in the Key Value Tables), and rules for production of new key values.

Key values can be used to detect the value of a key which has been pressed, using the KeyboardEvent.key attribute. Content authors can retrieve the character value of upper- or lower-case letters, number, symbols, or other character-producing keys, and also the key value of control keys, modifier keys, function keys, or other keys that do not generate characters. These values can be used for monitoring particular input strings, for detecting and acting on modifier key input in combination with other inputs (such as a mouse), for creating virtual keyboards, or for any number of other purposes.

Key values can also be used by content authors in string comparisons, as values for markup attributes (such as the HTML accesskey) in conforming host languages, or for other related purposes. A conforming host language SHOULD allow content authors to use either of the two equivalent string values for a key value: the character value, or the key value.

Note: While implementations will use the most relevant value for a key independently of the platform or keyboard layout mappings, content authors can not make assumptions on the ability of keyboard devices to generate them. When using keyboard events and key values for shortcut-key combinations, content authors can consider using numbers and function keys (F4, F5, and so on) instead of letters ([DWW95]) given that most keyboard layouts will provide keys for those.

A key value does not indicate a specific key on the physical keyboard, nor does it reflect the character printed on the key. A key value indicates the current value of the event with consideration to the current state of all active keys and key input modes (including shift modes and dead keys), as reflected in the operating-system mapping of the keyboard and reported to the implementation. In other words, the key value for the key marked 'O' on a QWERTY keyboard has the key value 'o' in an unshifted state, 'O' in a shifted state, 'ö' in an unshifted state during a dead-key operation to add an umlaut diacritic, and 'Ö' in a shifted state during a dead-key operation to add an umlaut diacritic. Because a user can map their keyboard to an arbitrary custom configuration, the content author is encouraged not to assume that a relationship exists between the shifted and unshifted states of a key and the majuscule form (uppercase or capital letters) and minuscule form (lowercase or small letters) of a character representation, but is encouraged instead to use the value of the KeyboardEvent.key attribute. The keyboard depicted in Figure 4 illustrates one possible set of key mappings on one possible keyboard layout. Many others exist, both standard and idiosyncratic.

It is also important to note that there is not a one-to-one relationship between key event states and key values. A particular key value might be associated with multiple keys. For example, many standard keyboards contain more than one key with the 'Shift' key value (normally distinguished by the KeyboardEvent.location values DOM_KEY_LOCATION_LEFT and DOM_KEY_LOCATION_RIGHT) or '8' key value (normally distinguished by the KeyboardEvent.location values DOM_KEY_LOCATION_STANDARD and DOM_KEY_LOCATION_NUMPAD), and user-configured custom keyboard layouts MAY duplicate any key value in multiple key-state scenarios (note that KeyboardEvent.location is intended for standard keyboard layouts, and cannot always indicate a meaningful distinction).

Finally, the meaning of any given character representation is context-dependent and complex. For example, in some contexts, the asterisk (star) glyph ('*') represents a footnote or emphasis (when bracketing a passage of text). However, in some documents or executable programs it is equivalent to the mathematical multiplication operation, while in other documents or executable programs, that function is reserved for the multiplication symbol ('×', Unicode value '\u00D7') or the Latin small letter 'x' (due to the lack of a multiplication key on many keyboards and the superficial resemblance of the glyphs '×' and 'x'). Thus, the semantic meaning or function of character representations is outside the scope of this specification.

Key Values and Unicode

The character values described in this specification are Unicode [Unicode] codepoints, and as such, have certain advantages.

The most obvious advantage is that it allows the content author to use the full range of internationalized language functionality available in the implementation, regardless of the limitations of the text input devices on the system. This opens up possibilities for virtual keyboards and Web-application-based input method editors.

Another benefit is that it allows the content author to utilize the Unicode general category properties programmatically.

With legacy keyboard event attributes such as keyCode and charCode, content authors are forced to filter key input using cryptic, platform- and implementation-specific numeric codes, with poor internationalization, such as the following pseudocode:

if ( ( event.charCode == 45 || event.charCode == 36 ) ||
     ( event.charCode >= 48 && event.charCode <= 57 ) ||
     ( event.charCode >= 96 && event.charCode <= 105 ) ) {
   // minus sign, dollar sign, and numeric characters from keyboard and numpad
   // ...
}
else if ( ( event.charCode >= 65 && event.charCode <= 90 ) ||
          ( event.charCode >= 97 && event.charCode <= 122 ) ) {
   // alphabetic characters from Latin character set, A-Z, a-z
   // ...
}
else {
   // ...
}

With key values and regular expressions, however, content authors can support selective and intuitive ranges for key-based input, in a cross-platform manner with advanced internationalization support, such as the following pseudocode:

if ( event.key == "-" || event.key.match("\p{Sc}") || event.key.match("\p{N}") ) {
   // minus sign, any currency symbol, and numeric characters (regardless of key location)
   // ...
}
else if ( event.key.match("\p{L}") ) {
   // alphabetic characters from any language, upper and lower case
   // ...
}
else {
   // ...
}

In addition, because Unicode categorizes each assigned code point into a group of code points used by a particular human writing system, even more advanced capabilities are possible.

A content author can match characters from a particular human script (e.g., Tibetan) using a regular expression such as \p{Tibetan}, to filter out other characters, or discover if a code point is in a certain code block (range of code points), using a regular expression like \p{InCyrillic}.

To facilitate this, implementations SHOULD support Unicode range detection using regular expressions, in a manner such as the Perl Compatible Regular Expressions (PCRE) [PCRE].

Modifier keys

Keyboard input uses modifier keys to change the normal behavior of a key. Like other keys, modifier keys generate keydown and keyup events, as shown in the example below. Some modifiers are activated while the key is being pressed down or maintained pressed such as 'Alt', 'Control', 'Shift', 'AltGraph', or 'Meta'. Others modifiers are activated depending on their state such as 'CapsLock', 'NumLock', or 'ScrollLock'. Change in the state happens when the modifier key is being pressed down. The KeyboardEvent interface provides convenient attributes for some common modifiers keys: KeyboardEvent.ctrlKey, KeyboardEvent.shiftKey, KeyboardEvent.altKey, KeyboardEvent.metaKey. Some operating systems simulate the 'AltGraph' modifier key with the combination of the 'Alt' and 'Control' modifier keys. Implementations are encouraged to use the 'AltGraph' modifier key.

The following example describes a possible sequence of events associated with the generation of the Unicode character Q (Latin Capital Letter Q, Unicode code point '\u0051') on a PC/AT US keyboard using a US mapping:

1. keydown 'Shift' shiftKey
2. keydown 'Q' shiftKey Latin Capital Letter Q
3. beforeinput 'Q'
4. input
5. keyup 'Q' shiftKey
6. keyup 'Shift'

The following example describes an alternate sequence of keys to the example above, where the 'Shift' key is released before the 'Q' key. The key value for the key labeled 'Q' will revert to its unshifted value for the keyup event:

1. keydown 'Shift' shiftKey
2. keydown 'Q' shiftKey Latin Capital Letter Q
3. beforeinput 'Q'
4. input
5. keyup 'Shift'
6. keyup 'q' Latin Small Letter Q

The following example describes a possible sequence of keys that does not generate a Unicode character (using the same configuration):

1. keydown 'Control' ctrlKey
2. keydown 'v' ctrlKey Latin Small Letter V
No beforeinput or input events are generated.
3. keyup 'v' ctrlKey Latin Small Letter V
4. keyup 'Control'

The following example shows the sequence of events when both 'Shift' and 'Control' are pressed:

1. keydown 'Control' ctrlKey
2. keydown 'Shift' ctrlKey shiftKey
3. keydown 'V' ctrlKey shiftKey Latin Capital Letter V
No beforeinput or input events are generated.
4. keyup 'V' ctrlKey shiftKey Latin Capital Letter V
5. keyup 'Shift' ctrlKey
6. keyup 'Control'

For non-US keyboard layouts, the sequence of events is the same, but the value of the key is based on the current keyboard layout. The following example shows a sequence of events when an Arabic keyboard layout is used:

1. keydown 'Control' ctrlKey
2. keydown 'ر' ctrlKey Arabic Letter Reh
No beforeinput or input events are generated.
3. keyup 'ر' ctrlKey Arabic Letter Reh
4. keyup 'Control'

Note: The value in the keydown and keyup events varies based on the current keyboard layout in effect when the key is pressed. This means that the 'v' key on a US layout and the 'ر' key on an Arabic layout will generate different events even though they are the same physical key. To identify these events as coming from the same physical key, you will need to make use of the code attribute as specified in the [UI Events] specification.

In some cases, modifier keys change the key value value for a key event. For example, on some MacOS keyboards, the key labeled 'delete' functions the same as the 'Backspace' key on the Windows OS when unmodified, but when modified by the 'Fn' key, acts as the 'Delete' key, and the value of the key value will match the most appropriate function of the key in its current modified state.

Dead keys

Some keyboard input uses dead keys for the input of composed character sequences. Unlike the handwriting sequence, in which users enter the base character first, keyboard input requires to enter a special state when a dead key is pressed and emit the character(s) only when one of a limited number of legal base character is entered.

Note: The MacOS and Linux operating systems use input methods to process dead keys.

The dead keys are represented in the key values set using combining diacritical marks. While Unicode combining characters always follow the handwriting sequence, with the combining character trailing the corresponding letter, typical deadkey input MAY reverse the sequence, with the combining character before the corresponding letter. For example, the word naïve, using the combining diacritic ¨, would be represented sequentially in Unicode as nai¨ve, but MAY be typed na¨ive. The sequence of keystrokes '\u0302' (Combining Circumflex Accent key) and '\u0065' (key marked with the Latin Small Letter E) will likely produce (on a PC/AT french keyboard using a french mapping and without any modifier activated) the Unicode character 'ê' (Latin Small Letter E With Circumflex), as preferred by the Unicode Normalization Form NFC:

Note: The keydown and keyup events shown in these examples would normally be suppressed during the composition session. They are included in these examples to make the user actions (pressing and releasing keys) more apparent.

Event Name KeyboardEvent
key
KeyboardEvent
isComposing
CompositionEvent
data
Notes
1. keydown '\u0302' false Combining Circumflex Accent
2. compositionstart ''
3. compositionupdate '\u0302'
4. keyup '\u0302' true
5. keydown 'ê' true
6. compositionupdate 'ê'
7. compositionend 'ê'
8. keyup 'e' false Latin Small Letter E

Note: In the second keydown event (step 5), the key value (assuming the event is not suppressed) will not be 'e' (Latin Small Letter E key) under normal circumstances because the value delivered to the user agent will already be modified by the dead key operation.

This process might be aborted when a user types an unsupported base character (that is, a base character for which the which the active diacritical mark is not available) after pressing a dead key:

Event Name KeyboardEvent
key
KeyboardEvent
isComposing
CompositionEvent
data
Notes
1. keydown '\u0302' false Combining Circumflex Accent
2. compositionstart ''
3. compositionupdate '\u0302'
4. keyup '\u0302' true
5. keydown 'q' true Latin Small Letter Q
6. compositionupdate ''
7. compositionend ''
8. keyup 'q' false

Input Method Editors

This specification includes a model for input method editors (IMEs), through the CompositionEvent interface and events. However, Composition Events and Keyboard Events do not necessarily map as a one-to-one relationship. As an example, receiving a keydown for the 'Accept' key value does not necessarily imply that the text currently selected in the IME is being accepted, but indicates only that a keystroke happened, disconnected from the IME Accept functionality (which would normally result in a compositionend event in most IME systems). Keyboard events cannot be used to determine the current state of the input method editor, which can be obtained through the data attribute of the CompositionEvent interface. Additionally, IME systems and devices vary in their functionality, and in which keys are used for activating that functionality, such that the 'Convert' and 'Accept' keys MAY be represented by other available keys. Keyboard events correspond to the events generated by the input device after the keyboard layout mapping.

Note: In some implementations or system configurations, some key events, or their values, might be suppressed by the IME in use.

The following example describes a possible sequence of keys to generate the Unicode character '市' (Kanji character, part of CJK Unified Ideographs) using Japanese input methods. This example assumes that the input method editor is activated and in the Japanese-Romaji input mode. The keys 'Convert' and 'Accept' MAY be replaced by others depending on the input device in use and the configuration of the IME, e.g., it can be respectively '\u0020' (Space key) and 'Enter'.

Note: '詩' (poem) and '市' (city) are homophones, both pronounced し (shi), so the user needs to use the 'Convert' key to select the proper option.

Event Name KeyboardEvent
key
KeyboardEvent
isComposing
CompositionEvent
data
Notes
1. keydown 's' false Latin Small Letter S
2. compositionstart ''
3. compositionupdate 's'
4. keyup 's' true
5. keydown 'i' true Latin Small Letter I
6. compositionupdate 'し'
7. keyup 'i' true
8. keydown 'Convert' true Convert
9. compositionupdate '詩'
10. keyup 'Convert' true
11. keydown 'Convert' true Convert
12. compositionupdate '市'
13. keyup 'Convert' true
14. keydown 'Accept' true Accept
15. compositionend '市'
16. keyup 'Accept' false

IME composition can also be canceled as in the following example, with conditions identical to the previous example. The key 'Cancel' might also be replaced by others depending on the input device in use and the configuration of the IME, e.g., it could be '\u001B' (Escape key).

Event Name KeyboardEvent
key
KeyboardEvent
isComposing
CompositionEvent
data
Notes
1. keydown 's' false Latin Small Letter S
2. compositionstart ''
3. compositionupdate 's'
4. keyup 's' true
5. keydown 'i' true Latin Small Letter I
6. compositionupdate 'し'
7. keyup 'i' true
8. keydown 'Convert' true Convert
9. compositionupdate '詩'
10. keyup 'Convert' true
11. keydown 'Convert' true Convert
12. compositionupdate '市'
13. keyup 'Convert' true
14. keydown 'Cancel' true Cancel
15. compositionupdate ''
16. compositionend ''
17. keyup 'Cancel' false

Note: Some input method editors (such as on the MacOS operating system) might set an empty string to the composition data attribute before canceling a composition.

Input Method Editor mode keys

Some keys on certain devices are intended to activate input method editor functionality, or to change the mode of an active input method editor. Custom keys for this purpose can be defined for different devices or language modes. The keys defined in this specification for this purpose are: Alphanumeric, CodeInput, FinalMode, HangulMode, HanjaMode, Hiragana, JunjaMode, KanaMode, KanjiMode, Katakana, and RomanCharacters. When one of these keys is pressed, and no IME is currently active, the appropriate IME is expected to be activated in the mode indicated by the key (if available). If an IME is already active when the key is pressed, the active IME might change to the indicated mode, or a different IME might be launched, or the might MAY be ignored, on a device- and application-specific basis.

This specification also defines other keys which are intended for operation specifically with input method editors: Accept, AllCandidates, Cancel, Convert, Compose, FullWidth, HalfWidth, NextCandidate, Nonconvert, and PreviousCandidate. The functions of these keys are not defined in this specification — refer to other resources for details on input method editor functionality.

Note: Keys with input method editor functions are not restricted to that purpose, and can have other device- or implementation-specific purposes.

Default actions and cancelable keyboard events

Canceling the default action of a keydown event MUST NOT affect its respective keyup event, but it MUST prevent the respective beforeinput and input (and keypress if supported) events from being generated. The following example describes a possible sequence of keys to generate the Unicode character Q (Latin Capital Letter Q) on a PC/AT US keyboard using a US mapping:

Event Name KeyboardEvent
key
InputEvent
data
Modifiers Notes
1. keydown 'Shift' shiftKey
2. keydown 'Q' shiftKey The default action is prevented, e.g., by invoking Event.preventDefault().
No beforeinput or input (or keypress, if supported) events are generated
3. keyup 'Q' shiftKey
4. keyup 'Shift'

If the key is a modifier key, the keystroke MUST still be taken into account for the modifiers states. The following example describes a possible sequence of keys to generate the Unicode character Q (Latin Capital Letter Q) on a PC/AT US keyboard using a US mapping:

Event Name KeyboardEvent
key
InputEvent
data
Modifiers Notes
1. keydown 'Shift' shiftKey The default action is prevented, e.g., by invoking Event.preventDefault().
2. keydown 'Q' shiftKey
3. beforeinput 'Q'
4. input
5. keyup 'Q' shiftKey
6. keyup 'Shift'

If the key is part of a sequence of several keystrokes, whether it is a dead key or it is contributing to an Input Method Editor sequence, the keystroke MUST be ignored (not taken into account) only if the default action is canceled on the keydown event. Canceling a dead key on a keyup event has no effect on beforeinput or input events. The following example uses the keystrokes '\u0302' (Combining Circumflex Accent key) and the key marked 'e' ('\u0065', Latin Small Letter E key) (on a PC/AT French keyboard using a French mapping and without any modifier activated):

Event Name KeyboardEvent
key
InputEvent
data
Notes
1. keydown '\u0302' The default action is prevented, e.g., by invoking Event.preventDefault().
2. keyup '\u0302'
3. keydown 'e'
4. beforeinput 'e'
5. input
6. keyup 'e'

Guidelines for selecting key values

This section is normative.

To determine the appropriate key values for a key, the user agent needs to consider the current function of the key (i.e., with modifiers), taking into account the keyboard layout mapping in use, to determine if the key is represented by the set of defined key values, if a corresponding Unicode character exists from which a key value MAY be derived, or if a new key value MUST be defined. The following algorithm determines the key value and character value to use:

  1. If the primary current function of the key is to generate a character, then:
    1. If there exists an appropriate character in the key values set, then the KeyboardEvent.key attribute MUST be a string consisting of the key value of that character.
    2. If there is no appropriate key value in the key values set, and there exists an appropriate Unicode code point, then the KeyboardEvent.key attribute MUST be a string consisting of the char value of that character.
  2. If the primary current function of the key is to serve as a function key, then:
    1. If there exists an appropriate key value in the key values set, then the KeyboardEvent.key attribute MUST be a string consisting of the key value of that character.
  • On a PC/AT US keyboard with a right-handed single-hand Dvorak key mapping, the key labeled 'Q' maps to the key values '5' (unmodified) and '%' (shifted). The primary function of this key is to generate the character '5' ('\u0035'). Since this character is a character (in Unicode general category Nd), the KeyboardEvent.key attribute value for the unmodified key will be '5'.
  • On a French PC keyboard with a standard French mapping, the primary function of the '^' key is as a dead key for the circumflex diacritical mark. The Unicode value for this key is '\u0302'.
  • On a Korean PC keyboard with a standard Korean mapping, the primary function of the 'Ha/En' key is to switch between Hangul and English input. The predefined key value list has an appropriate entry for this key, 'HangulMode', so this will be the key value.
  • On some models of mobile devices, there are special keys to launch specific applications. For a standard application like Calendar, there is a predefined key value of 'LaunchCalendar'. For applications not listed in the key value list, a new value may need to be defined.

While every attempt has been made to make this list of key values as complete as possible, new key values will periodically need to be defined as new input devices are introduced. Rather than allowing user agents to define their own key values (which may not work across multiple user agents), bugs should be filed so that this specification can be updated.

Keyboard Event key Value Tables

This section defines a list of key values which implementations MUST support, at a minimum, in addition to support for the full range of Unicode [Unicode] codepoints. Implementations MAY support additional key values, in a manner conforming to the guidelines for selecting and defining key values. The KeyboardEvent.key attribute of an event MUST always contain one of these control key or character values (even if the value is 'Unidentified'). If the key represents one of the set of printable control characters which has a Unicode character entry, such as the tab key, the KeyboardEvent.key attribute MUST have the key value (e.g., 'Tab').

Implementations that are unable to identify a key MUST use the key value 'Unidentified'.

Warning! Conforming implementations MUST only use 'Unidentified' as a key value when there is no way for the implementation to detect the key value. Exposing only this value MUST NOT indicate a conforming implementation.

The key values defined in this specification are based in part on the sets of keycodes from the java.awt.event.KeyEvent interface of the Java Platform, Standard Edition 6 API Specification [KeyEvent for Java], and the System.Windows.Forms.Keys key enumeration of the Microsoft .NET Framework 4.0 Class Library [Keys enumeration for .Net].

Note: The keys on the numeric keypad (e.g., the keypad '1' key) do not generate distinct key values from their non-keypad counterparts (e.g., the '1' key in the main part of the keyboard). The KeyboardEvent.location attribute can be used to determine if a key originated from the numeric keypad.

Note: There are special internationalization considerations for ECMAScript escaped characters. CharMod conformance [CharMod] expects the use of code points rather than surrogate pairs in escapes. ECMAScript escaped characters use surrogate pairs for characters outside the Basic Multilingual Plane ("\uD84E\uDDC2" for '𣧂', a Chinese character meaning untidy), rather than C-style fixed-length characters ("\U000239c2" for '𣧂') or delimited escapes such as Numeric Character References ("&#x239C2;"). Characters escaped in this manner:

  • are based on UTF-16 encoding, in that it uses surrogate pairs for values outside the Basic Multilingual Plane
  • are expressed using surrogate pairs, which makes it difficult for a human to look up the value, and might require unnecessary overhead for machine processing — this can also cause problems with software written in the incorrect belief that Unicode is a 16-bit character set
  • are problematic for characters on supplementary planes (emoji, or Chinese characters on plane 2), some of which are expected to be input using a keyboard
  • are not be suitable for Java or C, which use different escaping mechanisms (could be solved with a normalizing method)

The following sub-sections contain the normative list of case-sensitive key values, their character values (where applicable), an informative description of typical usage, and an informative categorization. A conforming implementation of the KeyboardEvent interface MUST support at least this set of values for use in the KeyboardEvent.key attributes, though not all values MAY be available on all platforms or devices.

Future versions of this specification MAY include key values not included here, which have become common since the publication of this specification.

Special Key Values

This key value is used when an implementation is unable to identify another key value, due to either hardware, platform, or software constraints.

Modifier Keys

The Alternative (Alt, Option, Menu) key. Enable alternate modifier function for interpreting concurrent or subsequent keyboard input. This key value is also used for the Apple 'Option' key. The Alternate Graphics (AltGr or AltGraph) key. This key is used enable the ISO Level 3 shift modifier (the standard 'Shift' key is the level 2 modifier). The Caps Lock (Capital) key. Toggle capital character lock function for interpreting subsequent keyboard input event. The Control (Ctrl) key, to enable control modifier function for interpreting concurrent or subsequent keyboard input. The Function switch (Fn) key. Activating this key simultaneously with another key changes that key's value to an alternate character or function. This key is often handled directly in the keyboard hardware and does not usually generate key events. The Function-Lock (FnLock, F-Lock) key. Activating this key switches the mode of the keyboard to changes some keys' values to an alternate character or function. This key is often handled directly in the keyboard hardware and does not usually generate key events. The Hyper key. The Meta key, to enable meta modifier function for interpreting concurrent or subsequent keyboard input. This key value is also used for the Apple 'Command' key. The Number Lock key, to toggle numer-pad mode function for interpreting subsequent keyboard input. The operating system key (e.g. the Windows Logo key). The Scroll Lock key, to toggle between scrolling and cursor movement modes. The Shift key, to enable shift modifier function for interpreting concurrent or subsequent keyboard input. The Super key. The Symbol modifier key (used on some virtual keyboards). The Symbol Lock key.

Whitespace Keys

The Enter key, to activate current selection or accept current input. This key value is also used for the 'Return' (Macintosh numpad) key. The Separator key, for context-sensitive text separators. The Horizontal Tabulation (Tab) key.

Note: The space or spacebar key is encoded as ' '.

Navigation Keys

The down arrow key, to navigate or traverse downward. The left arrow key, to navigate or traverse leftward. The right arrow key, to navigate or traverse rightward. The up arrow key, to navigate or traverse upward. The End key, used with keyboard entry to go to the end of content. The Home key, used with keyboard entry, to go to start of content. The Page Down key, to scroll down or display next page of content. The Page Up key, to scroll up or display previous page of content.

Editing Keys

The Backspace key. This key value is also used for the key labeled 'delete' on MacOS keyboards. The Clear key, for removing current selected input. The Copy key. The Cursor Select (Crsel) key. The Cut key. The Delete (Del) Key. This key value is also used for the key labeled 'delete' on MacOS keyboards when modified by the 'Fn' key. The Erase to End of Field key. This key deletes all characters from the current cursor position to the end of the current field. The Extend Selection (Exsel) key. The Insert (Ins) key, to toggle between text modes for insertion or overtyping. The Paste key. The Redo key. The Undo key.

UI Keys

The Accept (Commit, OK) key. Accept current option or input method sequence conversion. The Again key, to redo or repeat an action. The Attention (Attn) key. The Cancel key. Show the application's context menu. This key is commonly found between the right 'OS' key and the right 'Control' key. The Escape (Esc) key, to initiate an escape sequence. The Execute key. The Find key. Toggle display of help information. Pause the current state or application (as appropriate).

Note: Do not use this value for the pause button on media controllers. Use 'MediaPause' instead.

Play or resume the current state or application (as appropriate).

Note: Do not use this value for the play button on media controllers. Use 'MediaPlay' instead.

The properties (Props) key. The Select key. The ZoomIn key. The ZoomOut key.

Device Keys

The Brightness Down key. Typically controls the display brightness. The Brightness Up key. Typically controls the display brightness. The Camera key. Toggle removable media to eject (open) and insert (close) state. The LogOff key. Toggle power state.

Note: Some devices might not expose this key to the operating environment.

The PowerOff key. Sometime called "PowerDown". The Print Screen (PrintScrn, SnapShot) key, to initiate print-screen function. The Hibernate key. This key saves the current state of the computer to disk so that it can be restored. The computer will then shutdown. The Standby key. This key turns off the display and places the computer into a low-power mode without completely shutting down. It is sometimes called the "Suspend" or "Sleep" key. The WakeUp key.

IME and Composition Keys

The All Candidates key, to initate the multi-candidate mode. The Alphanumeric key. The Code Input key, to initiate the Code Input mode to allow characters to be entered by their code points. The Compose key, also known as Multi_key on the X Window System. This key acts in a manner similar to a dead key, triggering a mode where subsequent key presses are combined to produce a different character. The Convert key, to convert the current input method sequence. The Final Mode (Final) key used on some Asian keyboards, to enable the final mode for IMEs. Switch to the first character group. (ISO/IEC 9995) Switch to the last character group. (ISO/IEC 9995) Switch to the next character group. (ISO/IEC 9995) Switch to the previous character group. (ISO/IEC 9995) The Mode Change key, to toggle between or cycle through input modes of IMEs. The Next Candidate function key. The Nonconvert (Don't Convert) key, to accept current input method sequence without conversion in IMEs. The Previous Candidate function key. The Process key. The Single Candidate function key.

Keys specific to Korean keyboards

The Roman Characters function key, also known as the 'Youngja' or 'Young' key. The Hangul (Korean characters) Mode key, to toggle between Hangul and English modes. The Hanja (Korean characters) Mode key. The Junja (Korean characters) Mode key.

Keys specific to Japanese keyboards

The Zenkaku (Full-Width) Characters key. The (Half-Width) Characters key. The Zenkaku/Hankaku (full-width/half-width) toggle key. The Kana Mode (Kana Lock) key. The Kanji (Japanese name for ideographic characters of Chinese origin) Mode key. The Hiragana (Japanese Kana characters) key. The Katakana (Japanese Kana characters) key. The Hiragana/Katakana toggle key. The Eisu key. This key may close the IME, but it's purpose is defined by the current IME.

General-Purpose Function Keys

The exact number of these general purpose function keys varies on different platforms, and only the first few are defined explicitly here. Additional function key names are implicitly defined by incrementing the base-10 index at the end of the function key name. Thus, 'F24' and 'Soft8' are all valid key values.

The F1 key, a general purpose function key, as index 1. The F2 key, a general purpose function key, as index 2. The F3 key, a general purpose function key, as index 3. The F4 key, a general purpose function key, as index 4. The F5 key, a general purpose function key, as index 5. The F6 key, a general purpose function key, as index 6. The F7 key, a general purpose function key, as index 7. The F8 key, a general purpose function key, as index 8. The F9 key, a general purpose function key, as index 9. The F10 key, a general purpose function key, as index 10. The F11 key, a general purpose function key, as index 11. The F12 key, a general purpose function key, as index 12. General purpose virtual function key, as index 1. General purpose virtual function key, as index 2. General purpose virtual function key, as index 3. General purpose virtual function key, as index 4.

Multimedia Keys

These are extra keys found on "multimedia" keyboards.

Close the current document or message. Open an editor to forward the current message. Open an editor to reply to the current message. Send the current message. Toggle media between play and pause states. Select media. Stop media playing, pausing, forwarding, rewinding, or recording, if not already stopped. Seek to next media or program track. Seek to previous media or program track. Open a new document or message. Open an existing document or message. Print the current document or message. Save the current document or message. Spellcheck the current document or selection. Decrease audio volume. Increase audio volume. Toggle between muted state and prior volume level.

Application Keys

The Application Keys are special keys that are assigned to launch a particular application. Additional application key names can be defined by concatenating 'Launch' with the name of the application.

The 'Calculator' key. This is often the generic 'LaunchApplication' key, as index 2. The 'Calendar' key. The 'Mail' key. The 'Media Player' key. The 'Music Player' key. The 'My Computer' key. This is often the generic 'LaunchApplication' key, as index 1. The 'Screen Saver' key. The 'Spreadsheet' key. The 'Web Browser' key. The 'WebCam' key. The 'Word Processor' key.

Browser Keys

Navigate to previous content or page in current history. The Browser Favorites key. Navigate to next content or page in current history. The Browser Home key, used with keyboard entry, to go to the home page. The Browser Refresh key, to refresh the current page or content. The Browser Search key, to call up the user's preferred search page. The Browser Stop key, to stop loading the current page or content.

Media Controller Keys

The key values for media controllers (e.g. remote controls for television, audio systems, and set-top boxes) are derived in part from the consumer electronics technical specifications:

  • DTV Application Software Environment [DASE]
  • Open Cable Application Platform 1.1.3 [OCAP]
  • ANSI/CEA-2014-B, Web-based Protocol and Framework for Remote User Interface on UPnPTM Networks and the Internet [WEB4CE]

Adjust audio balance leftward. (VK_AUDIO_BALANCE_LEFT) Adjust audio balance rightward. (VK_AUDIO_BALANCE_RIGHT) Decrease audio bass boost or cycle down through bass boost states. (VK_BASS_BOOST_DOWN) Increase audio bass boost or cycle up through bass boost states. (VK_BASS_BOOST_UP) Adjust audio fader towards front. (VK_FADER_FRONT) Adjust audio fader towards rear. (VK_FADER_REAR) Advance surround audio mode to next available mode. (VK_SURROUND_MODE_NEXT) Select next (numerically or logically) lower channel. (VK_CHANNEL_DOWN) Select next (numerically or logically) higher channel. (VK_CHANNEL_UP) General purpose color-coded media function key, as index 0 (red). (VK_COLORED_KEY_0) General purpose color-coded media function key, as index 1 (green). (VK_COLORED_KEY_1) General purpose color-coded media function key, as index 2 (yellow). (VK_COLORED_KEY_2) General purpose color-coded media function key, as index 3 (blue). (VK_COLORED_KEY_3) General purpose color-coded media function key, as index 4 (grey). (VK_COLORED_KEY_4) General purpose color-coded media function key, as index 5 (brown). (VK_COLORED_KEY_5) Toggle the display of Closed Captions. (VK_CC) Adjust brightness of device, by toggling between or cycling through states. (VK_DIMMER) Swap video sources. (VK_DISPLAY_SWAP) Exit the current application. (VK_EXIT) Clear program or content stored as favorite 0. (VK_CLEAR_FAVORITE_0) Clear program or content stored as favorite 1. (VK_CLEAR_FAVORITE_1) Clear program or content stored as favorite 2. (VK_CLEAR_FAVORITE_2) Clear program or content stored as favorite 3. (VK_CLEAR_FAVORITE_3) Select (recall) program or content stored as favorite 0. (VK_RECALL_FAVORITE_0) Select (recall) program or content stored as favorite 1. (VK_RECALL_FAVORITE_1) Select (recall) program or content stored as favorite 2. (VK_RECALL_FAVORITE_2) Select (recall) program or content stored as favorite 3. (VK_RECALL_FAVORITE_3) Store current program or content as favorite 0. (VK_STORE_FAVORITE_0) Store current program or content as favorite 1. (VK_STORE_FAVORITE_1) Store current program or content as favorite 2. (VK_STORE_FAVORITE_2) Store current program or content as favorite 3. (VK_STORE_FAVORITE_3) Toggle display of program or content guide. (VK_GUIDE) If guide is active and displayed, then display next day's content. (VK_NEXT_DAY) If guide is active and displayed, then display previous day's content. (VK_PREV_DAY) Toggle display of information about currently selected context or media. (VK_INFO) Toggle instant replay. (VK_INSTANT_REPLAY) Launch linked content, if available and appropriate. (VK_LINK) List the current program. (VK_LIST) Toggle display listing of currently available live content or programs. (VK_LIVE) Lock or unlock current content or program. (VK_LOCK) Show a list of media applications. (VK_APPS)

Note: Do not confuse this key value with the Windows' VK_APPS / VK_CONTEXT_MENU key, which is encoded as 'ContextMenu'.

Initiate or continue forward playback at faster than normal speed, or increase speed if already fast forwarding. (VK_FAST_FWD) Select previously selected channel or media. (VK_LAST) Pause the currently playing media. (VK_PAUSE)

Note: Media controller devices should use this value rather than 'Pause' for their pause keys.

Initiate or continue media playback at normal speed, if not currently playing at normal speed. (VK_PLAY) Initiate or resume recording of currently selected media. (VK_RECORD) Initiate or continue reverse playback at faster than normal speed, or increase speed if already rewinding. (VK_REWIND) Skip forward to next content or program. (VK_SKIP) Cycle to next favorite channel (in favorites list). (VK_NEXT_FAVORITE_CHANNEL) Cycle to next user profile (if there are multiple user profiles). (VK_USER) Access on-demand content or programs. (VK_ON_DEMAND) Move picture-in-picture window down. (VK_PINP_DOWN) Move picture-in-picture window. (VK_PINP_MOVE) Toggle display of picture-in-picture window. (VK_PINP_TOGGLE) Move picture-in-picture window up. (VK_PINP_UP) Decrease media playback speed. (VK_PLAY_SPEED_DOWN) Reset playback to normal speed. (VK_PLAY_SPEED_RESET) Increase media playback speed. (VK_PLAY_SPEED_UP) Toggle random media or content shuffle mode. (VK_RANDOM_TOGGLE) Not a physical key, but this key code is sent when the remote control battery is low. (VK_RC_LOW_BATTERY) Toggle or cycle between media recording speeds. (VK_RECORD_SPEED_NEXT) Toggle RF (radio frequency) input bypass mode (pass RF input directly to the RF output). (VK_RF_BYPASS) Toggle scan channels mode. (VK_SCAN_CHANNELS_TOGGLE) Advance display screen mode to next available mode. (VK_SCREEN_MODE_NEXT) Toggle display of device settings screen. (VK_SETTINGS) Toggle split screen mode. (VK_SPLIT_SCREEN_TOGGLE) Toggle display of subtitles, if available. (VK_SUBTITLE) Toggle display of teletext, if available (VK_TELETEXT). Advance video mode to next available mode.(VK_VIDEO_MODE_NEXT) Cause device to identify itself in some manner, e.g., audibly or visibly. (VK_WINK) Toggle between full-screen and scaled content, or alter magnification level. (VK_ZOOM)

Some of the keys defined in the media controller standards already have appropriate keys defined in other sections of this specification. These following table summarizes the key values that MUST be used:

Navigate to previous content or page in current history. (VK_BACK) Navigate to next content or page in current history. (VK_FORWARD) Toggle display of the on-screen menu. (VK_MENU) Toggle removable media to eject (open) and insert (close) state. (VK_EJECT_TOGGLE) The End key, used with keyboard entry to go to the end of content. (VK_GO_TO_END) The Enter key, to activate current selection or accept current input. (VK_SELECT) The Home key, used with keyboard entry, to go to start of content. (VK_GO_TO_START) Toggle media between play and pause states. (VK_PLAY_PAUSE) Stop media playing, pausing, forwarding, rewinding, or recording, if not already stopped. (VK_STOP) Seek to next media or program track. (VK_TRACK_NEXT) Seek to previous media or program track. (VK_TRACK_PREV) Toggle power state. (VK_POWER) This key value is used when an implementations is unable to identify another key value, due to either hardware, platform, or software constraints. (VK_UNDEFINED) Decrease audio volume. (VK_VOLUME_DOWN) Increase audio volume. (VK_VOLUME_UP) Toggle between muted state and prior volume level. (VK_VOLUME_MUTE)

Legacy Event Initializers

This section is informative

Early versions of this specification included an initialization method on the interface (for example initMouseEvent) that required a long list of parameters that, in most cases, did not fully initialize all attributes of the event object. Because of this, event interfaces which were derived from the basic Event interface required that the initializer of each of the derived interfaces be called explicitly in order to fully initialize an event.

Initializing all the attributes of a MutationEvent requires calls to two initializer methods: initEvent and initMutationEvent.

Due in part to the length of time in the development of this standard, some implementations MAY have taken a dependency on these (now deprecated) initializer methods. For completeness, these legacy event intializers are described in this Appendix.

Legacy Event Initializer Interfaces

This section is informative

This section documents legacy initializer methods that were introduced in earlier versions of the DOM Level 3 Events specification.

Initializers for interface CustomEvent

// Originally introduced (and deprecated) in DOM Level 3
void initCustomEvent()

Initializes attributes of a CustomEvent object. This method has the same behavior as Event.initEvent().

Warning! The initCustomEvent method is deprecated.

DOMString typeArg

Refer to the Event.initEvent() method for a description of this parameter.

boolean bubblesArg

Refer to the Event.initEvent() method for a description of this parameter.

boolean cancelableArg

Refer to the Event.initEvent() method for a description of this parameter.

any detailArg

Specifies CustomEvent.detail.

Initializers for interface UIEvent

// Deprecated in DOM Level 3
void initUIEvent()

Initializes attributes of an UIEvent object. This method has the same behavior as Event.initEvent().

Warning! The initUIEvent method is deprecated, but supported for backwards-compatibility with widely-deployed implementations.

DOMString typeArg

Refer to the Event.initEvent() method for a description of this parameter.

boolean bubblesArg

Refer to the Event.initEvent() method for a description of this parameter.

boolean cancelableArg

Refer to the Event.initEvent() method for a description of this parameter.

Window? viewArg

Specifies UIEvent.view. This value MAY be null.

long detailArg

Specifies UIEvent.detail.

Initializers for interface FocusEvent

// Originally introduced (and deprecated) in DOM Level 3
void initFocusEvent()

Initializes attributes of a FocusEvent object. This method has the same behavior as UIEvent.initUIEvent().

Warning! The initFocusEvent method is deprecated.

DOMString typeArg

Refer to the UIEvent.initUIEvent() method for a description of this parameter.

boolean bubblesArg

Refer to the UIEvent.initUIEvent() method for a description of this parameter.

boolean cancelableArg

Refer to the UIEvent.initUIEvent() method for a description of this parameter.

Window? viewArg

Refer to the UIEvent.initUIEvent() method for a description of this parameter.

long detailArg

Refer to the UIEvent.initUIEvent() method for a description of this parameter.

EventTarget? relatedTargetArg

Specifies FocusEvent.relatedTarget. This value MAY be null.

Initializers for interface MouseEvent

// Deprecated in DOM Level 3
void initMouseEvent()

Initializes attributes of a MouseEvent object. This method has the same behavior as UIEvent.initUIEvent().

Warning! The initMouseEvent method is deprecated, but supported for backwards-compatibility with widely-deployed implementations.

DOMString typeArg

Refer to the UIEvent.initUIEvent() method for a description of this parameter.

boolean bubblesArg

Refer to the UIEvent.initUIEvent() method for a description of this parameter.

boolean cancelableArg

Refer to the UIEvent.initUIEvent() method for a description of this parameter.

Window? viewArg

Refer to the UIEvent.initUIEvent() method for a description of this parameter.

long detailArg

Refer to the UIEvent.initUIEvent() method for a description of this parameter.

long screenXArg

Specifies MouseEvent.screenX.

long screenYArg

Specifies MouseEvent.screenY.

long clientXArg

Specifies MouseEvent.clientX.

long clientYArg

Specifies MouseEvent.clientY.

boolean ctrlKeyArg

Specifies MouseEvent.ctrlKey.

boolean altKeyArg

Specifies MouseEvent.altKey.

boolean shiftKeyArg

Specifies MouseEvent.shiftKey.

boolean metaKeyArg

Specifies MouseEvent.metaKey.

short buttonArg

Specifies MouseEvent.button.

EventTarget? relatedTargetArg

Specifies MouseEvent.relatedTarget. This value MAY be null.

Initializers for interface WheelEvent

// Originally introduced (and deprecated) in DOM Level 3
void initWheelEvent()

Initializes attributes of a WheelEvent object. This method has the same behavior as MouseEvent.initMouseEvent().

Warning! The initWheelEvent method is deprecated.

DOMString typeArg

Refer to the UIEvent.initUIEvent() method for a description of this parameter.

boolean bubblesArg

Refer to the UIEvent.initUIEvent() method for a description of this parameter.

boolean cancelableArg

Refer to the UIEvent.initUIEvent() method for a description of this parameter.

Window? viewArg

Refer to the UIEvent.initUIEvent() method for a description of this parameter.

long detailArg

Refer to the UIEvent.initUIEvent() method for a description of this parameter.

long screenXArg

Refer to the MouseEvent.initMouseEvent() method for a description of this parameter.

long screenYArg

Refer to the MouseEvent.initMouseEvent() method for a description of this parameter.

long clientXArg

Refer to the MouseEvent.initMouseEvent() method for a description of this parameter.

long clientYArg

Refer to the MouseEvent.initMouseEvent() method for a description of this parameter.

short buttonArg

Refer to the MouseEvent.initMouseEvent() method for a description of this parameter.

EventTarget? relatedTargetArg

Refer to the MouseEvent.initMouseEvent() method for a description of this parameter.

DOMString modifiersListArg

A white space separated list of modifier key values to be activated on this object. As an example, "Control Shift" marks the control and shift modifiers as activated (the MouseEvent.ctrlKey and MouseEvent.shiftKey inherited attributes will be true on the initialized WheelEvent object).

double deltaXArg

Specifies WheelEvent.deltaX.

double deltaYArg

Specifies WheelEvent.deltaY.

double deltaZArg

Specifies WheelEvent.deltaZ.

unsigned long deltaMode

Specifies WheelEvent.deltaMode.

Initializers for interface KeyboardEvent

// Originally introduced (and deprecated) in DOM Level 3
void initKeyboardEvent()

Initializes attributes of a KeyboardEvent object. This method has the same behavior as UIEvent.initUIEvent(). The value of UIEvent.detail remains undefined.

Warning! The initKeyboardEvent method is deprecated.

DOMString typeArg

Refer to the UIEvent.initUIEvent() method for a description of this parameter.

boolean bubblesArg

Refer to the UIEvent.initUIEvent() method for a description of this parameter.

boolean cancelableArg

Refer to the UIEvent.initUIEvent() method for a description of this parameter.

Window? viewArg

Refer to the UIEvent.initUIEvent() method for a description of this parameter.

long detailArg

Refer to the UIEvent.initUIEvent() method for a description of this parameter.

DOMString keyArg

Specifies KeyboardEvent.key.

unsigned long locationArg

Specifies KeyboardEvent.location.

DOMString modifiersListArg

A white space separated list of modifier key values to be activated on this object. As an example, "Control Alt" marks the control and alt modifiers as activated.

boolean repeat

Specifies whether the key event is repeating. See KeyboardEvent.repeat.

Initializers for interface CompositionEvent

// Originally introduced (and deprecated) in DOM Level 3
void initCompositionEvent()

Initializes attributes of a CompositionEvent object. This method has the same behavior as UIEvent.initUIEvent(). The value of UIEvent.detail remains undefined.

Warning! The initCompositionEvent method is deprecated.

DOMString typeArg

Refer to the UIEvent.initUIEvent() method for a description of this parameter.

boolean bubblesArg

Refer to the UIEvent.initUIEvent() method for a description of this parameter.

boolean cancelableArg

Refer to the UIEvent.initUIEvent() method for a description of this parameter.

Window? viewArg

Refer to the UIEvent.initUIEvent() method for a description of this parameter.

DOMString? dataArg

Specifies CompositionEvent.data.

DOMString? locale

Specifies the locale attribute of the CompositionEvent. This attribute is not defined in DOM3, but will be included in the [UI Events] specification. User agents which do not support locale should ignore this parameter.

Legacy Key Attributes

This section is informative

This section provides a non-normative description of the attributes that are currently used when handling keyboard events.

These features were never formally specified and the current browser implementations vary in significant ways. The large amount of legacy content, including script libraries, that relies upon detecting the user agent and acting accordingly means that any attempt to formalize these legacy attributes and events would risk breaking as much content as it would fix or enable. Additionally, these attributes are not suitable for international usage, nor do they address accessibility concerns.

Therefore, this specification does not normatively define the events and attributes commonly employed for handling keyboard input, though they MAY be present in user agents for compatibility with legacy content. Authors SHOULD use the KeyboardEvent.key attribute instead of the charCode and keyCode attributes.

However, for the purpose of documenting the current state of these features and their relation to normative events and attributes, this section provides an informative description. For implementations which do support these attributes and events, it is suggested that the definitions provided in this section be used.

Legacy KeyboardEvent supplemental interface

This section is informative

Browser support for keyboards has traditionally relied on three ad-hoc attributes, keyCode, charCode, and which.

All three of these attributes return a numerical code that represents some aspect of the key pressed: keyCode is an index of the key itself. charCode is the ASCII value of the character keys. which is the character value where available and otherwise the key index. The values for these attributes, and the availability of the attribute, is inconsistent across platforms, keyboard languages and layouts, user agents, versions, and even event types.

Interface KeyboardEvent (supplemental)

Introduced in DOM Level 3

The partial KeyboardEvent interface is an informative extension of the KeyboardEvent interface, which adds the charCode, keyCode, and which attributes.

The partial KeyboardEvent interface can be obtained by using the DocumentEvent.createEvent("KeyboardEvent") method call in implementations that support this extension.

// The following support legacy user agents
readonly attribute unsigned long charCode

charCode holds a character value, for keypress events which generate character input. The value is the Unicode reference number (code point) of that character (e.g. event.charCode = event.char.charCodeAt(0)). For keydown or keyup events, the value of charCode is 0.

readonly attribute unsigned long keyCode

keyCode holds a system- and implementation-dependent numerical code signifying the unmodified identifier associated with the key pressed. Unlike the KeyboardEvent.key attribute, the set of possible values are not normatively defined in this specification. Typically, these value of the keyCode SHOULD represent the decimal codepoint in ASCII [RFC20][US-ASCII] or Windows 1252 [WIN1252], but MAY be drawn from a different appropriate character set. Implementations that are unable to identify a key use the key value '0'.

See Legacy key models for more details on how to determine the values for keyCode.

readonly attribute unsigned long which

which holds a system- and implementation-dependent numerical code signifying the unmodified identifier associated with the key pressed. In most cases, the value is identical to keyCode.

dictionary KeyboardEventInit (supplemental)

Browsers that include support for keyCode, charCode, and which in KeyboardEvent should also add the following members to the KeyboardEventInit dictionary.

The partial KeyboardEventInit dictionary is an informative extension of the KeyboardEventInit dictionary, which adds charCode, keyCode, and which members to initialize the corresponding KeyboardEvent attributes.

unsigned long charCode = 0

Initializes the charCode attribute of the KeyboardEvent to the Unicode code point for the event's character.

unsigned long keyCode = 0

Initializes the keyCode attribute of the KeyboardEvent to the system- and implementation-dependent numerical code signifying the unmodified identifier associated with the key pressed.

unsigned long which = 0

Initializes the which attribute of the KeyboardEvent to the implementation-dependent numerical code signifying the unmodified identifier associated with the key pressed. In most cases, the value is identical to keyCode.

Legacy key models

This section is informative

Implementations differ on which values are exposed on these attributes for different event types. An implementation MAY choose to expose both virtual key codes and character codes in the keyCode property (conflated model), or report separate keyCode and charCode properties (split model).

How to determine keyCode for keydown and keyup events

The keyCode for keydown or keyup events is calculated as follows:

  1. Read the virtual key code from the operating system's event information, if such information is available.
  2. If an Input Method Editor is processing key input and the event is keydown, return 229.
  3. If input key when pressed without modifiers would insert a numerical character (0-9), return the ASCII code of that numerical character.
  4. If input key when pressed without modifiers would insert a lower case character in the a-z alphabetical range, return the ASCII code of the upper case equivalent.
  5. If the implementation supports a key code conversion table for the operating system and platform, look up the value. If the conversion table specifies an alternate virtual key value for the given input, return the specified value.
  6. If the key's function, as determined in an implementation-specific way, corresponds to one of the keys in the table of fixed virtual key codes, return the corresponding key code.
  7. Return the virtual key code from the operating system.
  8. If no key code was found, return 0.

How to determine keyCode for keypress events

The keyCode for keypress events is calculated as follows:

  1. If the implementation supports a conflated model, set keyCode to the Unicode code point of the character being entered.
  2. If the implementation supports a split model, set keyCode to 0.

Fixed virtual key codes

The virtual key codes for the following keys do not usually change with keyboard layouts on desktop systems:

Key Virtual Key
Code
Notes
'Backspace' 8
'Tab' 9
'Enter' 13
'Shift' 16
'Control' 17
'Alt' 18
'CapsLock' 20
'Escape' 27 Esc
' ' 32 Space
'PageUp' 33
'PageDown' 34
'End' 35
'Home' 36
'ArrowLeft' 37
'ArrowUp' 38
'ArrowRight' 39
'ArrowDown' 40
'Delete' 46 Del

Optionally fixed virtual key codes

The following punctuation characters MAY change virtual codes between keyboard layouts, but reporting these values will likely be more compatible with legacy content expecting US-English keyboard layout:

Key Character Virtual Key
Code
Semicolon ';' 186
Colon ':' 186
Equals sign '=' 187
Plus '+' 187
Comma ',' 188
Less than sign '<' 188
Minus '-' 189
Underscore '_' 189
Period '.' 190
Greater than sign '>' 190
Forward slash '/' 191
Question mark '?' 191
Backtick '`' 192
Tilde '~' 192
Opening square bracket '[' 219
Opening curly brace '{' 219
Backslash '\' 220
Pipe '|' 220
Closing square bracket ']' 221
Closing curly brace '}' 221
Single quote ''' 222
Double quote '"' 222

Legacy Event Types

This section is informative

This section provides a non-normative description of the event types that are deprecated in this document.

The purpose of this section is to document the current state of these features and their relation to normative events. For implementations which do support these events, it is suggested that the definitions provided in this section be used.

The following table provides an informative summary of the event types which are deprecated in this specification. They are included here for reference and completeness.

Event Type Sync / Async Bubbling phase Trusted event target types DOM interface Cancelable Default Action
DOMActivate Sync Yes Element UIEvent Yes None
DOMAttrModified Sync Yes Element MutationEvent No None
DOMCharacterDataModified Sync Yes Text, Comment, CDATASection, ProcessingInstruction MutationEvent No None
DOMFocusIn Sync Yes Element FocusEvent No None
DOMFocusOut Sync Yes Element FocusEvent No None
DOMNodeInserted Sync Yes Element, Attr, Text, Comment, CDATASection, DocumentType, EntityReference, ProcessingInstruction MutationEvent No None
DOMNodeInsertedIntoDocument Sync No Element, Attr, Text, Comment, CDATASection, DocumentType, EntityReference, ProcessingInstruction MutationEvent No None
DOMNodeRemoved Sync Yes Element, Attr, Text, Comment, CDATASection, DocumentType, EntityReference, ProcessingInstruction MutationEvent No None
DOMNodeRemovedFromDocument Sync No Element, Attr, Text, Comment, CDATASection, DocumentType, EntityReference, ProcessingInstruction MutationEvent No None
DOMSubtreeModified Sync Yes Window, Document, DocumentFragment, Element, Attr MutationEvent No None
keypress Sync Yes Document, Element KeyboardEvent Yes Varies: launch text composition system; blur and focus events; DOMActivate event; other event

Legacy UIEvent events

DOMActivate
Type DOMActivate
Interface UIEvent
Sync / Async Sync
Bubbles Yes
Target Element
Cancelable Yes
Default action None
Context info

A user agent MUST dispatch this event when a button, link, or other state-changing element is activated. Refer to Activation triggers and behavior for more details.

Warning! The DOMActivate event type is defined in this specification for reference and completeness, but this specification deprecates the use of this event type in favor of the related event type click. Other specifications MAY define and maintain their own DOMActivate event type for backwards compatibility.

Note: While DOMActivate and click are not completely equivalent, implemented behavior for the click event type has developed to encompass the most critical accessibility aspects for which the DOMActivate event type was designed, and is more widely implemented. Content authors are encouraged to use the click event type rather than the related mousedown or mouseup event type to ensure maximum accessibility.

Implementations which support the DOMActivate event type SHOULD also dispatch a DOMActivate event as a default action of a click event which is associated with an activation trigger. However, such implementations SHOULD only initiate the associated activation behavior once for any given occurrence of an activation trigger.

The DOMActivate event type is REQUIRED to be supported for XForms [XFORMS], which is intended for implementation within a host language. In a scenario where a plugin or script-based implementation of XForms is intended for installation in a native implementation of this specification which does not support the DOMActivate event type, the XForms user agent has to synthesize and dispatch its own DOMActivate events based on the appropriate activation triggers.

Thus, when a click event is dispatched by the DOM Level 3 Events user agent, the XForms user agent has to determine whether to synthesize a DOMActivate event with the same relevant properties as a default action of that click event. Appropriate cues might be whether the click event is trusted, or whether its event target has a DOMActivate event listener registered.

Authoring Note: Don't rely upon the interoperable support of DOMActivate in many user agents. Instead, the click event type should be used since it will provide more accessible behavior due to broader implementation support.

Warning! The DOMActivate event type is deprecated in this specification.

Activation event order

If the DOMActivate event is supported by the user agent, then the events MUST be dispatched in a set order relative to each other: (with only pertinent events listed):

1. click
2. DOMActivate default action, if supported by the user agent; synthesized; trusted="false"
3. All other default actions, including the activation behavior

If the focused element is activated by a key event, then the following shows the typical sequence of events (with only pertinent events listed):

1. keydown MUST be a key which can activate the element, such as the 'Enter' or ' ' key, or the element is not activated
2. click default action; synthesized; trusted="false"
3. DOMActivate default action, if supported by the user agent; synthesized; trusted="false"
4. All other default actions, including the activation behavior

Legacy FocusEvent events

DOMFocusIn
Type DOMFocusIn
Interface FocusEvent
Sync / Async Sync
Bubbles Yes
Target Element
Cancelable No
Default action None
Context info

A user agent MUST dispatch this event when an event target receives focus. The focus MUST be given to the element before the dispatch of this event type. This event type MUST be dispatched after the event type focus.

Warning! The DOMFocusIn event type is defined in this specification for reference and completeness, but this specification deprecates the use of this event type in favor of the related event types focus and focusin.

DOMFocusOut
Type DOMFocusOut
Interface FocusEvent
Sync / Async Sync
Bubbles Yes
Target Element
Cancelable No
Default action None
Context info

A user agent MUST dispatch this event when an event target loses focus. The focus MUST be taken from the element before the dispatch of this event type. This event type MUST be dispatched after the event type blur.

Warning! The DOMFocusOut event type is defined in this specification for reference and completeness, but this specification deprecates the use of this event type in favor of the related event types blur and focusout.

Legacy FocusEvent event order

The following is the typical sequence of events when a focus is shifted between elements, including the deprecated DOMFocusIn and DOMFocusOut events. The order shown assumes that no element is initially focused.

User shifts focus
1. focusin Sent before first target element receives focus
2. focus Sent after first target element receives focus
3. DOMFocusIn If supported
User shifts focus
4. focusout Sent before first target element loses focus
5. focusin Sent before second target element receives focus
6. blur Sent after first target element loses focus
7. DOMFocusOut If supported
8. focus Sent after second target element receives focus
9. DOMFocusIn If supported

Legacy KeyboardEvent events

The keypress event is the traditional method for capturing key events and processing them before the DOM is updated with the effects of the key press. Code that makes use of the keypress event typically relies on the legacy charCode, keyCode, and which attributes.

Note that the keypress event is specific to key events, and has been replaced by the more general event sequence of beforeinput and input events. These new input events are not specific to keyboard actions and can be used to capture user input regardless of the original source.

keypress
Type keypress
Interface KeyboardEvent
Sync / Async Sync
Bubbles Yes
Target Document, Element
Cancelable Yes
Default action Varies: launch text composition system; blur and focus events; DOMActivate event; other event
Context info

If supported by a user agent, this event MUST be dispatched when a key is pressed down, if and only if that key normally produces a character value. The keypress event type is device dependent and relies on the capabilities of the input devices and how they are mapped in the operating system.

This event type MUST be generated after the key mapping. It MUST NOT be fired when using an input method editor.

If this event is canceled, it should prevent the input event from firing, in addition to canceling the default action.

Authors SHOULD use the beforeinput event instead of the keypress event.

Note: The keypress event is traditionally associated with detecting a character value rather than a physical key, and might not be available on all keys in some configurations.

Warning!

The keypress event type is defined in this specification for reference and completeness, but this specification deprecates the use of this event type. When in editing contexts, authors can subscribe to the beforeinput event instead.

keypress event order

The keypress event type MUST be dispatched after the keydown event and before the keyup event associated with the same key.

The keypress event type MUST be dispatched after the beforeinput event and before the input event associated with the same key.

The sequence of key events for user-agents the support the keypress event is demonstrated in the following example:

Event Name KeyboardEvent
key
InputEvent
data
1. keydown 'a'
2. beforeinput 'a'
3. keypress 'a'
Any default actions related to this key, such as inserting a character in to the DOM.
4. input
5. keyup 'a'

Legacy MutationEvent events

The mutation and mutation name event modules are designed to allow notification of any changes to the structure of a document, including attribute, text, or name modifications.

Note: None of the event types associated with the MutationEvent interface are designated as cancelable. This stems from the fact that it is very difficult to make use of existing DOM interfaces which cause document modifications if any change to the document might or might not take place due to cancelation of the resulting event. Although this is still a desired capability, it was decided that it would be better left until the addition of transactions into the DOM.

Many single modifications of the tree can cause multiple mutation events to be dispatched. Rather than attempt to specify the ordering of mutation events due to every possible modification of the tree, the ordering of these events is left to the implementation.

Warning!

The MutationEvent interface was introduced in DOM Level 2 Events, but has not yet been completely and interoperably implemented across user agents. In addition, there have been critiques that the interface, as designed, introduces a performance and implementation challenge.

DOM4 [DOM4] provides a new mechanism using a MutationObserver interface which addresses the use cases that mutation events solve, but in a more performant manner. Thus, this specification describes mutation events for reference and completeness of legacy behavior, but deprecates the use of the MutationEvent interface.

Interface MutationEvent

Introduced in DOM Level 2, deprecated in DOM Level 3

The MutationEvent interface provides specific contextual information associated with Mutation events.

To create an instance of the MutationEvent interface, use the DocumentEvent.createEvent("MutationEvent") method call.

// attrChangeType
const unsigned short MODIFICATION = 1

The Attr was modified in place.

const unsigned short ADDITION = 2

The Attr was just added.

const unsigned short REMOVAL = 3

The Attr was just removed.

readonly attribute Node? relatedNode

relatedNode MUST be used to identify a secondary node related to a mutation event. For example, if a mutation event is dispatched to a node indicating that its parent has changed, the relatedNode will be the changed parent. If an event is instead dispatched to a subtree indicating a node was changed within it, the relatedNode MUST be the changed node. In the case of the DOMAttrModified event, it indicates the Attr node which was modified, added, or removed.

The un-initialized value of this attribute MUST be null.

readonly attribute DOMString prevValue

prevValue indicates the previous value of the Attr node in DOMAttrModified events, and of the CharacterData node in DOMCharacterDataModified events.

The un-initialized value of this attribute MUST be "" (the empty string).

readonly attribute DOMString newValue

newValue indicates the new value of the Attr node in DOMAttrModified events, and of the CharacterData node in DOMCharacterDataModified events.

The un-initialized value of this attribute MUST be "" (the empty string).

readonly attribute DOMString attrName

attrName indicates the name of the changed Attr node in a DOMAttrModified event.

The un-initialized value of this attribute MUST be "" (the empty string).

readonly attribute unsigned short attrChange

attrChange indicates the type of change which triggered the DOMAttrModified event. The values can be MODIFICATION, ADDITION, or REMOVAL.

The un-initialized value of this attribute MUST be 0.

Note: There is no defined constant for the attrChange value of 0 (the un-initialized value).

void initMutationEvent()

Initializes attributes of a MutationEvent object. This method has the same behavior as Event.initEvent().

DOMString typeArg

Refer to the Event.initEvent() method for a description of this parameter.

boolean bubblesArg

Refer to the Event.initEvent() method for a description of this parameter.

boolean cancelableArg

Refer to the Event.initEvent() method for a description of this parameter.

Node? relatedNodeArg

Specifies MutationEvent.relatedNode.

DOMString prevValueArg

Specifies MutationEvent.prevValue. This value MAY be the empty string.

DOMString newValueArg

Specifies MutationEvent.newValue. This value MAY be the empty string.

DOMString attrNameArg

Specifies MutationEvent.attrName. This value MAY be the empty string.

unsigned short attrChangeArg

Specifies MutationEvent.attrChange. This value MAY be 0.

The mutation event types are listed below.

DOMAttrModified
Type DOMAttrModified
Interface MutationEvent
Sync / Async Sync
Bubbles Yes
Target Element
Cancelable No
Default action None
Context info

A user agent MUST dispatch this event after an Attr.value has been modified and after an Attr node has been added to or removed from an Element. The event target of this event MUST be the Element node where the change occurred. It is implementation dependent whether this event type occurs when the children of the Attr node are changed in ways that do not affect the value of Attr.value.

Warning! The DOMAttrModified event type is defined in this specification for reference and completeness, but this specification deprecates the use of this event type.

DOMCharacterDataModified
Type DOMCharacterDataModified
Interface MutationEvent
Sync / Async Sync
Bubbles Yes
Target Text, Comment, CDATASection, ProcessingInstruction
Cancelable No
Default action None
Context info

A user agent MUST dispatch this event after CharacterData.data or ProcessingInstruction.data have been modified, but the node itself has not been inserted or deleted. The event target of this event MUST be the CharacterData node or the ProcessingInstruction node.

Warning! The DOMCharacterDataModified event type is defined in this specification for reference and completeness, but this specification deprecates the use of this event type.

DOMNodeInserted
Type DOMNodeInserted
Interface MutationEvent
Sync / Async Sync
Bubbles Yes
Target Element, Attr, Text, Comment, CDATASection, DocumentType, EntityReference, ProcessingInstruction
Cancelable No
Default action None
Context info

A user agent MUST dispatch this event type when a node other than an Attr node has been added as a child of another node. A user agent MAY dispatch this event when an Attr node has been added to an Element node (see note below). This event MUST be dispatched after the insertion has taken place. The event target of this event MUST be the node being inserted.

Note: For detecting attribute insertion, use the DOMAttrModified event type instead.

Warning! The DOMNodeInserted event type is defined in this specification for reference and completeness, but this specification deprecates the use of this event type.

DOMNodeInsertedIntoDocument
Type DOMNodeInsertedIntoDocument
Interface MutationEvent
Sync / Async Sync
Bubbles No
Target Element, Attr, Text, Comment, CDATASection, DocumentType, EntityReference, ProcessingInstruction
Cancelable No
Default action None
Context info

A user agent MUST dispatch this event when a node has been inserted into a document, either through direct insertion of the node or insertion of a subtree in which it is contained. A user agent MAY treat an Attr node as part of an Element's subtree. This event MUST be dispatched after the insertion has taken place. The event target of this event MUST be the node being inserted. If the node is being directly inserted, the event type DOMNodeInserted MUST occur before this event type.

Warning! The DOMNodeInsertedIntoDocument event type is defined in this specification for reference and completeness, but this specification deprecates the use of this event type.

DOMNodeRemoved
Type DOMNodeRemoved
Interface MutationEvent
Sync / Async Sync
Bubbles Yes
Target Element, Attr, Text, Comment, CDATASection, DocumentType, EntityReference, ProcessingInstruction
Cancelable No
Default action None
Context info

A user agent MUST dispatch this event when a node other than an Attr node is being removed from its parent node. A user agent MAY dispatch this event when an Attr node is being removed from its ownerElement (see note below). This event MUST be dispatched before the removal takes place. The event target of this event MUST be the node being removed.

Note: For reliably detecting attribute removal, use the DOMAttrModified event type instead.

Warning! The DOMNodeRemoved event type is defined in this specification for reference and completeness, but this specification deprecates the use of this event type.

DOMNodeRemovedFromDocument
Type DOMNodeRemovedFromDocument
Interface MutationEvent
Sync / Async Sync
Bubbles No
Target Element, Attr, Text, Comment, CDATASection, DocumentType, EntityReference, ProcessingInstruction
Cancelable No
Default action None
Context info

A user agent MUST dispatch this event when a node is being removed from a document, either through direct removal of the node or removal of a subtree in which it is contained. A user agent MAY treat an Attr node as part of an Element's subtree. This event MUST be dispatched before the removal takes place. The event target of this event type MUST be the node being removed. If the node is being directly removed, the event type DOMNodeRemoved MUST occur before this event type.

Note: For reliably detecting attribute removal, use the DOMAttrModified event type instead.

Warning! The DOMNodeRemovedFromDocument event type is defined in this specification for reference and completeness, but this specification deprecates the use of this event type.

DOMSubtreeModified
Type DOMSubtreeModified
Interface MutationEvent
Sync / Async Sync
Bubbles Yes
Target Window, Document, DocumentFragment, Element, Attr
Cancelable No
Default action None
Context info

This is a general event for notification of all changes to the document. It can be used instead of the more specific mutation and mutation name events. It MAY be dispatched after a single modification to the document or, at the implementation's discretion, after multiple changes have occurred. The latter case SHOULD generally be used to accommodate multiple changes which occur either simultaneously or in rapid succession. The target of this event MUST be the lowest common parent of the changes which have taken place. This event MUST be dispatched after any other events caused by the mutation(s) have occurred.

Warning! The DOMSubtreeModified event type is defined in this specification for reference and completeness, but this specification deprecates the use of this event type.

Extending Events

This section is informative

Introduction

This specification defines several interfaces and many events, however, this is not an exhaustive set of events for all purposes. To allow content authors and implementers to add desired functionality, this specification provides two mechanisms for extend this set of interfaces and events without creating conflicts: custom events and implementation-specific extensions.

Custom Events

A script author MAY wish to define an application in terms of functional components, with event types that are meaningful to the application architecture. The content author can use the CustomEvent interface to create their own events appropriate to the level of abstraction they are using.

A content author might have created an application which features a dynamically generated bar chart. This bar chart is meant to be updated every 5 minutes, or when a feed shows new information, or when the user refreshes it manually by clicking a button. There are several handlers that have to be called when the chart needs to be updated: the application has to fetch the most recent data, show an icon to the user that the event is being updated, and rebuild the chart. To manage this, the content author can choose to create a custom updateChart event, which is fired whenever one of the trigger conditions is met:


var chartData = ...;
var evt = document.createEvent("CustomEvent");
evt.initCustomEvent( "updateChart", true, false, { data: chartData });
document.documentElement.dispatchEvent(evt);

Implementation-Specific Extensions

While a new event is being designed and prototyped, or when an event is intended for implementation-specific functionality, it is desirable to distinguish it from standardized events. Implementors SHOULD prefix event types specific to their implementations with a short string to distinguish it from the same event in other implementations and from standardized events. This is similar to the vendor-specific keyword prefixes in CSS, though without the dashes ("-") used in CSS, since that can cause problems when used as an attribute name in Javascript.

A particular browser vendor, FooCorp, might wish to introduce a new event, jump. This vendor implements fooJump in their browser, using their vendor-specific prefix: 'foo'. Early adopters start experimenting with the event, using someElement.addEventListener("fooJump", doJump, false ), and provide feedback to FooCorp, who change the behavior of fooJump accordingly.

After some time, another vendor, BarOrg, decides they also want the functionality, but implement it slightly differently, so they use their own vendor-specific prefix, "bar" in their event type name: barJump. Content authors experimenting with this version of the jump event type register events with BarOrg's event type name. Content authors who wish to write code that accounts for both browsers can either register each event type separately with specific handlers, or use the same handler and switch on the name of the event type. Thus, early experiments in different codebases do not conflict, and the early adopter is able to write easily-maintained code for multiple implementations.

Eventually, as the feature matures, the behavior of both browsers stabilizes and might converge due to content author and user feedback or through formal standardization. As this stabilization occurs, and risk of conflicts decrease, content authors can remove the forked code, and use the jump event type name (even before it is formally standardized) using the same event handler and the more generic registration method someElement.addEventListener( "jump", doJump, false).

Known Implementation-Specific Prefixes

At the time of writing, the following event-type name prefixes are known to exist:

Prefix Web Engine (Organization)
moz, Moz Gecko (Mozilla)
ms, MS Trident (Microsoft)
o, O Presto (Opera Software)
webkit WebKit (Apple, Google, others)

Security Considerations

This appendix discusses security considerations for DOM Level 3 Events implementations. The discussion is limited to security issues that arise directly from implementation of the event model, APIs and events defined in this specification. Implementations typically support other features like scripting languages, other APIs and additional events not defined in this document. These features constitute an unknown factor and are out of scope of this document. Implementers SHOULD consult the specifications of such features for their respective security considerations.

Many of the event types defined in this specification are dispatched in response to user actions. This allows malicious event listeners to gain access to information users would typically consider confidential, e.g., typos they might have made when filling out a form, if they reconsider their answer to a multiple choice question shortly before submitting a form, their typing rate or primary input mechanism. In the worst case, malicious event listeners could capture all user interactions and submit them to a third party through means (not defined in DOM Level 3 Events) that are generally available in DOM implementations, such as the XMLHttpRequest interface.

In DOM implementations that support facilities to load external data, events like the error event can provide access to sensitive information about the environment of the computer system or network. An example would be a malicious HTML document that attempts to embed a resource on the local network or the localhost on different ports. An embedded DOM application could then listen for error and load events to determine which other computers in a network are accessible from the local system or which ports are open on the system to prepare further attacks.

An implementation of DOM Level 3 Events alone is generally insufficient to perform attacks of this kind and the security considerations of the facilities that possibly support such attacks apply. For conformance with this specification, DOM implementations MAY take reasonable steps to ensure that DOM applications do not get access to confidential or sensitive information. For example, they might choose not to dispatch load events to nodes that attempt to embed resources on the local network.

Changes

Changes between DOM Level 2 Events and DOM Level 3 Events

Numerous clarifications to the interfaces and event types have been made. The HTMLEvents module is no longer defined in this document. The focus and blur events have been added to the UIEvent module, and the dblclick event has been added to the MouseEvent module. This new specification provides a better separation between the DOM event flow, the event types, and the DOM interfaces.

Changes to DOM Level 2 event flow

This new specification introduced the following new concepts in the event flow:

Changes to DOM Level 2 event types

Many clarifications have been made on the event types. The conformance is now explicitly defined against the event types, and not only in terms of interfaces used by the event types.

"MutationEvents" have been deprecated. Support for namespaced events, present in early drafts of this specification, has also been removed.

For user agents which support the DOMNodeInserted and DOMNodeRemoved event types, this specification no longer requires that the event type be fired for Attr nodes.

The resize event type no longer bubbles, reflecting existing implementations.

Changes to DOM Level 2 Events interfaces

Interface Event
The Event interface has one new attribute, Event.defaultPrevented, and one new method, Event.stopImmediatePropagation().
Event.timeStamp is now a Number in the ECMAScript binding. A proposed correction to make the same change in [DOM3 Core] is forthcoming.
DOM Level 3 Events considers the Event.type attribute to be case-sensitive, while DOM Level 2 Events considers Event.type to be case-insensitive.
Interface EventTarget
The method EventTarget.dispatchEvent() was modified.
Interface MouseEvent
The MouseEvent interface has one new method MouseEvent.getModifierState().
Exception EventException
The exception EventException is removed in this specification. The prior DISPATCH_REQUEST_ERR code is re-mapped to a DOMException of type InvalidStateError.

New Interfaces

The interfaces CustomEvent, FocusEvent, KeyboardEvent, CompositionEvent, and WheelEvent were added to the Events module.

Changes between different drafts of DOM Level 3 Events

The DOM Level 3 Events document was originally developed between 2000 and 2003, and published as a W3C Note, pending further feedback and interest from implementers. In 2006, it was picked up for revision and progress on the Recommendation Track, and was then revised to reflect the current state of implementation and the needs of script authors.

Despite its status only as a W3C Note, rather than an official Recommendation, DOM 3 Events saw some implementation, and was also referenced by other specifications, so care is being taken to cause minimal disruption, while still adapting the specification to the current environment.

The current specification has been reordered significantly from the earlier W3C Note form, and also from the structure of DOM2 Events, in order to clarify the material. New diagrams have been put in place to represent hierarchies and events flows more clearly. Here are some of the more important changes between drafts:

Acknowledgements

Many people contributed to the DOM specifications (Level 1, 2 or 3), including participants of the DOM Working Group, the DOM Interest Group, the WebAPI Working Group, and the WebApps Working Group. We especially thank the following:

Andrew Watson (Object Management Group), Andy Heninger (IBM), Angel Diaz (IBM), Arnaud Le Hors (W3C and IBM), Ashok Malhotra (IBM and Microsoft), Ben Chang (Oracle), Bill Smith (Sun), Bill Shea (Merrill Lynch), Bob Sutor (IBM), Chris Lovett (Microsoft), Chris Wilson (Microsoft), David Brownell (Sun), David Ezell (Hewlett-Packard Company), David Singer (IBM), Dimitris Dimitriadis (Improve AB and invited expert), Don Park (invited), Elena Litani (IBM), Eric Vasilik (Microsoft), Gavin Nicol (INSO), Ian Jacobs (W3C), James Clark (invited), James Davidson (Sun), Jared Sorensen (Novell), Jeroen van Rotterdam (X-Hive Corporation), Joe Kesselman (IBM), Joe Lapp (webMethods), Joe Marini (Macromedia), Johnny Stenback (Netscape/AOL), Jon Ferraiolo (Adobe), Jonathan Marsh (Microsoft), Jonathan Robie (Texcel Research and Software AG), Kim Adamson-Sharpe (SoftQuad Software Inc.), Lauren Wood (SoftQuad Software Inc., former Chair), Laurence Cable (Sun), Mark Davis (IBM), Mark Scardina (Oracle), Martin Dürst (W3C), Mary Brady (NIST), Mick Goulish (Software AG), Mike Champion (Arbortext and Software AG), Miles Sabin (Cromwell Media), Patti Lutsky (Arbortext), Paul Grosso (Arbortext), Peter Sharpe (SoftQuad Software Inc.), Phil Karlton (Netscape), Philippe Le Hégaret (W3C, W3C Team Contact and former Chair), Ramesh Lekshmynarayanan (Merrill Lynch), Ray Whitmer (iMall, Excite@Home, and Netscape/AOL, Chair), Rezaur Rahman (Intel), Rich Rollman (Microsoft), Rick Gessner (Netscape), Rick Jelliffe (invited), Rob Relyea (Microsoft), Scott Isaacs (Microsoft), Sharon Adler (INSO), Steve Byrne (JavaSoft), Tim Bray (invited), Tim Yu (Oracle), Tom Pixley (Netscape/AOL), Vidur Apparao (Netscape), Vinod Anupam (Lucent), Anne van Kesteren (Opera Software), Arun Ranganathan (AOL), Björn Höhrmann, Charles McCathieNevile (Opera Software, Co-Chair), Christophe Jolif (ILOG), Dean Jackson (W3C, W3C Team Contact), Doug Schepers (Vectoreal), Gorm Haug Eriksen (Opera Software), Ian Davis (Talis Information Limited), Ian Hickson (Google), John Robinson (AOL), Jonas Sicking (Mozilla Foundation), Luca Mascaro (HTML Writers Guild), Maciej Stachowiak (Apple Computer), Marc Hadley (Sun Microsystems), Michael Shenfield (Research In Motion), Robin Berjon, (Expway, Co-Chair), Scott Hayman (Research In Motion), Stéphane Sire (IntuiLab), and T.V. Raman (Google).

Contributors: In the WebApps Working Group, the following people made substantial material contributions in the process of refining and revising this specification: Olli Pettay (Mozilla), Hallvord R. M. Steen (Opera), Travis Leithead (Microsoft), Hironori Bono (Google), Daniel Danilatos (Google), Glenn Adams (Samsung), Mark Vickers (Comcast), Bob Lund (Cable Laboratories), Cameron McCormack (Invited Expert / Mozilla), Masayuki Nakano (Mozilla), Takayoshi Kochi (Google) and Gary Kacmarcik (Google).

Glossary contributors: Arnaud Le Hors (W3C) and Robert S. Sutor (IBM Research).

Test suite contributors: Fred Drake, Mary Brady (NIST), Carmelo Montanez (NIST), Rick Rivello (NIST), Robert Clary (Netscape), Neil Delima (IBM), with a special mention to Curt Arnold.

Thanks to all those who have helped to improve this specification by sending suggestions and corrections (please, keep bugging us with your issues!), or writing informative books or Web sites: Brad Pettit, Dylan Schiemann, David Flanagan, Steven Pemberton, Curt Arnold, Al Gilman, Misha Wolf, Sigurd Lerstad, Michael B. Allen, Alexander J. Vincent, Martin Dürst, Ken Rehor, Garrett Smith, Sergey Ilinsky, Martijn Wargers, Sean Hogan, Magnus Kristiansen, Alex Russell, Jorge Chamorro, Peter-Paul Koch, William Edney, Erik Arvidsson, Cameron McCormack, Kazuyuki Ashimura, Øistein E. Andersen, James Su, Tony Chang, Ojan Vafai, Richard Ishida, Paul Irish, Mike Taylor, Oliver Hunt, Alexey Proskuryakov, Giuseppe Pascale, and Jan Goyvaerts (regular-expressions.info).

Production Systems

The current drafts of this specification are lovingly hand-crafted in HTML and SVG, using ReSpec and custom scripts to format the document according to W3C requirements.

Earlier versions of this specification were written in XML — the HTML, OMG IDL, Java and ECMAScript bindings were all produced automatically. Thanks to Joe English, author of cost, which was used as the basis for producing DOM Level 1. Thanks also to Gavin Nicol, who wrote the scripts which run on top of cost. Arnaud Le Hors and Philippe Le Hégaret maintained the scripts.

After DOM Level 1, Xerces was used as the basis DOM implementation and wish to thank the authors. Philippe Le Hégaret and Arnaud Le Hors wrote the Java programs which are the DOM application.

Thanks also to Jan Kärrman, author of html2ps, which was previously used to generate PostScript versions of the specification.

References

For the latest version of any W3C specification please consult the list of W3C Technical Reports available at http://www.w3.org/TR/.

Normative References

[BCP-47] Best Current Practice 47: Tags for Identifying Languages
A. Phillips, M. Davis, Editors,
September 2009.
The specification for describing the structure, content, construction, and semantics of language tags to indicate the human language used. Available at http://www.rfc-editor.org/rfc/bcp/bcp47.txt.
[CharMod]
Character Model for the World Wide Web 1.0: Fundamentals,
M. Dürst, F. Yergeau, R. Ishida, M. Wolf, T. Texin, Editors.
World Wide Web Consortium, 15 February 2005.
This version of the Character Model for the World Wide Web 1.0: Fundamentals specification is http://www.w3.org/TR/2005/REC-charmod-20050215/.
The latest version of Character Model for the World Wide Web 1.0: Fundamentals is available at http://www.w3.org/TR/charmod/.
[DOM3 Core]
Document Object Model Level 3 Core Specification,
A. Le Hors, et al., Editors.
World Wide Web Consortium, April 2004.
This version of the Document Object Model Level 3 Core Specification is http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/.
The latest version of DOM Level 3 Core is available at http://www.w3.org/TR/DOM-Level-3-Core/.
[DOM2 Events]
Document Object Model Level 2 Events Specification,
T. Pixley, Editor.
World Wide Web Consortium, November 2000.
This version of the Document Object Model Level 2 Events Specification is http://www.w3.org/TR/2000/REC-DOM-Level-2-Events-20001113.
The latest version of Document Object Model Level 2 Events is available at http://www.w3.org/TR/DOM-Level-2-Events/.
[ECMAScript]
ECMAScript Language Specification,
5.1 Edition.
European Computer Manufacturers Association, Standard ECMA-262, June 2011.
This version of the ECMAScript Language is available from http://ecma-international.org/ecma-262/5.1/.
[HTML5]
HTML 5,
I. Hickson, Editor.
World Wide Web Consortium, work in progress, 29 March 2012.
This edition of HTML 5 is http://www.w3.org/TR/2012/WD-html5-20120329/.
The latest edition of HTML 5 is available at http://www.w3.org/TR/html5/.
[Java]
The Java Language Specification,
J. Gosling, B. Joy, and G. Steele, Authors.
Addison-Wesley, September 1996.
Available at http://java.sun.com/docs/books/jls.
[RFC2119] Key words for use in RFCs to indicate Requirement Levels
S Bradner, 1997.
The specification for how to use English to specify normativity, as if it were a technical language. Available at http://www.ietf.org/rfc/rfc2119.txt.
[UAX #15]
Unicode Normalization Forms,
The Unicode Standard Annex #15. The Unicode Consortium, 2006.
The latest version of this annex is available at http://www.unicode.org/reports/tr15/.
[UIEvents]
UI Events,
G. Kacmarcik, T. Leithead, Editors.
World Wide Web Consortium, Editor's Draft, 5 May 2013.
[Unicode]
The Unicode Standard, Version 5.0,
ISBN 0-321-48091-0, as updated periodically by the publication of new versions.
See also Versions of the Unicode Standard, available at http://www.unicode.org/standard/versions/ for latest version and additional information on versions of the standard and of the Unicode Character Database.
[WEB IDL]
Web IDL,
C. McCormack. 19 April 2012.
This version of the Web IDL Candidate Recommendation is: http://www.w3.org/TR/2012/CR-WebIDL-20120419/.
The latest version of Web IDL is available at http://dev.w3.org/2006/webapi/WebIDL/.
[XML Namespaces 1.0]
Namespaces in XML 1.0,
T. Bray, D. Hollander, A. Layman, and R. Tobin, Editors.
World Wide Web Consortium, 16 August 2006.
This version of the Namespaces in XML 1.0 Specification is http://www.w3.org/TR/2006/REC-xml-names-20060816.
The latest version of Namespaces in XML 1.0 is available at http://www.w3.org/TR/xml-names/.

Informative References

[ARIA]
Accessible Rich Internet Applications (WAI-ARIA) Version 1.0,
J. Craig, M. Cooper, R. Schwerdtfeger, L. Seeman, L. Pappas, Editors.
World Wide Web Consortium, 18 January 2011.
This version of the WAI-ARIA Candidate Recommendation is http://www.w3.org/TR/2011/CR-wai-aria-20110118/.
The latest edition of WAI-ARIA is available at http://www.w3.org/TR/wai-aria/.
[XFORMS]
XForms 1.1,
J. Boyer, Editor.
World Wide Web Consortium, work in progress, 20 October 2009.
This edition of XForms 1.1 is http://www.w3.org/TR/2009/REC-xforms-20091020/.
The latest edition of XForms is available at http://www.w3.org/TR/xforms/.
[CSS2.1]
Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification,
B. Bos, T. Çelik, I. Hickson, H.W. Lie, Editors.
World Wide Web Consortium, 07 June 2011.
This version of the CSS 2.1 Recommendation is http://www.w3.org/TR/2011/REC-CSS2-20110607/.
The latest version of CSS 2.1 is available at http://www.w3.org/TR/CSS2/.
[DASE]
ATSC A/100-2, DTV Application Software Environment Level 1 (DASE-1) Part 2: Declarative Applications and Environment.
Advanced Television Systems Committee, 09 March 2003.
Available at http://www.atsc.org/cms/standards/a100/a_100_2.pdf.
[DOM3 Load and Save]
Document Object Model Level 3 Load and Save Specification,
J. Stenback, A. Heninger, Editors.
World Wide Web Consortium, April 2004.
This version of the DOM Level 3 Load and Save Specification is http://www.w3.org/TR/2004/REC-DOM-Level-3-LS-20040407/.
The latest version of DOM Level 3 Load and Save is available at http://www.w3.org/TR/DOM-Level-3-LS/.
[DOM2 Range]
Document Object Model (DOM) Level 2 Traversal and Range Specification,
J. Kesselman, J. Robie, M. Champion, P. Sharpe, V. Apparao, L. Wood, Editors.
World Wide Web Consortium, November 2000.
[DOM4]
DOM4,
A. van Kesteren, A. Gregor, Ms2ger, Editors.
World Wide Web Consortium, Working Draft, 5 April 2012.
[DWW95]
Developing International Software for Windows 95 and Windows NT: A Handbook for International Software Design,
N. Kano, Author.
Microsoft Press, 1995. ISBN 1-55615-840-8.
[HTML 4.01]
HTML 4.01 Specification,
D. Raggett, A. Le Hors, and I. Jacobs, Editors.
World Wide Web Consortium, December 1999.
This version of the HTML 4.01 Recommendation is http://www.w3.org/TR/1999/REC-html401-19991224.
The latest version of HTML 4 is available at http://www.w3.org/TR/html4/.
[HTML Editing]
HTML Editing APIs,
A. Gregor, Editor.
World Wide Web Consortium, work in progress, 12 March 2012.
[ISO9995-2/3]
ISO/IEC 9995, Information technology -- Keyboard layouts for text and office systems -- Part 2: Alphanumeric Section and Part 3: Complementary layouts of the alphanumeric zone of the alphanumeric section.
[ISO9995-8]
ISO/IEC 9995-8:2006, Information technology -- Keyboard layouts for text and office systems -- Part 8: Allocation of letters to the keys of a numeric keypad.
[KeyEvent for Java]
Java™ Platform, Standard Edition 6 API Specification, Class java.awt.events.KeyEvent.
Oracle.
Available at http://docs.oracle.com/javase/6/docs/api/java/awt/event/KeyEvent.html.
[Keys Enumeration for .Net]
.NET Framework 4.5 Class Library, Keys Enumeration.
Microsoft.
Available at http://msdn.microsoft.com/en-us/library/system.windows.forms.keys.aspx.
[KeyProps]
Legacy Keyboard Event Properties,
D. Schepers, Editor.
World Wide Web Consortium, work in progress, 04 August 2010.
This edition of Legacy Keyboard Event Properties is https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/Note-KeyProps.html.
The latest edition of Legacy Keyboard Event Properties is available at https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/Note-KeyProps.html.
[OCAP]
Open Cable Application Platform 1.1.3.
Cable Television Laboratories, Inc.,
03 June 2010.
Available at http://www.cablelabs.com/specifications/OC-SP-OCAP1.1.3-100603.pdf.
[PCRE]
Perl Compatible Regular Expressions library.
Available at http://www.pcre.org/.
[RFC20] ASCII format for Network Interchange
V. Cerf, 1969.
Available at http://tools.ietf.org/rfc/rfc20.txt
[US-ASCII] Coded Character Set - 7-Bit American Standard Code for Information Interchange
Standard ANSI X3.4-1986, ANSI, 1986.
[UAAG 2.0]
User Agent Accessibility Guidelines (UAAG) 2.0,
J. Allan, K. Ford, J. Richards, J. Spellman, Editors.
World Wide Web Consortium, work in progress, 8 March 2010.
This version of the UAAG 2.0 specfication is http://www.w3.org/WAI/UA/2010/ED-UAAG20-20100308/.
The latest version of UAAG 2.0 is available at http://www.w3.org/TR/UAAG20/.
[WEB4CE]
ANSI/CEA-2014-B, Web-based Protocol and Framework for Remote User Interface on UPnPTM Networks and the Internet (Web4CE).
Consumer Electronics Association, January 2011.
Available at http://www.ce.org/Standards/Standard-Listings/R7-Home-Network-Committee/CEA-2014-B-(ANSI%29.aspx.
[WIN1252]
Windows 1252 a Coded Character Set - 8-Bit.
Microsoft Corporation.
[XML 1.0]
Extensible Markup Language (XML) 1.0,
T. Bray, J. Paoli, C. M. Sperberg-McQueen, et. al, Editors.
World Wide Web Consortium, August 2006.
This version of the XML 1.0 Recommendation is http://www.w3.org/TR/2006/REC-xml-20060816/.
The latest version of XML 1.0 is available at http://www.w3.org/TR/xml/.