HTMLElement
Baseline Widely available *
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
* Some parts of this feature may have varying levels of support.
TheHTMLElement interface represents anyHTML element. Some elements directly implement this interface, while others implement it via an interface that inherits it.
In this article
Instance properties
Also inherits properties from its parent,Element.
HTMLElement.accessKeyA string representing the access key assigned to the element.
HTMLElement.accessKeyLabelRead onlyReturns a string containing the element's assigned access key.
HTMLElement.anchorElementRead only Non-standardExperimentalReturns a reference to the element's anchor element, or
nullif it doesn't have one.HTMLElement.attributeStyleMapRead onlyA
StylePropertyMaprepresenting the declarations of the element'sstyleattribute.HTMLElement.autocapitalizeA string that represents the element's capitalization behavior for user input. Valid values are:
none,off,on,characters,words,sentences.HTMLElement.autofocusA boolean value reflecting the
autofocusHTML global attribute, which indicates whether the control should be focused when the page loads, or when dialog or popover become shown if specified in an element inside<dialog>elements or elements whose popover attribute is set.HTMLElement.autocorrectA boolean that represents whether or not text input by a user should be automatically corrected.This reflects the
autocorrectHTML global attribute.HTMLElement.contentEditableA string, where a value of
truemeans the element is editable and a value offalsemeans it isn't.HTMLElement.datasetRead onlyReturns a
DOMStringMapwith which script can read and write the element'scustom data attributes (data-*).HTMLElement.dirA string, reflecting the
dirglobal attribute, representing the directionality of the element. Possible values are"ltr","rtl", and"auto".HTMLElement.draggableA boolean value indicating if the element can be dragged.
HTMLElement.editContextExperimentalReturns the
EditContextassociated with the element, ornullif there isn't one.HTMLElement.enterKeyHintA string defining what action label (or icon) to present for the enter key on virtual keyboards.
HTMLElement.hiddenA string or boolean value reflecting the value of the element's
hiddenattribute.HTMLElement.inertA boolean value indicating 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.innerTextRepresents 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.As a setter, it replaces the content inside the selected element, converting any line breaks into
<br>elements.HTMLElement.inputModeA string value reflecting the value of the element's
inputmodeattribute.HTMLElement.isContentEditableRead onlyReturns a boolean value indicating whether or not the content of the element can be edited.
HTMLElement.langA string representing the language of an element's attributes, text, and element contents.
HTMLElement.nonceReturns 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 onlyReturns a
doublecontaining the height of an element, relative to the layout.HTMLElement.offsetLeftRead onlyReturns a
double, the distance from this element's left border to itsoffsetParent's left border.HTMLElement.offsetParentRead onlyAn
Elementthat is the element from which all offset calculations are currently computed.HTMLElement.offsetTopRead onlyReturns a
double, the distance from this element's top border to itsoffsetParent's top border.HTMLElement.offsetWidthRead onlyReturns a
doublecontaining the width of an element, relative to the layout.HTMLElement.outerTextRepresents the rendered text content of a node and its descendants.As a getter, it is the same as
HTMLElement.innerText(it represents the rendered text content of an element and its descendants).As a setter, it replaces the selected node and its contents with the given value, converting any line breaks into<br>elements.HTMLElement.popoverGets and sets an element's popover state via JavaScript (
"auto","hint", or"manual"), and can be used for feature detection. Reflects the value of thepopoverglobal HTML attribute.HTMLElement.spellcheckA boolean value that controls thespell-checking hint. It is available on all HTML elements, though it doesn't affect all of them.
HTMLElement.styleA
CSSStyleDeclarationrepresenting the declarations of the element'sstyleattribute.HTMLElement.tabIndexA
longrepresenting the position of the element in the tabbing order.HTMLElement.titleA string containing the text that appears in a popup box when mouse is over the element.
HTMLElement.translateA boolean value representing the translation.
HTMLElement.virtualKeyboardPolicyExperimentalA string indicating the on-screen virtual keyboard behavior on devices such as tablets, mobile phones, or other devices where a hardware keyboard may not be available, if the element's content is editable (for example, it is an
<input>or<textarea>element, or an element with thecontenteditableattribute set).HTMLElement.writingSuggestionsA string indicating if browser-provided writing suggestions should be enabled under the scope of the element or not.
Instance methods
Also inherits methods from its parent,Element.
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.
HTMLElement.hidePopover()Hides a popover element by removing it from thetop layer and styling it with
display: none.HTMLElement.showPopover()Shows a popover element by adding it to thetop layer and removing
display: none;from its styles.HTMLElement.togglePopover()Toggles a popover element between the hidden and showing states.
Events
Listen to these events usingaddEventListener() or by assigning an event listener to theoneventname property of this interface.
Also, inherits events from its parent,Element.
changeFired 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.commandFires on an element that is controlled via a
buttonwith validcommandForElementandcommandvalues, whenever the button is interacted with (e.g., it is clicked).errorFired when a resource failed to load, or can't be used.
loadFires for elements containing a resource when the resource has successfully loaded.
Drag & drop events
dragThis event is fired when an element or text selection is being dragged.
dragendThis event is fired when a drag operation is being ended (by releasing a mouse button or hitting the escape key).
dragenterThis event is fired when a dragged element or text selection enters a valid drop target.
dragleaveThis event is fired when a dragged element or text selection leaves a valid drop target.
dragoverThis event is fired continuously when an element or text selection is being dragged and the mouse pointer is over a valid drop target (every 50 ms WHEN mouse is not moving ELSE much faster between 5 ms (slow movement) and 1ms (fast movement) approximately. This firing pattern is different than
mouseover).dragstartThis event is fired when the user starts dragging an element or text selection.
dropThis event is fired when an element or text selection is dropped on a valid drop target.
Toggle events
Specifications
| Specification |
|---|
| HTML> # htmlelement> |