---
title: "ElementInternals and Form-Associated Custom Elements"
description: "Safari Technology Preview 162 enables ElementInternals and form-associated custom elements by default, letting custom elements set default ARIA roles and labels and take part in form submission and validation."
url: "https://swe.quest/articles/elementinternals-and-form-associated-custom-elements-ed9dab4b8065833c"
canonical: "https://webkit.org/blog/13711/elementinternals-and-form-associated-custom-elements/"
source: "WebKit"
published: "2023-02-06"
difficulty: "medium"
kind: "How-to"
reading_minutes: 4
tags: ["browsers","frontend","accessibility","javascript"]
---

# ElementInternals and Form-Associated Custom Elements

A post on [WebKit](https://swe.quest/sources/webkit.md), published 2023-02-06, 4 min read, How-to. Original: [https://webkit.org/blog/13711/elementinternals-and-form-associated-custom-elements/](https://webkit.org/blog/13711/elementinternals-and-form-associated-custom-elements/)

## Summary

Safari Technology Preview 162 enables ElementInternals and form-associated custom elements by default, letting custom elements set default ARIA roles and labels and take part in form submission and validation. Calling attachInternals() and setting ariaRole avoids the old pattern of adding a role attribute in the constructor, which blocked page authors from overriding it. Declaring static formAssociated = true enables setFormValue, setValidity and reportValidity with native validation UI and :invalid styling. The lifecycle callbacks formAssociatedCallback, formResetCallback, formDisabledCallback and formStateRestoreCallback are also available, though WebKit currently supports only string state and not autocomplete restoration.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Browsers](https://swe.quest/tags/browsers.md) (Web & mobile)
- [Frontend](https://swe.quest/tags/frontend.md) (Web & mobile)
- [Accessibility](https://swe.quest/tags/accessibility.md) (Web & mobile)
- [JavaScript](https://swe.quest/tags/javascript.md) (Languages)

## Prerequisites

- Custom Elements API
- Shadow DOM
- HTML forms

## Keywords

ElementInternals, Custom Elements, WebKit, Safari Technology Preview, ARIA, Shadow DOM

## Related posts

- [WebKit Features in Safari 16.0](https://swe.quest/articles/webkit-features-in-safari-16-0-e20c6c1e305e84fe.md): WebKit · 2022-09-12 · Easy · 10 min read · Browsers, CSS, Identity & auth, Accessibility, Developer tools
  Safari 16.0 ships AVIF images on iOS, passkeys built on WebAuthn, CSS Container Queries (size queries and cq\* units), Subgrid, Offset Path animation, overscroll-behavior, Shared Workers, and Web Inspector Extensions, plus a new Flexbox Inspector.
- [Introducing the Dialog Element](https://swe.quest/articles/introducing-the-dialog-element-9af9ed3251b7cd00.md): WebKit · 2022-02-07 · Medium · 4 min read · Browsers, Frontend, Accessibility, CSS
  Safari 15.4 beta and Safari Technology Preview 134 add the HTML \`\<dialog\>\` element, a native, accessible replacement for the script-blocking \`alert\`, \`confirm\` and \`prompt\` methods and for framework-built modals.
- [An HTML Switch Control](https://swe.quest/articles/an-html-switch-control-f6ff0673a2bcdfca.md): WebKit · 2024-02-28 · Medium · 3 min read · Browsers, Frontend, Accessibility, CSS
  Safari 17.4 adds a native HTML switch control via \`\<input type=checkbox switch\>\`, which falls back to a plain checkbox in browsers without support.
- [New WebKit Features in Safari 15.5](https://swe.quest/articles/new-webkit-features-in-safari-15-5-b4bbee299beae982.md): WebKit · 2022-05-16 · Easy · 5 min read · Browsers, CSS, Accessibility, Application security
  Safari 15.5 is mostly a polish and bug-fix release, adding three developer-facing technologies: the HTML \`inert\` attribute, which makes an element non-interactive and hides it from assistive technologies; the CSP Level 3 \`worker-src\` directive for restricting worker script sources; and WKWebView \`minimumViewportInset\`/\`maximumViewportInset\` APIs so apps can support the new CSS small, large and dynamic viewport units.
- [In March, we see Firefox 87](https://swe.quest/articles/in-march-we-see-firefox-87-89133003c9c65b13.md): Mozilla Hacks · 2021-03-23 · Medium · 4 min read · Browsers, Privacy, Developer tools, Accessibility
  Firefox 87 enables the beforeinput event and InputEvent.getTargetRanges() by default, letting web apps inspect and cancel text edits in inputs and contenteditable elements before the DOM changes, with an example that protects metadata spans inside an editable comment.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
