Form-Associated Custom Elements

Guide to making web components participate in native HTML form submission using ElementInternals.

Form-Associated Custom Elements

Make web components participate in native HTML form submission, validation, and reset using the ElementInternals API.

What Are Form-Associated Custom Elements?

By default, custom elements are invisible to HTML forms. A <form> only collects data from native form controls (<input>, <select>, <textarea>). Form-Associated Custom Elements (FACE) let your web components behave like native form controls:

  • Submit values via FormData without hidden inputs
  • Participate in native constraint validation (:valid, :invalid)
  • Respond to form reset and browser history restoration
  • Work with <label> and <fieldset>

Complete Template

Here is a complete annotated template showing all the pieces needed for a form-associated web component:

Step-by-Step Checklist

The boilerplate is intentionally small — roughly 5 lines to opt in. The rest is component-specific logic.

VB components like <combo-box> use a different strategy: the light-DOM input and list are usable before JS, and JS enhances them with filtering, keyboard navigation, and form association.

Validation

The setValidity() method accepts the same constraint flags as native inputs:

Firefox ARIA Caveat

Firefox does not yet support ARIA reflection on ElementInternals. When you set internals.role or internals.ariaLabel, Firefox silently ignores it. VB provides a small utility to handle this cross-browser:

These helpers check for support and fall back to setting attributes on the host element. See src/utils/form-internals.js.

VB Examples

Two VB components use this pattern:

  • <star-rating> — Star rating input with radio buttons internally, form value via ElementInternals
  • <combo-box> — Autocomplete combobox with full keyboard navigation, filtering, and form association

Browser Support

Form-Associated Custom Elements are supported in all modern browsers. ElementInternals shipped in Chrome 77, Firefox 93, and Safari 16.4. The ARIA reflection part of ElementInternals is not yet supported in Firefox (use the VB utility above).

Further Reading