ElementInternals
Baseline Widely available *
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2023.
* Some parts of this feature may have varying levels of support.
TheElementInternals interface of theDocument Object Model gives web developers a way to allow custom elements to fully participate in HTML forms. It provides utilities for working with these elements in the same way you would work with any standard HTML form element, and also exposes theAccessibility Object Model to the element.
In this article
Constructor
This interface has no constructor. AnElementInternals object is returned when callingHTMLElement.attachInternals().
Instance properties
ElementInternals.shadowRootRead onlyReturns the
ShadowRootobject associated with this element.ElementInternals.formRead onlyReturns the
HTMLFormElementassociated with this element.ElementInternals.statesRead onlyReturns the
CustomStateSetassociated with this element.ElementInternals.willValidateRead onlyA boolean value which returns true if the element is a submittable element that is a candidate forconstraint validation.
ElementInternals.validityRead onlyReturns a
ValidityStateobject which represents the different validity states the element can be in, with respect to constraint validation.ElementInternals.validationMessageRead onlyA string containing the validation message of this element.
ElementInternals.labelsRead onlyReturns a
NodeListof all of the label elements associated with this element.
Instance properties included from ARIA
TheElementInternals interface also includes the following properties.
Note:These are included in order that default accessibility semantics can be defined on a custom element. These may be overwritten by author-defined attributes, but ensure that default semantics are retained should the author delete those attributes, or fail to add them at all. For more information see theAccessibility Object Model explainer.
ElementInternals.ariaAtomicA string reflecting the
aria-atomicattribute, which indicates whether assistive technologies will present all, or only parts of, the changed region based on the change notifications defined by thearia-relevantattribute.ElementInternals.ariaAutoCompleteA string reflecting the
aria-autocompleteattribute, which indicates whether inputting text could trigger display of one or more predictions of the user's intended value for a combobox, searchbox, or textbox and specifies how predictions would be presented if they were made.ElementInternals.ariaBrailleLabelA string reflecting the
aria-braillelabelattribute, which defines the braille label of the element.ElementInternals.ariaBrailleRoleDescriptionA string reflecting the
aria-brailleroledescriptionattribute, which defines the ARIA braille role description of the element.ElementInternals.ariaBusyA string reflecting the
aria-busyattribute, which indicates whether an element is being modified, as assistive technologies may want to wait until the modifications are complete before exposing them to the user.ElementInternals.ariaCheckedA string reflecting the
aria-checkedattribute, which indicates the current "checked" state of checkboxes, radio buttons, and other widgets that have a checked state.ElementInternals.ariaColCountA string reflecting the
aria-colcountattribute, which defines the number of columns in a table, grid, or treegrid.ElementInternals.ariaColIndexA string reflecting the
aria-colindexattribute, which defines an element's column index or position with respect to the total number of columns within a table, grid, or treegrid.ElementInternals.ariaColIndexTextA string reflecting the
aria-colindextextattribute, which defines a human readable text alternative of aria-colindex.ElementInternals.ariaColSpanA string reflecting the
aria-colspanattribute, which defines the number of columns spanned by a cell or gridcell within a table, grid, or treegrid.ElementInternals.ariaCurrentA string reflecting the
aria-currentattribute, which indicates the element that represents the current item within a container or set of related elements.ElementInternals.ariaDescriptionA string reflecting the
aria-descriptionattribute, which defines a string value that describes or annotates the current ElementInternals.ElementInternals.ariaDisabledA string reflecting the
aria-disabledattribute, which indicates that the element is perceivable but disabled, so it is not editable or otherwise operable.ElementInternals.ariaExpandedA string reflecting the
aria-expandedattribute, which indicates whether a grouping element owned or controlled by this element is expanded or collapsed.ElementInternals.ariaHasPopupA string reflecting the
aria-haspopupattribute, which indicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an ElementInternals.ElementInternals.ariaHiddenA string reflecting the
aria-hiddenattribute, which indicates whether the element is exposed to an accessibility API.ElementInternals.ariaInvalidA string reflecting the
aria-invalidattribute, which indicates the entered value does not conform to the format expected by the application.ElementInternals.ariaKeyShortcutsA string reflecting the
aria-keyshortcutsattribute, which indicates keyboard shortcuts that an author has implemented to activate or give focus to an object.ElementInternals.ariaLabelA string reflecting the
aria-labelattribute, which defines a string value that labels the current object.ElementInternals.ariaLevelA string reflecting the
aria-levelattribute, which defines the hierarchical level of an element within a structure.ElementInternals.ariaLiveA string reflecting the
aria-liveattribute, which indicates that an element will be updated, and describes the types of updates the user agents, assistive technologies, and user can expect from the live region.ElementInternals.ariaModalA string reflecting the
aria-modalattribute, which indicates whether an element is modal when displayed.ElementInternals.ariaMultilineA string reflecting the
aria-multilineattribute, which indicates whether a text box accepts multiple lines of input or only a single line.ElementInternals.ariaMultiSelectableA string reflecting the
aria-multiselectableattribute, which indicates that the user may select more than one item from the current selectable descendants.ElementInternals.ariaOrientationA string reflecting the
aria-orientationattribute, which indicates whether the element's orientation is horizontal, vertical, or unknown/ambiguous.ElementInternals.ariaPlaceholderA string reflecting the
aria-placeholderattribute, which defines a short hint intended to aid the user with data entry when the control has no value.ElementInternals.ariaPosInSetA string reflecting the
aria-posinsetattribute, which defines an element's number or position in the current set of listitems or treeitems.ElementInternals.ariaPressedA string reflecting the
aria-pressedattribute, which indicates the current "pressed" state of toggle buttons.ElementInternals.ariaReadOnlyA string reflecting the
aria-readonlyattribute, which indicates that the element is not editable, but is otherwise operable.ElementInternals.ariaRelevantNon-standardA string reflecting the
aria-relevantattribute, which indicates what notifications the user agent will trigger when the accessibility tree within a live region is modified. This is used to describe what changes in anaria-liveregion are relevant and should be announced.ElementInternals.ariaRequiredA string reflecting the
aria-requiredattribute, which indicates that user input is required on the element before a form may be submitted.ElementInternals.roleA string which contains an ARIA role. A full list of ARIA roles can be found on theARIA techniques page.
ElementInternals.ariaRoleDescriptionA string reflecting the
aria-roledescriptionattribute, which defines a human-readable, author-localized description for the role of an Element.ElementInternals.ariaRowCountA string reflecting the
aria-rowcountattribute, which defines the total number of rows in a table, grid, or treegrid.ElementInternals.ariaRowIndexA string reflecting the
aria-rowindexattribute, which defines an element's row index or position with respect to the total number of rows within a table, grid, or treegrid.ElementInternals.ariaRowIndexTextA string reflecting the
aria-rowindextextattribute, which defines a human readable text alternative of aria-rowindex.ElementInternals.ariaRowSpanA string reflecting the
aria-rowspanattribute, which defines the number of rows spanned by a cell or gridcell within a table, grid, or treegrid.ElementInternals.ariaSelectedA string reflecting the
aria-selectedattribute, which indicates the current "selected" state of elements that have a selected state.ElementInternals.ariaSetSizeA string reflecting the
aria-setsizeattribute, which defines the number of items in the current set of listitems or treeitems.ElementInternals.ariaSortA string reflecting the
aria-sortattribute, which indicates if items in a table or grid are sorted in ascending or descending order.ElementInternals.ariaValueMaxA string reflecting the
aria-valueMaxattribute, which defines the maximum allowed value for a range widget.ElementInternals.ariaValueMinA string reflecting the
aria-valueMinattribute, which defines the minimum allowed value for a range widget.ElementInternals.ariaValueNowA string reflecting the
aria-valueNowattribute, which defines the current value for a range widget.ElementInternals.ariaValueTextA string reflecting the
aria-valuetextattribute, which defines the human-readable text alternative of aria-valuenow for a range widget.
Instance properties reflected from ARIA element references
The properties reflect the elements specified byid reference in the corresponding attributes, but with some caveats. SeeReflected element references in theReflected attributes guide for more information.
ElementInternals.ariaActiveDescendantElementAn element that represents the current active element when focus is on a
compositewidget,combobox,textbox,group, orapplication.Reflects thearia-activedescendantattribute.ElementInternals.ariaControlsElementsAn array of elements whose contents or presence are controlled by the element it is applied to.Reflects the
aria-controlsattribute.ElementInternals.ariaDescribedByElementsAn array of elements that contain the accessible description for the element it is applied to.Reflects the
aria-describedbyattribute.ElementInternals.ariaDetailsElementsAn array of elements that provide accessible details for the element it is applied to.Reflects the
aria-detailsattribute.ElementInternals.ariaErrorMessageElementsAn array of elements that provide an error message for the element it is applied to.Reflects the
aria-errormessageattribute.ElementInternals.ariaFlowToElementsAn array of elements that identify the next element (or elements) in an alternate reading order of content, overriding the general default reading order at the user's discretion.Reflects the
aria-flowtoattribute.ElementInternals.ariaLabelledByElementsAn array of elements that provide the accessible name for the element it is applied to.Reflects the
aria-labelledbyattribute.ElementInternals.ariaOwnsElementsAn array of elements owned by the element this is applied to.This is used to define a visual, functional, or contextual relationship between a parent and its child elements when the DOM hierarchy cannot be used to represent the relationship.Reflects the
aria-ownsattribute.
Instance methods
ElementInternals.setFormValue()Sets the element's submission value and state, communicating these to the user agent.
ElementInternals.setValidity()Sets the validity of the element.
ElementInternals.checkValidity()Checks if an element meets anyconstraint validation rules applied to it.
ElementInternals.reportValidity()Checks if an element meets anyconstraint validation rules applied to it, and also sends a validation message to the user agent.
Examples
The following example demonstrates how to create a custom form-associated element withHTMLElement.attachInternals.
class CustomCheckbox extends HTMLElement { static formAssociated = true; constructor() { super(); this.internals_ = this.attachInternals(); } // …}window.customElements.define("custom-checkbox", CustomCheckbox);let element = document.createElement("custom-checkbox");let form = document.createElement("form");// Append element to form to associate itform.appendChild(element);console.log(element.internals_.form);// expected output: <form><custom-checkbox></custom-checkbox></form>Specifications
| Specification |
|---|
| HTML> # the-elementinternals-interface> |
Browser compatibility
See also
- More capable form controls via web.dev (2019)
- Creating custom form controls with ElementInternals via CSS-tricks (2021)