DOM Methods

HTMLElement.attachInternals()

Build a form with the HTML form generator

Obtains internal APIs for an eligible autonomous custom element. A second attachment throws; call once, usually during construction, and retain the result. Form-specific operations additionally require a form-associated definition. Example result: true.

Formal Syntax & Structure

html syntaxhtml
this.attachInternals()

Return Value

ElementInternals

Internal object.

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 instanceof ElementInternals;  })().catch(error => { result.textContent = "Error: " + error.name; });</script>

Browser Compatibility

Minimum supported versions across modern rendering engines

Widely Available (2023)
Blink
Chrome
77+
Yes
Blink
Edge
79+
Yes
Gecko
Firefox
93+
Yes
WebKit
Safari
16.4+
Yes
Blink
Opera
64+
Yes
The attachInternals method is widely available. Baseline interoperability since March 2023; individual ElementInternals members may differ.
HTML Living Standard
HTML Reference