DOM Interfaces
ElementInternals
Provides a custom element with internal form participation and accessibility capabilities. Setting static formAssociated = true enables form-specific members. It does not automatically supply keyboard interaction, labels or a value; the component author implements these. Example result: demo-form.
Formal Syntax & Structure
html syntaxhtml
this.attachInternals()Return Value
ElementInternals
Internal object associated with the custom element.
Working Example
Example Snippethtml
<form id="demo-form"> <demo-field name="city"></demo-field></form><p> Result: <output id="result"></output></p><script> const result = document.getElementById("result"); (async () => { class DemoField extends HTMLElement { static formAssociated = true; constructor() { super(); this.internals = this.attachInternals(); } } customElements.define("demo-field", DemoField); const field = document.querySelector("demo-field"); const internals = field.internals; result.textContent = internals.form.id; })().catch(error => { result.textContent = "Error: " + error.name; });</script>