hidden attributeBecause this attribute is typically implemented using CSS, it's also possible to override it using CSS. For instance, a rule that applies 'display: block' to all elements will cancel the effects of the <{global/hidden}> attribute. Authors therefore have to take care when writing their style sheets to make sure that the attribute is still styled as expected.
for attributes of
<{label}> and <{output}> elements that are not
themselves <{global/hidden}> must similarly not refer to elements that are
<{global/hidden}>. In both cases, such references would cause user confusion.
Elements and scripts may, however, refer to elements that are <{global/hidden}> in other contexts.
form attribute.
hidden IDL attribute must reflect
the content attribute of the same name.
This section does not define or create any content attribute named "inert". This section merely defines an abstract concept of inertness.
A node (in particular elements and text nodes) can be marked as inert. When a node is inert, then the user agent must act as if the node was absent for the purposes of targeting user interaction events, may ignore the node for the purposes of text search user interfaces (commonly known as "find in page"), and may prevent the user from selecting text in that node. User agents should allow the user to override the restrictions on search and text selection, however.
For example, consider a page that consists of just a single inert
paragraph positioned in the middle of a <{body}>. If a user moves their pointing device
from the body over to the inert paragraph and clicks on the paragraph,
no mouseover event would be fired, and the mousemove and click events would
be fired on the <{body}> element rather than the paragraph.
When a node is inert, it generally cannot be focused. Inert nodes that are commands will also get disabled.
While a browsing context container is marked as inert, its nested browsing context's active document, and all nodes in that {{Document}}, must be marked as inert. An entireDocument can be marked as blocked by a modal dialog
subject. While a Document is so marked, every node that is in the Document, with the exception of the subject element and its
descendants, must be marked inert. (The elements excepted by this paragraph can
additionally be marked inert through other means; being part of a modal dialog does not
"protect" a node from being marked inert.)
Only one element at a time can mark a Document as being blocked by a modal
dialog. When a new <{dialog}> is made to block a {{Document}}, the previous element, if any, stops blocking the
{{Document}}.
The <{dialog}> element's showModal() method makes use of this mechanism.
click event, as described below.
The user agent should allow the user to manually trigger elements that have an activation
behavior, for instance using keyboard or voice input, or through mouse clicks. When the
user triggers an element with a defined activation behavior in a manner other than
clicking it, the default action of the interaction event must be to run synthetic click
activation steps on the element.
For accessibility, the keyboard's `Enter` and `Space` keys are often used to trigger an element's [=activation behavior=]. [[wai-aria-practices-1.1]]
Each element has a click in progress flag, initially set to false. When a user agent is to run synthetic click activation steps on an element, the user agent must run the following steps:click event at the element. If the
run synthetic click activation steps algorithm was invoked because the click() method was invoked, then the isTrusted attribute must be initialized to false.click event is not canceled, run post-click
activation steps on the element.
If the event is canceled, the user agent must run canceled activation
steps on the element instead.
click
event. When a user agent is to
run authentic click activation steps for a given event event, it must
follow these steps:
click event) at target.
If there is an element e and the click
event is not canceled, run post-click activation steps on element e.
If there is an element e and the event is canceled, run
canceled activation steps on element e.
The algorithms above don't run for arbitrary synthetic events dispatched by author script. The
click() method can be used to make the run synthetic click activation steps
algorithm happen programmatically.
Click-focusing behavior (e.g., the focusing of a text field when user clicks in one) typically happens before the click, when the mouse button is first depressed, and is therefore not discussed here.
Given an element target, the nearest activatable element is the element returned by the following algorithm:click event that was fired by the steps above
leading up to this point.
click()click() method must run the following steps:
1. If the element is a form control that is disabled, abort these steps.
2. Run synthetic click activation steps on the element.
If the widget with focus in this example was the text field in the dialog box, then key
input would be channeled from the graphical system to ① the Web browser, then to ②
the tab, then to ③ the dialog, and finally to ④ the text field.
Node object
that represents the position of the focusable area in the DOM. (When the focusable
area is itself a Node, it is its own DOM anchor.) The DOM anchor is
used in some APIs as a substitute for the focusable area when there is no other DOM object
to represent the focusable area.
The following table describes what objects can be focusable
areas. The cells in the left column describe objects that can be focusable areas; the cells in the right column describe the DOM
anchors for those elements. (The cells that span both columns are non-normative examples.)
| Focusable area | DOM anchor |
|---|---|
| Examples | |
| Elements that have their tabindex focus flag set, that are not actually disabled, that are not expressly inert, and that are either being rendered or being used as relevant canvas fallback content. | The element itself. |
|
<{iframe}>, | |
| The shapes of <{area}> elements in an image map associated with an <{img}> element that is being rendered and is not expressly inert. | The <{img}> element. |
|
In the following example, the <{area}> element creates two shapes, one on each
image. The DOM anchor of the first shape is the first <{img}> element, and the
DOM anchor of the second shape is the second <{img}> element.
...
| |
| The user-agent provided subwidgets of elements that are being rendered and are not actually disabled or expressly inert. | The element for which the focusable area is a subwidget. |
|
The controls in the user
interface that is exposed to the user for a <{video}> element, the up and down
buttons in a spin-control version of | |
| The scrollable regions of elements that are being rendered and are not expressly inert. | The element for which the box that the scrollable region scrolls was created. |
|
The CSS 'overflow' property's ''scroll'' value typically creates a scrollable region. | |
The viewport of a Document that is in a browsing context and is not
inert.
|
The Document for which the viewport was created.
|
|
The contents of an <{iframe}>. | |
| Any other element or part of an element, especially to aid with accessibility or to better match platform conventions. | The element. |
|
A user agent could make all list item bullets focusable, so that a user can more easily navigate lists. Similarly, a user agent could make all elements with <{global/title}> attributes focusable, so that their advisory information can be accessed. | |
A browsing context container (e.g., an <{iframe}>) is a focusable area, but key events routed to a browsing context container get immediately routed to the nested browsing context's active document. Similarly, in sequential focus navigation a browsing context container essentially acts merely as a placeholder for its nested browsing context's active document.
Each focusable area belongs to a control group. Each control group has an owner. Control group owners are control group owner objects. The following are control group owner objects:open
attribute specified and that are being rendered.Document
for which the viewport was created, an <{input}> control belongs to the control
group of its nearest ancestor <{dialog}> or {{Document}}, and an image
map's shapes belong to the nearest ancestor dialog or Document of the
<{img}> elements (not the <{area}> elements — this means one
<{area}> element might create multiple shapes in different control groups).
open
attribute specified and that is being rendered (i.e., that is a control group
owner object) and is not expressly inert
belongs to the dialog group whose manager is
the <{dialog}> element's nearest ancestor control group owner object.
A dialog is expressly inert if it is
inert but its nearest ancestor control group owner object is not.
If no <{dialog}> element has a particular control group owner object as
its nearest ancestor control group owner object, then that control group owner
object has no dialog group.
Each dialog group can have a dialog designated as the focused
dialog of the dialog group. Which dialog is so designated changes over time,
based on algorithms in this specification.
dialog returned by this algorithm:
Document of the top-level
browsing context.dialog object in a dialog group,
let current object be that dialog group's manager, and return to the step labeled loop.
Otherwise, if current object is a focusable area, let current
object be that focusable area's control group's owner, and return to the step labeled loop.
Otherwise, if current object is a Document in a nested browsing context, let current object be its browsing context container,
and return to the step labeled loop.
The chain starts with subject and (if subject is or can be the
currently focused area of a top-level browsing context) continues up the focus
hierarchy up to the Document of the top-level browsing context.
tabindex attributetabindex content attribute allows authors to
indicate that an element is supposed to be focusable,
whether it is supposed to be reachable using sequential focus navigation and, optionally,
to suggest where in the sequential focus navigation order the element appears.
Using a positive value for <{global/tabindex}> to specify the element's position in the sequential focus navigation order interacts with the order of all focusable elements. It is error-prone, and therefore not recommended. Authors should generally leave elements to appear in their default order.
Elements that do not receive focus by default can be made focusable using
tabindex="0". This value does not specify a particular position in the
sequential focus navigation order. Instead, the element's position in the navigation
order will be determined by the order in which the element appears in the document.
However, authors should only make elements focusable if they act as interactive controls or widgets.
In addition, authors should ensure that these focusable elements have an appropriate ARIA role
attribute.
For non-interactive elements that need to receive focus but that are not meant to be part of the sequential focus navigation order (for instance, the target of a skip link, or a container element that needs to be programmatically focused via JavaScript), authors should use a negative value of tabindex="-1".
controls attributeOne valid reason to ignore the requirement that sequential focus navigation not allow the author to lead to the element would be if the user's only mechanism for moving the focus is sequential focus navigation. For instance, a keyboard-only user would be unable to click on a text field with a negative <{global/tabindex}>, so that user's user agent would be well justified in allowing the user to tab to the control regardless.
In current user agent implementations, an element that is only focusable because of its <{global/tabindex}>
attribute will generally not fire a click event in response to a non-mouse activation
(e.g., hitting the "enter" key while the element is focused).
tabIndex IDL attribute must
reflect the value of the <{global/tabindex}> content
attribute. Its default value is 0 for elements that are focusable and are included in the
sequential focus navigation order, and -1 for all other elements.
Most current browsers instead give the {{HTMLElement/tabIndex}} IDL attribute a value of 0 for some list of elements that are by default a focusable area, and -1 for other elements, if there is no <{global/tabindex}> content attribute set. This behaviour is not well-defined and will hopefully be improved in the future.
open attribute specified and that is being
rendered (i.e., that is a control group owner object), nor a focusable
area, then run the first matching set of steps from the following list:
area
element belongs.
DocumentDocument's viewport.
A <{dialog}> element can be both a control group owner
object and a focusable area, if it has both an open attribute specified and a <{global/tabindex}> attribute specified and is being
rendered.
dialog in a dialog group, and
the dialog group manager has a non-empty control group, then let
new focus target be the designated focused area of that focus group.
Otherwise, if old focus target is a focusable area, then let new
focus target be the first focusable area of its control group
(if the control group owner is a {{Document}}, this will always be a
viewport).
Otherwise, let new focus target be null.
The unfocusing steps do not always result in the focus changing, even when applied to the currently focused area of a top-level browsing context. For example, if the currently focused area of a top-level browsing context is a viewport, then it will usually keep its focus regardless until another focusable area is explicitly focused with the focusing steps.
dialog in the dialog
group, if any, or else the first dialog in the dialog group regardless of
inertness, must be designated the focused dialog of the dialog
group.
Focus fixup rule one: When the designated focused area of a control group is removed from that control group in
some way (e.g., it stops being a focusable area, it is removed from the DOM, it
becomes expressly inert, etc), and the control
group is still not empty: designate the first non-inert focused area in that control group to be the new
focused area of the control group, if any; if they are all inert, then
designate the first focused area in that
control group to be the new focused area of the control group regardless
of inertness. If such a removal instead results in the control
group being empty, then there is simply no longer a focused area of the control
group.
For example, this might happen because an element is removed from its {{Document}}, or has a <{global/hidden}> attribute added. It might also happen to an <{input}> element when the element gets disabled.
Focus fixup rule two: When a dialog group has no designated focused dialog of the dialog group, and its dialog group manager's control group changes from being non-empty to being empty, the first non-inertdialog in the dialog group, if any, or else the first dialog in
the dialog group regardless of inertness, must be designated
the focused dialog of the dialog group.
Focus fixup rule three: When the designated focused dialog of a dialog group is removed from that dialog group in
some way (e.g., it stops being rendered, it loses its open attribute, it becomes expressly inert, etc), and there is still a dialog group (because the
dialog in question was not the last dialog in that dialog group):
if the dialog group's manager's control
group is non-empty, let there be no designated focused dialog of the dialog group
any more; otherwise (in the case that the control group is empty), designate the first
non-inert dialog in the dialog group to be the focused
dialog of the dialog group, or, if they are all inert, designate the first
dialog in the dialog group to be the focused dialog of the dialog
group regardless of inertness.
When the currently focused area of a top-level browsing context was a focusable
area but stops being a focusable area, or when it was a dialog in a
dialog group and stops being part of that dialog group, or when it
starts being inert, the user agent must run the following steps:
input
element, and the change event applies to the element, and the element does not have a
defined activation behavior, and the user has changed the element's value or its list of selected files while the control was focused
without committing that change, then fire a simple event that bubbles named change at the element.
Document object, let blur
event target be that Document object's Window object.
Otherwise, let blur event target be null.
blur at blur event target, with
related blur target as the related target.
In some cases, e.g., if entry is an area
element's shape, a scrollable region, or a viewport, no event is fired.
focusout at the blur event target.
It is possible for entry to be both a dialog
element and a focusable area, in which case it is its own control group
owner.
Document object, let focus
event target be that Document object's Window object.
Otherwise, let focus event target be null.
focus at focus event target, with
related focus target as the related target.
In some cases, e.g., if entry is an area
element's shape, a scrollable region, or a viewport, no event is fired.
focusin at the focus event target.
FocusEvent
object, initialize it to have the given name e, to not bubble, to not be
cancelable, and to have the relatedTarget
attribute initialized to r, the view attribute initialized to the Window object of the Document object of t, and the detail attribute initialized to 0, and must then dispatch the newly created FocusEvent object
at the specified target element t.
dialog; let target node be
target area.Document that has a <{body}> element, then let target node be the <{body}> element of that {{Document}}.
Otherwise, if target node is a {{Document}} object that has a non-null
document element, then let target node be that document element.
It is possible for the currently focused area of a top-level browsing
context to be inert, for example if a modal dialog is shown, and then that dialog
element is made inert. It is likely to be the result of a logic error in the
application, though.
Document object target, are
as follows:
Document of the top-level browsing
context.For example, the user agent could set it to the position of the user's click if the user clicks on the document contents.
When the user requests that focus move from the currently focused area of a top-level browsing context to the next or previous focusable area (e.g., as the default action of pressing the tab key), or when the user requests that focus sequentially move to a top-level browsing context in the first place (e.g., from the browser's location bar), the user agent must use the following algorithm:Typically, pressing tab requests the next control, and pressing shift+tab requests the previous control.
For example, if direction is backward, then the last focusable control before the browser's rendering area would be the control to focus.
If the user agent has no focusable controls — a kiosk-mode browser, for instance — then the user agent may instead restart these steps with the starting point being the top-level browsing context itself.| direction is forward | direction is backward | |
|---|---|---|
| starting point is a browsing context | Let candidate be the first suitable sequentially focusable area in starting point's active document's primary control group, if any; or else null | Let candidate be the last suitable sequentially focusable area in starting point's active document's primary control group, if any; or else null |
| selection mechanism is DOM | Let candidate be the first suitable sequentially focusable area in the home control group following starting point, if any; or else null | Let candidate be the last suitable sequentially focusable area in the home control group preceding starting point, if any; or else null |
| selection mechanism is sequential | Let candidate be the first suitable sequentially focusable area in the home sequential focus navigation order following starting point, if any; or else null | Let candidate be the last suitable sequentially focusable area in the home sequential focus navigation order preceding starting point, if any; or else null |
The home sequential focus navigation order is the home control group's sequential focus navigation order, but is only used when the starting point is in that sequential focus navigation order (when it's not, selection mechanism will be DOM).
activeElementiframe is the element returned by the activeElement API in the iframe's
node document.
hasFocus()focus()focus()blur()focus() method on the Document's document element.
Do not use this method to hide the focus ring if you find the focus ring unsightly. Instead,
use a CSS rule to override the 'outline' property, and provide a different way to show what
element is focused. Be aware that if an alternative focusing style isn't made available, the
page will be significantly less usable for people who primarily navigate pages using a keyboard,
or those with reduced vision who use focus outlines to help them navigate the page.
:link:focus, :visited:focus { outline: none; background: yellow; color: black; }
activeElement attribute on
Document objects must return the value returned by the following steps:
Document on which the method was
invoked.Document that has a <{body}> element, then let
candidate be the <{body}> element of that
{{Document}}.
Otherwise, if candidate is a {{Document}} with a non-null document element, then
let candidate be that document element.
Otherwise, if candidate is a {{Document}}, then let candidate be null.
hasFocus() method on the
Document object, when invoked, must return the result of running the has focus
steps with the Document object as the argument.
The focus() method on the Window
object, when invoked, must run the focusing steps with the Window
object's browsing context. Additionally, if this browsing context is a
top-level browsing context, user agents are encouraged to trigger some sort of
notification to indicate to the user that the page is attempting to gain focus.
The blur() method on the Window
object, when invoked, provides a hint to the user agent that the script believes the user probably
is not currently interested in the contents of the browsing context of the
Window object on which the method was invoked, but that the contents might become
interesting again in the future.
User agents are encouraged to ignore calls to this blur()
method entirely.
Historically, the focus() and blur() methods actually affected the system-level focus of the
system widget (e.g., tab or window) that contained the browsing context, but hostile
sites widely abuse this behavior to the user's detriment.
focus() method on elements, when invoked, must
run the following algorithm:
blur() method, when invoked, should run the
unfocusing steps for the element on which the method was called. User agents may
selectively or uniformly ignore calls to this method for usability reasons.
For example, if the blur() method is unwisely
being used to remove the focus ring for aesthetics reasons, the page would become unusable by
keyboard users. Ignoring calls to this method would thus allow keyboard users to interact with the
page.
There are three clipboard actions that affect selection: cut, copy, and paste. Focus may follow selection, and user-agents handle this by default, but when custom clipboard actions are implemented the author needs to provide the following behaviors:
User agents may not assign any shortcut, or assigned shortcuts may be overridden by other browser- or system-level shortcuts.
A valid value for the <{global/accesskey}> attribute consists of a single printable character, such as a letter or digit. User agents should provide users with a list of the shortcuts available, but authors are encouraged to do so also.accesskey attributeaccesskey
content attribute set. The <{global/accesskey}> attribute's value is used
by the user agent as a guide for creating a keyboard shortcut that activates or focuses the
element.
If specified, the value must be a single printable character:
this typically (but not always) means a string one Unicode code point in length.
accesskey="ñ"
to assign ñ, because in many browsers no shortcut will be assigned.
Characters in
Normalization Form C
such as accesskey="ñ" are valid values and generally recognised, but whether users can generate the shortcut
generally depends on their local keyboard settings among other factors.
Printable characters that may represent more than one Unicode code point, such as
accesskey="श्र", are valid values.
Authors should not use space characters such as " ".
Authors should not use an <{global/accesskey}> attribute with the same value, nor with a value
that differs only by case or the use of a modifier key, for more than one element in the same document,
because in some browsers doing so causes the attribute to be ignored.
Document that has an associated
browsing context, and neither the element nor any of its ancestors has a
<{global/hidden}> attribute specified, then the user agent must either focus the element,
or trigger the Action of the command.
User agents might expose elements that have an <{global/accesskey}> attribute in other ways as well, e.g., in a menu displayed in response to a specific key combination, or with a user gesture.
accessKey IDL attribute must
reflect the <{global/accesskey}> content attribute.
contenteditable content attribute
[NoInterfaceObject]
interface ElementContentEditable {
attribute DOMString contentEditable;
readonly attribute boolean isContentEditable;
};
The contenteditable content attribute is an
enumerated attribute whose keywords are the empty string, true,
and false. The empty string and the true keyword map
to the true state. The false keyword maps to the false state.
In addition, there is a third state, the inherit state, which is the missing value default (and the invalid value default).
The true state indicates that the element is editable. The inherit state
indicates that the element is editable if its parent is. The false state indicates that the
element is not editable.
true", "false", or "inherit", based on the state of the <{global/contenteditable}> attribute.
Can be set, to change that state.
Throws a "{{SyntaxError}}" {{DOMException}} if the new value isn't one of those strings.
isContentEditablecontentEditable IDL attribute,
on getting, must return the string "true" if the content attribute is set to
the true state, "false" if the content attribute is set to the false state,
and "inherit" otherwise. On setting, if the new value is an
ASCII case-insensitive match for the string "inherit" then the content
attribute must be removed, if the new value is an ASCII case-insensitive match for
the string "true" then the content attribute must be set to the string
"true", if the new value is an ASCII case-insensitive match for
the string "false" then the content attribute must be set to the string
"false", and otherwise the attribute setter must throw a
"{{SyntaxError}}" {{DOMException}}.
The isContentEditable IDL attribute, on
getting, must return true if the element is either an editing host or
editable, and false otherwise.
designMode IDL attributedesignMode, which can be either enabled or
disabled.
on" if the document is editable, and "off" if it isn't.
Can be set, to change the document's current state. This focuses the document and resets the
selection in that document.
designMode IDL attribute on the
Document object takes two values, "on" and "off". On
setting, the new value must be compared in an ASCII case-insensitive manner to these two
values; if it matches the "on" value, then designMode must be enabled,
and if it matches the "off" value, then designMode must be disabled.
Other values must be ignored.
On getting, if designMode is enabled, the IDL
attribute must return the value "on"; otherwise it is disabled, and the
attribute must return the value "off".
The last state set must persist until the document is destroyed or the state is changed.
Initially, documents must have their designMode
disabled.
When the designMode changes from being disabled to
being enabled, the user agent must immediately reset the document's active range's
start and end boundary points to be at the start of the Document and then run the
focusing steps for the document element of the {{Document}}, if non-null.
execCommand(),
queryCommandEnabled(),
queryCommandIndeterm(),
queryCommandState(),
queryCommandSupported(), and
queryCommandValue()
methods, text selections, and the delete the selection algorithm are defined in the
HTML Editing APIs specification. The interaction of editing and the undo/redo features in user
agents is defined by the UndoManager and DOM Transaction specification. [[EDITING]] [[UNDO]]
spellcheck attribute is an enumerated
attribute whose keywords are the empty string, true and false. The empty string and the true keyword map to the
true state. The false keyword maps to the false state. In
addition, there is a third state, the default state, which is the missing value default (and the invalid value default).
The true state indicates that the element is to have its spelling and grammar checked. The default state indicates that the element is to act according to a default behavior, possibly based on the parent element's own <{global/spellcheck}> state, as defined below. The false state indicates that the element is not to be checked.
forceSpellCheck()spellcheck IDL attribute, on getting, must
return true if the element's <{global/spellcheck}> content attribute is
in the true state, or if the element's <{global/spellcheck}>
content attribute is in the default state and the element's default behavior is true-by-default, or if the element's <{global/spellcheck}> content attribute is in the default state and the
element's default behavior is inherit-by-default and the element's parent
element's {{HTMLElement/spellcheck}} IDL attribute would return true;
otherwise, if none of those conditions applies, then the attribute must instead return false.
The {{HTMLElement/spellcheck}} IDL attribute is not affected by user preferences that override the <{global/spellcheck}> content attribute, and therefore might not reflect the actual spellchecking state.
On setting, if the new value is true, then the element's <{global/spellcheck}> content attribute must be set to the literal string "true", otherwise it must be set to the literal string "false".
readonly attribute specified and that are not disabled).readonly attribute and that are not disabled.input and <{textarea}> elements, it is the element itself.
To determine if a word, sentence, or other piece of text in an applicable element (as defined
above) is to have spelling- and grammar-checking enabled, the user agent must use the following
algorithm:
pattern to ensure that the resulting value is valid, where
possible.
If checking is disabled, the user agent should not indicate spelling or grammar errors for that
text.
Even when checking is enabled, user agents may opt to not report spelling or grammar errors in
text that the user agent deems the user has no interest in having checked (e.g., text that was
already present when the page was loaded, or that the user did not type, or text in controls that
the user has not focused, or in parts of e-mail addresses that the user agent is not confident
were misspelt). The forceSpellCheck() method,
when invoked on an element, must override this behavior, forcing the user agent to consider all
spelling and grammar errors in text in that element for which checking is enabled to be of
interest to the user.
This specification does not define the user interface for spelling and grammar checkers. A user agent could offer on-demand checking, could perform continuous checking while the checking is enabled, or could use other interfaces.
mousedown event that is followed by a series of mousemove events, and
the drop could be triggered by the mouse being released.
When using an input modality other than a pointing device, users would probably have to
explicitly indicate their intention to perform a drag-and-drop operation, stating what they wish
to drag and where they wish to drop it, respectively.
However it is implemented, drag-and-drop operations must have a starting point (e.g., where the
mouse was clicked, or the start of the selection or element that was selected for the drag), may
have any number of intermediate steps (elements that the mouse moves over during a drag, or
elements that the user picks as possible drop points as he cycles through possibilities), and
must either have an end point (the element above which the mouse button was released, or the
element that was finally selected), or be canceled. The end point must be the last element
selected as a possible drop point before the drop occurs (so if the operation is not canceled,
there must be at least one element in the middle step).
dragstart that stores the data being dragged.
The event handler typically needs to check that it's not a text selection that is being dragged,
and then needs to store data into the {{DataTransfer}} object and set the allowed effects
(copy, move, link, or some combination).
For example:
What fruits do you like?
drop event.
A drop target can handle the dragenter event (to report whether or not the drop
target is to accept the drop) and the dragover event (to specify what feedback
is to be shown to the user).
drop event allows the actual drop to be performed. This event needs to be
canceled, so that the {{DataTransfer/dropEffect}} attribute's value can be used by the source
(otherwise it's reset).
For example:
Drop your favorite fruits below:
dragend event can be used.
For our example here, that means updating the original markup to handle that event:
What fruits do you like?
dragstart event. New data can be added to the
drag data store.
drop event. The list of items representing dragged data can be
read, including the data. No new data can be added.
uninitialized".
DataTransfer interface
interface DataTransfer {
attribute DOMString dropEffect;
attribute DOMString effectAllowed;
[SameObject] readonly attribute DataTransferItemList items;
void setDragImage(Element image, long x, long y);
/* old interface */
[SameObject] readonly attribute DOMString[] types;
DOMString getData(DOMString format);
void setData(DOMString format, DOMString data);
void clearData(optional DOMString format);
[SameObject] readonly attribute FileList files;
};
none", "copy", "link", and "move".
dragstart event), to change
the allowed operations.
The possible values are "none",
"copy", "copyLink", "copyMove", "link", "linkMove", "move", "all", and "uninitialized",
dragstart event. In addition, if any files are being dragged,
then one of the types will be the string "Files".
FileList of the files being dragged, if any.
dropEffect attribute controls
the drag-and-drop feedback that the user is given during a drag-and-drop operation. When the
{{DataTransfer}} object is created, the {{DataTransfer/dropEffect}} attribute is set to a string value. On
getting, it must return its current value. On setting, if the new value is one of "none", "copy", "link", or "move", then the attribute's current value must be
set to the new value. Other values must be ignored.
The effectAllowed attribute is
used in the drag-and-drop processing model to initialize the {{DataTransfer/dropEffect}} attribute during the dragenter and dragover events. When the {{DataTransfer}} object is
created, the {{DataTransfer/effectAllowed}} attribute is set
to a string value. On getting, it must return its current value. On setting, if drag data
store's mode is the read/write mode and the new value is one of "none", "copy", "copyLink", "copyMove", "link", "linkMove", "move", "all", or "uninitialized", then the attribute's
current value must be set to the new value. Otherwise it must be left unchanged.
The items attribute must return a
{{DataTransferItemList}} object associated with the {{DataTransfer}} object.
The setDragImage(element, x, y) method must run the following steps:
types attribute must return a
live read only array giving the strings
that the following steps would produce.
Files". (This value can be
distinguished from the other values because it is not lowercase.)getData(format) method
must run the following steps:
text", change it to "text/plain".url", change it to "text/uri-list" and set convert-to-URL to true.text/uri-list data, and then set result to the first URL from
the list, if any, or the empty string otherwise. [[!RFC2483]]setData(format, data) method must run the following steps:
text", change it to "text/plain".
If format equals "url", change it to "text/uri-list".
clearData() method must run the
following steps:
text", change it to "text/plain".
If format equals "url", change it to "text/uri-list".
The {{DataTransfer/clearData()}} method does not
affect whether any files were included in the drag, so the {{DataTransfer/types}} attribute's list might still not be empty after
calling {{DataTransfer/clearData()}} (it would still contain the
"Files" string if any files were included in the drag).
files attribute must return a
live FileList sequence consisting of File objects
representing the files found by the following steps.
Furthermore, for a given FileList object and a given underlying file, the same
File object must be used each time.
FileList is empty. Abort these steps; return the empty list L.This version of the API does not expose the types of the files during the drag.
DataTransferItemList interface
interface DataTransferItemList {
readonly attribute unsigned long length;
getter DataTransferItem (unsigned long index);
DataTransferItem? add(DOMString data, DOMString type);
DataTransferItem? add(File data);
void remove(unsigned long index);
void clear();
};
length attribute must
return zero if the object is in the disabled mode; otherwise it must return the number of
items in the drag data store item list.
When a {{DataTransferItemList}} object is not in the disabled mode, its
supported property indices are the numbers in the range 0 .. n-1, where
n is the number of items in the drag data store item list.
To determine the value of an indexed property
i of a {{DataTransferItemList}} object, the user agent must return a
{{DataTransferItem}} object representing the ith item in the
drag data store. The same object must be returned each time a particular item is
obtained from this {{DataTransferItemList}} object. The {{DataTransferItem}}
object must be associated with the same {{DataTransfer}} object as the
{{DataTransferItemList}} object when it is first created.
The add() method must run the
following steps:
FileFile,
in ASCII lowercase, and whose data is the same as the
File's data.
clear() method, if the
{{DataTransferItemList}} object is in the read/write mode,
must remove all the items from the drag data store. Otherwise, it must do
nothing.
DataTransferItem interface
interface DataTransferItem {
readonly attribute DOMString kind;
readonly attribute DOMString type;
void getAsString(FunctionStringCallback? _callback);
File? getAsFile();
};
callback FunctionStringCallback = void (DOMString data);
File object, if the drag data item kind is File.
kind attribute must return the
empty string if the {{DataTransferItem}} object is in the disabled mode; otherwise
it must return the string given in the cell from the second column of the following table from the
row whose cell in the first column contains the drag data item kind of the item
represented by the {{DataTransferItem}} object:
| Kind | String |
|---|---|
| Plain Unicode string | "string"
|
| File | "file"
|
type attribute must return the
empty string if the {{DataTransferItem}} object is in the disabled mode; otherwise
it must return the drag data item type string of the item represented by the
{{DataTransferItem}} object.
The getAsString(callback) method must run the following steps:
getAsFile()
method must run the following steps:
File object representing the actual data of the item represented
by the {{DataTransferItem}} object.
DragEvent interface
[Constructor(DOMString type, optional DragEventInit eventInitDict)]
interface DragEvent : MouseEvent {
readonly attribute DataTransfer? dataTransfer;
};
dictionary DragEventInit : MouseEventInit {
DataTransfer? dataTransfer = null;
};
Although, for consistency with other event interfaces, the {{DragEvent}} interface has a constructor, it is not particularly useful. In particular, there's no way to create a useful {{DataTransfer}} object from script, as {{DataTransfer}} objects have a processing and security model that is coordinated by the browser during drag-and-drops.
ThedataTransfer attribute of the
{{DragEvent}} interface must return the value it was initialized to. It represents the
context information for the event.
When a user agent is required to fire a DND event named e at an element,
using a particular drag data store, and optionally with a specific related
target, the user agent must run the following steps:
Window object of the Document
object of the specified target element.dragstart, then set the drag data store mode to the
read/write mode and set dataDragStoreWasChanged to true.
If e is drop, set the drag data store mode to the read-only mode.
none" if e is dragstart, drag, dragexit, or dragleave; to the value corresponding to the current
drag operation if e is drop or
dragend; and to a value based on the {{DataTransfer/effectAllowed}} attribute's value and the
drag-and-drop source, as given by the following table, otherwise (i.e., if e
is dragenter or dragover):
| {{DataTransfer/effectAllowed}} | {{DataTransfer/dropEffect}} |
|---|---|
"none" |
"none" |
"copy" |
"copy" |
"copyLink" |
"copy", or, if appropriate, "link" |
"copyMove" |
"copy", or, if appropriate, "move" |
"all" |
"copy", or, if appropriate, either "link" or "move" |
"link" |
"link" |
"linkMove" |
"link", or, if appropriate, "move" |
"move" |
"move" |
"uninitialized" when what is being dragged is a selection from a text field |
"move", or, if appropriate, either "copy" or "link" |
"uninitialized" when what is being dragged is a selection |
"copy", or, if appropriate, either "link" or "move" |
"uninitialized" when what is being dragged is an <{a}> element with an <{links/href}> attribute |
"link", or, if appropriate, either "copy" or "move" |
| Any other case | "copy", or, if appropriate, either "link" or "move" |
For example, Windows platform conventions are such that dragging while
holding the "alt" key indicates a preference for linking the data, rather than moving or copying
it. Therefore, on a Windows system, if "link" is an option according to
the table above while the "alt" key is depressed, the user agent could select that instead of
"copy" or "move".
dragexit, dragleave, or dragend, and to have the view attribute initialized to window, the detail attribute initialized to zero, the mouse and key
attributes initialized according to the state of the input devices as they would be for user
interaction events, the relatedTarget
attribute initialized to related target, and the {{DragEvent/dataTransfer}} attribute initialized to
dataTransfer, the {{DataTransfer}} object created above.
If there is no relevant pointing device, the object must have its screenX, screenY, clientX, clientY, and button attributes set to 0.
dragstart.)<{img}> elements and <{a}> elements with an <{links/href}> attribute have their <{global/draggable}> attribute set to true by default.
Multiple events are fired on the source node during the course of the drag-and-drop operation.
text/plain"application/octet-stream" otherwise.Dragging files can currently only happen from outside a browsing context, for example from a file system manager application.
If the drag initiated outside of the application, the user agent must add items to the drag data store item list as appropriate for the data being dragged, honoring platform conventions where appropriate; however, if the platform conventions do not use MIME types to label dragged data, the user agent must make a best-effort attempt to map the types to MIME types, and, in any case, all the drag data item type strings must be in ASCII lowercase. User agents may also add one or more items representing the selection or dragged element(s) in other forms, e.g., as HTML.application/microdata+jsonsrc content attribute
relative to the element's node documenttext/uri-listdragstart at the
source node.
If the event is canceled, then the drag-and-drop operation should not occur; abort these
steps.
Since events with no event listeners registered are, almost by definition, never canceled, drag-and-drop is always available to the user if the author does not specifically prevent it.
none", "copy", "link", and "move". Initially, it has the value
"none". It is updated by the user agent
as described in the steps below.
User agents must, as soon as the drag operation is initiated and every 350ms (±200ms) thereafter for as long as the drag
operation is ongoing, queue a task to perform the following steps in sequence:
drag at the
source node. If this event is canceled, the user agent must set the current
drag operation to "none" (no
drag operation).
drag event was not canceled and the user has not
ended the drag-and-drop operation, check the state of the drag-and-drop operation, as
follows:
dragexit at the current
target element, and then update the current target element as follows:
dragenter
at the immediate user selection.
If the event is canceled, then set the current target element to the
immediate user selection.
Otherwise, run the appropriate step from the following list:
text/plain" and the
drag data item kind Plain Unicode stringbody elementdragenter
at the body element, if there is one, or at the Document object,
if not. Then, set the current target element to the body element, regardless of whether that event was canceled or not.
dragleave at the previous target
element, with the new current target element as the specific related
target.
dragover at this current
target element.
If the dragover event is not canceled, run the
appropriate step from the following list:
text/plain" and
the drag data item kind Plain Unicode stringcopy" or "move", as appropriate given the platform
conventions.none".dragover event is
canceled), set the current drag operation based on the values of the {{DataTransfer/effectAllowed}} and {{DataTransfer/dropEffect}} attributes of the
{{DragEvent}} object's {{DragEvent/dataTransfer}}
object as they stood after the event dispatch
finished, as per the following table:
| {{DataTransfer/effectAllowed}} | {{DataTransfer/dropEffect}} | Drag operation |
|---|---|---|
"uninitialized", "copy", "copyLink", "copyMove", or "all" |
"copy" |
"copy" |
"uninitialized", "link", "copyLink", "linkMove", or "all" |
"link" |
"link" |
"uninitialized", "move", "copyMove", "linkMove", or "all" |
"move" |
"move" |
| Any other case | "none" |
|
| Drag operation | Feedback |
|---|---|
"copy" |
Data will be copied if dropped here. |
"link" |
Data will be linked if dropped here. |
"move" |
Data will be moved if dropped here. |
"none" |
No operation allowed, dropping here will cancel the drag-and-drop operation. |
drag
event was canceled, then this will be the last iteration. Run the following steps, then stop the
drag-and-drop operation:
none" (no drag operation), or, if the user
ended the drag-and-drop operation by canceling it (e.g., by hitting the Escape key),
or if the current target element is null, then the drag operation failed. Run
these substeps:
dragleave at it; otherwise, if
it is not null, use platform-specific conventions for drag cancelation.none".drop at it; otherwise, use
platform-specific conventions for indicating a drop.text/plain" and the drag data item kind Plain Unicode
stringtext/plain" and a drag
data item kind that is Plain Unicode string into the text field or
editing host or editable element in a manner consistent with
platform-specific conventions (e.g., inserting it at the current mouse cursor position, or
inserting it at the end of the field).none".dragend at the
source node.
dragend event:
move", and the source of the
drag-and-drop operation is a selection in the DOM that is entirely contained within an
editing hostmove", and the source of the
drag-and-drop operation is a selection in a text fieldnone"User agents are encouraged to consider how to react to drags near the edge of scrollable regions. For example, if a user drags a link to the bottom of the viewport on a long page, it might make sense to scroll the page so that the user can drop the link lower on the page.
This model is independent of which Document object the nodes involved are from;
the events are fired as described above and the rest of the processing model runs as described
above, irrespective of how many documents are involved in the operation.
| Event Name | Target | Cancelable? | Drag data store mode | {{DataTransfer/dropEffect}} | Default Action |
|---|---|---|---|---|---|
dragstart |
Source node | ✓ Cancelable | Read/write mode | "none" |
Initiate the drag-and-drop operation |
drag |
Source node | ✓ Cancelable | Protected mode | "none" |
Continue the drag-and-drop operation |
dragenter |
Immediate user selection or the body element |
✓ Cancelable | Protected mode | Based on {{DataTransfer/effectAllowed}} value | Reject immediate user selection as potential target element |
dragexit |
Previous target element | — | Protected mode | "none" |
None |
dragleave |
Previous target element | — | Protected mode | "none" |
None |
dragover |
Current target element | ✓ Cancelable | Protected mode | Based on {{DataTransfer/effectAllowed}} value | Reset the current drag operation to "none" |
drop |
Current target element | ✓ Cancelable | Read-only mode | Current drag operation | Varies |
dragend |
Source node | — | Protected mode | Current drag operation | Varies |
dragstart event, defaulting to
"uninitialized" in the dragstart event.
draggable attributedraggable content attribute set. The
<{global/draggable}> attribute is an enumerated attribute. It has three states. The first
state is true and it has the keyword true. The second state is false
and it has the keyword false. The third state is auto; it has no keywords but
it is the missing value default.
The true state means the element is draggable; the false state means that it is not.
The auto state uses the default behavior of the user agent.
An element with a <{global/draggable}> attribute should also have a <{global/title}> attribute
that names the element for the purpose of non-visual interactions.
draggable IDL attribute, whose value depends on the content
attribute's in the way described below, controls whether or not the element is draggable.
Generally, only text selections are draggable, but elements whose {{HTMLElement/draggable}} IDL
attribute is true become draggable as well.
If an element's <{global/draggable}> content attribute has the state true, the
{{HTMLElement/draggable}} IDL attribute must return true.
Otherwise, if the element's <{global/draggable}> content attribute has the state false,
the {{HTMLElement/draggable}} IDL attribute must return false.
Otherwise, the element's <{global/draggable}> content attribute has the state auto. If
the element is an <{img}> element, an <{object}> element that
represents an image, or an <{a}> element with an <{links/href}> content
attribute, the {{HTMLElement/draggable}} IDL attribute must return true; otherwise, the
{{HTMLElement/draggable}} IDL attribute must return false.
If the {{HTMLElement/draggable}} IDL attribute is set to the value false, the
<{global/draggable}> content attribute must be set to the literal value "false".
If the {{HTMLElement/draggable}} IDL attribute is set to the value true, the <{global/draggable}>
content attribute must be set to the literal value "true".
dragstart event available to scripts until the drop event, because
otherwise, if a user were to drag sensitive information from one document to a second document,
crossing a hostile third document in the process, the hostile document could intercept the data.
For the same reason, user agents must consider a drop to be successful only if the user
specifically ended the drag operation — if any scripts end the drag operation, it must be
considered unsuccessful (canceled) and the drop event must not be fired.
User agents should take care to not start drag-and-drop operations in response to script
actions. For example, in a mouse-and-window environment, if a script moves a window while the
user has his mouse button depressed, the user agent would not consider that to start a drag. This is
important because otherwise user agents could cause data to be dragged from sensitive sources and
dropped into hostile documents without the user's consent.
User agents should filter potentially active (scripted) content (e.g., HTML) when it is dragged
and when it is dropped, using a safelist of known-safe features. Similarly, relative URLs
should be turned into absolute URLs to avoid references changing in unexpected ways. This
specification does not specify how this is performed.