HTMLElement
The HTMLElement interface represents any HTML element. Some elements directly implement this interface, while others implement it via an interface that inherits it.
Properties
Inherits properties from its parent, Element, and implements those from DocumentAndElementEventHandlers, GlobalEventHandlers, and TouchEventHandlers.
HTMLElement.accessKey-
Is a
DOMStringrepresenting the access key assigned to the element. -
HTMLElement.accessKeyLabelRead only -
Returns a
DOMStringcontaining the element's assigned access key. -
HTMLElement.attributeStyleMapRead only -
Is a
StylePropertyMaprepresenting the declarations of the element'sstyleattribute. HTMLElement.contentEditable-
Is a
DOMString, where a value oftruemeans the element is editable and a value offalsemeans it isn't. -
HTMLElement.isContentEditableRead only -
Returns a boolean value indicating whether or not the content of the element can be edited.
-
HTMLElement.contextMenu -
Is a
HTMLMenuElementrepresenting the contextual menu associated with the element. It may benull. -
HTMLElement.datasetRead only -
Returns a
DOMStringMapwith which script can read and write the element's custom data attributes (data-*) . HTMLElement.dir-
Is a
DOMString, reflecting thedirglobal attribute, representing the directionality of the element. Possible values are"ltr","rtl", and"auto". HTMLElement.draggable-
Is a
Booleanindicating if the element can be dragged. HTMLElement.enterkeyhint-
Is a
DOMStringdefining what action label (or icon) to present for the enter key on virtual keyboards. HTMLElement.hidden-
Is a
Booleanindicating if the element is hidden or not. HTMLElement.inert-
Is a
Booleanindicating whether the user agent must act as though the given node is absent for the purposes of user interaction events, in-page text searches ("find in page"), and text selection. HTMLElement.innerText-
Represents the "rendered" text content of a node and its descendants. As a getter, it approximates the text the user would get if they highlighted the contents of the element with the cursor and then copied it to the clipboard.
-
HTMLElement.itemScope -
Is a
Booleanrepresenting the item scope. -
HTMLElement.itemTypeRead only -
Returns a
DOMSettableTokenList… -
HTMLElement.itemId -
Is a
DOMStringrepresenting the item ID. -
HTMLElement.itemRefRead only -
Returns a
DOMSettableTokenList… -
HTMLElement.itemPropRead only -
Returns a
DOMSettableTokenList… -
HTMLElement.itemValue -
Returns a
Objectrepresenting the item value. HTMLElement.lang-
Is a
DOMStringrepresenting the language of an element's attributes, text, and element contents. HTMLElement.noModule-
Is a
Booleanindicating whether an import script can be executed in user agents that support module scripts. HTMLElement.nonce-
Returns the cryptographic number used once that is used by Content Security Policy to determine whether a given fetch will be allowed to proceed.
-
HTMLElement.offsetHeightRead only -
Returns a
doublecontaining the height of an element, relative to the layout. -
HTMLElement.offsetLeftRead only -
Returns a
double, the distance from this element's left border to itsoffsetParent's left border. -
HTMLElement.offsetParentRead only -
Returns a
Elementthat is the element from which all offset calculations are currently computed. -
HTMLElement.offsetTopRead only -
Returns a
double, the distance from this element's top border to itsoffsetParent's top border. -
HTMLElement.offsetWidthRead only -
Returns a
doublecontaining the width of an element, relative to the layout. -
HTMLElement.propertiesRead only -
Returns a
HTMLPropertiesCollection… HTMLElement.spellcheck-
Is a
Booleanthat controls spell-checking. It is present on all HTML elements, though it doesn't have an effect on all of them. HTMLElement.style-
Is a
CSSStyleDeclarationrepresenting the declarations of the element'sstyleattribute. HTMLElement.tabIndex-
Is a
longrepresenting the position of the element in the tabbing order. HTMLElement.title-
Is a
DOMStringcontaining the text that appears in a popup box when mouse is over the element. -
HTMLElement.translate -
Is a
Booleanrepresenting the translation.
Event handlers
Most event handler properties, of the form onXYZ, are defined on the DocumentAndElementEventHandlers, GlobalEventHandlers or TouchEventHandlers interfaces and implemented by HTMLElement. In addition, the following handlers are specific to HTMLElement.
-
HTMLElement.oncopy -
Returns the event handling code for the
copyevent (bug 280959). -
HTMLElement.oncut -
Returns the event handling code for the
cutevent (bug 280959). -
HTMLElement.onpaste -
Returns the event handling code for the
pasteevent (bug 280959). -
TouchEventHandlers.ontouchstart -
Returns the event handling code for the
touchstartevent. -
TouchEventHandlers.ontouchend -
Returns the event handling code for the
touchendevent. -
TouchEventHandlers.ontouchmove -
Returns the event handling code for the
touchmoveevent. -
TouchEventHandlers.ontouchenter -
Returns the event handling code for the
touchenterevent. -
TouchEventHandlers.ontouchleave -
Returns the event handling code for the
touchleaveevent. -
TouchEventHandlers.ontouchcancel -
Returns the event handling code for the
touchcancelevent.
Methods
Inherits methods from its parent, Element, and implements those from DocumentAndElementEventHandlers, GlobalEventHandlers, and TouchEventHandlers.
-
HTMLElement.attachInternals() -
Returns an
ElementInternalsobject, and enables a custom element to participate in HTML forms. HTMLElement.blur()-
Removes keyboard focus from the currently focused element.
HTMLElement.click()-
Sends a mouse click event to the element.
HTMLElement.focus()-
Makes the element the current keyboard focus.
Events
Listen to these events using addEventListener() or by assigning an event listener to the oneventname property of this interface.
invalid-
Fired when an element does not satisfy its constraints during constraint validation. Also available via the
oninvalidproperty.
Animation events
animationcancel-
Fired when an animation unexpectedly aborts. Also available via the
onanimationcancelproperty. animationend-
Fired when an animation has completed normally. Also available via the
onanimationendproperty. animationiteration-
Fired when an animation iteration has completed. Also available via the
onanimationiterationproperty. animationstart-
Fired when an animation starts. Also available via the
onanimationstartproperty.
Input events
beforeinput-
Fired when the value of an
<input>,<select>, or<textarea>element is about to be modified. input-
Fired when the
valueof an<input>,<select>, or<textarea>element has been changed. Also available via theoninputproperty. change-
Fired when the
valueof an<input>,<select>, or<textarea>element has been changed and committed by the user. Unlike theinputevent, thechangeevent is not necessarily fired for each alteration to an element'svalue.
Pointer events
gotpointercapture-
Fired when an element captures a pointer using
setPointerCapture(). Also available via theongotpointercaptureproperty. lostpointercapture-
Fired when a captured pointer is released. Also available via the
onlostpointercaptureproperty. pointercancel-
Fired when a pointer event is canceled. Also available via the
onpointercancelproperty. pointerdown-
Fired when a pointer becomes active. Also available via the
onpointerdownproperty. pointerenter-
Fired when a pointer is moved into the hit test boundaries of an element or one of its descendants. Also available via the
onpointerenterproperty. pointerleave-
Fired when a pointer is moved out of the hit test boundaries of an element. Also available via the
onpointerleaveproperty. pointermove-
Fired when a pointer changes coordinates. Also available via the
onpointermoveproperty. pointerout-
Fired when a pointer is moved out of the hit test boundaries of an element (among other reasons). Also available via the
onpointeroutproperty. pointerover-
Fired when a pointer is moved into an element's hit test boundaries. Also available via the
onpointeroverproperty. pointerup-
Fired when a pointer is no longer active. Also available via the
onpointerupproperty.
Transition events
transitioncancel-
Fired when a CSS transition is canceled. Also available via the
ontransitioncancelproperty. transitionend-
Fired when a CSS transition has completed. Also available via the
ontransitionendproperty. transitionrun-
Fired when a CSS transition is first created. Also available via the
ontransitionrunproperty. transitionstart-
Fired when a CSS transition has actually started. Also available via the
ontransitionstartproperty.
Specifications
| Specification |
|---|
| HTML Standard (HTML) # htmlelement |
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
HTMLElement |
1 |
12 |
1 |
5.5 |
8 |
1.3 |
1 |
18 |
4 |
10.1 |
1 |
1.0 |
accessKey |
17 |
12 |
5 |
5.5 |
≤12.1 |
6 |
4.4 |
18 |
5 |
≤12.1 |
6 |
1.0 |
accessKeyLabel |
No |
No |
8 |
No |
No |
14 |
No |
No |
8 |
No |
14 |
No |
animationcancel_event |
No |
No |
54 |
No |
No |
13.1
12
|
No |
No |
54 |
No |
13.4
12
|
No |
animationend_event |
43 |
12 |
Yes |
10 |
30 |
9 |
43 |
43 |
Yes |
30 |
9 |
4.0 |
animationiteration_event |
43 |
12 |
51 |
10 |
30 |
9 |
43 |
43 |
51 |
30 |
9 |
4.0 |
animationstart_event |
43 |
12 |
51 |
10 |
30 |
9 |
43 |
43 |
51 |
30 |
9 |
4.0 |
attachInternals |
77 |
79 |
93 |
No |
64 |
No |
77 |
77 |
93 |
55 |
No |
12.0 |
autocapitalize |
66 |
79 |
83 |
No |
53 |
No |
66 |
66 |
83 |
47 |
10.3 |
9.0 |
autofocus |
79
1-79
Supported for
HTMLButtonElement, HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement. |
79
12-79
Supported for
HTMLButtonElement, HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement. |
1
Supported for
HTMLButtonElement, HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement. |
10
Supported for
HTMLButtonElement, HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement. |
66
≤12.1-66
Supported for
HTMLButtonElement, HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement. |
4
Supported for
HTMLButtonElement, HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement. |
79
≤37-79
Supported for
HTMLButtonElement, HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement. |
79
18-79
Supported for
HTMLButtonElement, HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement. |
4
Supported for
HTMLButtonElement, HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement. |
57
≤12.1-57
Supported for
HTMLButtonElement, HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement. |
3.2
Supported for
HTMLButtonElement, HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement. |
12.0
1.0-12.0
Supported for
HTMLButtonElement, HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement. |
beforeinput_event |
Yes |
79 |
87
74-87
|
No |
Yes |
Yes |
Yes |
Yes |
87
79-87
|
Yes |
Yes |
Yes |
blur |
1 |
12 |
1.5 |
5.5 |
8 |
3 |
4.4 |
18 |
4 |
10.1 |
1 |
1.0 |
click |
9
Before Chrome 19,
click() is only defined on buttons and inputs. |
12 |
3
["Before Firefox 5,
click() is only defined on buttons and inputs, and has no effect on text and file inputs.", "Starting in Firefox 75, the click() function works even when the element is not attached to a DOM tree."] |
5.5 |
10.5 |
6 |
≤37
Before Android WebView 4.4,
click() is only defined on buttons and inputs. |
18
Before Chrome 19,
click() is only defined on buttons and inputs. |
4
["Before Firefox 5,
click() is only defined on buttons and inputs, and has no effect on text and file inputs.", "Starting in Firefox for Android 79, the click() function works even when the element is not attached to a DOM tree."] |
11 |
6 |
1.0
Before Samsung Internet 1.5,
click() is only defined on buttons and inputs. |
contentEditable |
1 |
12 |
3 |
5.5 |
9 |
3 |
4.4 |
18 |
4 |
10.1 |
1 |
1.0 |
contextMenu |
45-61 |
≤18-79 |
85
8-85
|
No |
No |
No |
45-61 |
45-61 |
85
8-85
|
No |
No |
5.0-8.0 |
dataset |
8 |
12 |
6 |
11 |
11 |
5.1 |
4.4 |
18 |
6 |
11 |
5 |
1.0 |
dir |
1 |
12 |
1 |
5.5 |
≤12.1 |
3 |
4.4 |
18 |
4 |
≤12.1 |
1 |
1.0 |
draggable |
3 |
12 |
2 |
10 |
12 |
5 |
4.4 |
18 |
4 |
12 |
4 |
1.0 |
enterKeyHint |
77 |
79 |
94
79-94
|
No |
64 |
13.1 |
77 |
77 |
94 |
55 |
13.4 |
12.0 |
focus |
1 |
12 |
1.5 |
5.5 |
8 |
3 |
4.4 |
18 |
4 |
10.1 |
1 |
1.0 |
gotpointercapture_event |
57 |
17 |
59 |
No |
44 |
13 |
57 |
57 |
79 |
43 |
13 |
7.0 |
hidden |
6 |
12 |
1 |
11 |
11.6 |
5.1 |
≤37 |
18 |
4 |
12 |
5 |
1.0 |
inert |
60 |
79 |
81 |
No |
47 |
No |
No |
60 |
81 |
44 |
No |
No |
innerText |
1 |
12 |
45 |
5.5 |
9.6 |
3 |
4.4 |
18 |
45 |
10.1 |
1 |
1.0 |
input_event |
1 |
79
12-79
Not supported on
select, checkbox, or radio inputs. |
6 |
9
Only supports
input of type text and password. |
11.6 |
3.1 |
1 |
18 |
6 |
12 |
2 |
1.0 |
inputMode |
66 |
79 |
77 |
No |
53 |
12.1 |
66 |
66 |
79 |
47 |
12.2 |
9.0 |
isContentEditable |
1 |
12 |
4 |
5.5 |
≤12.1 |
3 |
4.4 |
18 |
4 |
≤12.1 |
1 |
1.0 |
itemId |
17-28 |
No |
16-49 |
No |
11-15 |
No |
No |
18-28 |
16-49 |
11-14 |
No |
1.0-1.5 |
itemProp |
17-28 |
No |
16-49 |
No |
11-15 |
No |
No |
18-28 |
16-49 |
11-14 |
No |
1.0-1.5 |
itemRef |
17-28 |
No |
16-49 |
No |
11-15 |
No |
No |
18-28 |
16-49 |
11-14 |
No |
1.0-1.5 |
itemScope |
17-28 |
No |
16-49 |
No |
11-15 |
No |
No |
18-28 |
16-49 |
11-14 |
No |
1.0-1.5 |
itemType |
17-28 |
No |
16-49 |
No |
11-15 |
No |
No |
18-28 |
16-49 |
11-14 |
No |
1.0-1.5 |
itemValue |
17-28 |
No |
16-49 |
No |
11-15 |
No |
No |
18-28 |
16-49 |
11-14 |
No |
1.0-1.5 |
lang |
1 |
12 |
1 |
5.5 |
≤12.1 |
3 |
4.4 |
18 |
4 |
≤12.1 |
1 |
1.0 |
lostpointercapture_event |
57 |
17 |
59 |
No |
44 |
13 |
57 |
57 |
79 |
43 |
13 |
7.0 |
nonce |
61 |
79 |
75 |
No |
48 |
10
The property is defined only for its useful elements:
<link>, <script>, and <style>; it is undefined for all other elements. |
61 |
61 |
79 |
45 |
10
The property is defined only for its useful elements:
<link>, <script>, and <style>; it is undefined for all other elements. |
8.0 |
offsetHeight |
1 |
12 |
1 |
5.5 |
8 |
3 |
1 |
18 |
4 |
10.1 |
1 |
1.0 |
offsetLeft |
1 |
12 |
1 |
5.5 |
8 |
3 |
1 |
18 |
4 |
10.1 |
1 |
1.0 |
offsetParent |
1 |
12 |
1 |
5.5 |
8 |
3 |
1 |
18 |
4 |
10.1 |
1 |
1.0 |
offsetTop |
1 |
12 |
1 |
5.5 |
8 |
3 |
1 |
18 |
4 |
10.1 |
1 |
1.0 |
offsetWidth |
1 |
12 |
1 |
5.5 |
8 |
3 |
1 |
18 |
4 |
10.1 |
1 |
1.0 |
oncopy |
1 |
12 |
3 |
5.5 |
≤12.1 |
3 |
1 |
18 |
4 |
≤12.1 |
1 |
1.0 |
oncut |
1 |
12 |
9 |
5.5 |
≤12.1 |
3 |
1 |
18 |
9 |
≤12.1 |
1 |
1.0 |
onpaste |
1 |
12 |
9 |
5.5 |
≤12.1 |
3 |
1 |
18 |
9 |
≤12.1 |
1 |
1.0 |
outerText |
43 |
12 |
No |
5.5 |
≤12.1 |
1.3 |
43 |
43 |
No |
≤12.1 |
1 |
4.0 |
pointercancel_event |
55 |
12
12-79
|
59
29
|
11
10
|
42 |
13 |
55 |
55 |
79
29
|
42 |
13 |
6.0 |
pointerdown_event |
55 |
12
12-79
|
59
29
|
11
10
|
42 |
13 |
55 |
55 |
79
29
|
42 |
13 |
6.0 |
pointerenter_event |
55 |
12
12-79
|
59
29
|
11
10
|
42 |
13 |
55 |
55 |
79
29
|
42 |
13 |
6.0 |
pointerleave_event |
55 |
12
12-79
|
59
29
|
11
10
|
42 |
13 |
55 |
55 |
79
29
|
42 |
13 |
6.0 |
pointermove_event |
55 |
12
12-79
|
59
29
|
11
10
|
42 |
13 |
55 |
55 |
79
29
|
42 |
13 |
6.0 |
pointerout_event |
55 |
12
12-79
|
59
29
|
11
10
|
42 |
13 |
55 |
55 |
79
29
|
42 |
13 |
6.0 |
pointerover_event |
55 |
12
12-79
|
59
29
|
11
10
|
42 |
13 |
55 |
55 |
79
29
|
42 |
13 |
6.0 |
pointerrawupdate_event |
77 |
79 |
No |
No |
64 |
No |
77 |
77 |
No |
55 |
No |
12.0 |
pointerup_event |
55 |
12
12-79
|
59
29
|
11
10
|
42 |
13 |
55 |
55 |
79
29
|
42 |
13 |
6.0 |
spellcheck |
9 |
12 |
2 |
10 |
≤12.1 |
5.1 |
≤37 |
18 |
4 |
≤12.1 |
5 |
1.0 |
tabIndex |
1 |
18
12
Returns incorrect value for elements without an explicit tabindex attribute. See issue 4365703 for details.
|
1 |
5.5
Returns incorrect value for elements without an explicit tabindex attribute. See issue 4365703 for details.
|
≤12.1 |
3.1 |
4.4 |
18 |
4 |
≤12.1 |
2 |
1.0 |
title |
1 |
12 |
1 |
5.5 |
≤12.1 |
3 |
4.4 |
18 |
4 |
≤12.1 |
1 |
1.0 |
transitioncancel_event |
74 |
≤79 |
53 |
? |
62 |
13.1
12
|
74 |
74 |
53 |
53 |
13.4
12
|
11.0 |
transitionend_event |
26
1
|
≤79
≤79
|
51 |
10 |
12.1
15
11.6-15
|
7
4
|
≤37
≤37
|
26
18
|
51 |
12.1
14
12-14
|
7
3.2
|
1.5
1.0
|
transitionrun_event |
74 |
≤79 |
53 |
? |
62 |
13.1
12
|
74 |
74 |
53 |
53 |
13.4
12
|
11.0 |
transitionstart_event |
74 |
≤79 |
53 |
? |
62 |
13.1
12
|
74 |
74 |
53 |
53 |
13.4
12
|
11.0 |
translate |
19 |
79 |
No |
No |
15 |
6 |
4.4 |
25 |
No |
14 |
6 |
1.5 |
attributeStyleMap |
66 |
79 |
No |
No |
53 |
No |
66 |
66 |
No |
47 |
No |
9.0 |
style |
1 |
12 |
1 |
5.5 |
8 |
3 |
1 |
18 |
4 |
10.1 |
1 |
1.0 |
See also
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement