web-components-forms-a11y-pitfalls
Step 6 of the pipeline (WORKFLOW.md), for the second half of custom-element work: the part where an element stops being a private widget and has to cooperate with the page around it. The premise: a custom element is a bare box to the platform; it is not focusable, not labelled, not submitted, not reset, and its events do not mean what they meant before the shadow root was added, until you wire each of those yourself. Each rule gives the symptom, the check and the fix.
Constructor, callbacks, registration and teardown are in skills/web-components-lifecycle-pitfalls; the library-level practice for Lit is in skills/web-components-conventions; general widget semantics are in skills/accessibility and skills/nuxt-semantic-element-first. This block does not repeat them.
When
- A custom element wraps an input and "the form does not send it", "reset does nothing" or "it stays enabled inside a disabled fieldset".
- A custom button, checkbox or select is announced as nothing, cannot be tabbed to, or has no accessible name.
- A listener on the host sees the wrong
event.target, or an event never leaves the shadow root.
- Page styles do not reach into the element, or the element's styles leak out or lose to the page.
- The element must render on the server, then become interactive.
Skip when the element only displays content and takes no input: §1 does not apply; say "not applicable: reason".
Steps
Read the section the task meets. They are independent.
| § |
Covers |
Read it when |
File |
| 1 |
Form participation: formAssociated, setFormValue, validity, reset, disabled, restore, attribute against property |
the element holds a value that a form must submit or validate |
01-form-participation.md |
| 2 |
Default semantics, labels, focus, custom states, event retargeting and composed |
the element is interactive, or events cross the shadow edge |
02-semantics-focus-events.md |
| 3 |
Styling hooks across the boundary, declarative shadow DOM, hydration, testing |
styles must cross the boundary, or the element is server-rendered |
03-styling-and-server-render.md |
Output / checkpoint
An element is done when: a native <form> with it inside submits the expected pair, resets, disables with its fieldset and reports invalid through the form's own validation (§1); with the keyboard alone and a screen reader it is reachable, named, and announces its state (§2); an outer listener receives the event with a target that names the host (§2); and, if server-rendered, the page is readable and the markup is stable before any script runs (§3). No checkpoint is written: a craft block, 🟡, nothing here was run in a browser by us.
Guardrails
- Make the element form-associated and give the form its value through the element's internals (§1.1). Never mirror the value into a hidden light-DOM input as a workaround that duplicates validation and reset.
- Set default role, label and state through the internals, and let the page override them with attributes (§2.1). Never leave a clickable box with no role, no name and no tab stop.
- Dispatch events from the host and state
bubbles and composed on purpose (§2.4). Never rely on a retargeted event.target to find the inner node.
- Expose styling through custom properties and named parts (§3.1). Never ask page authors to reach into a shadow root, and do not reopen a closed root to allow it.
- Treat server-rendered markup as the first paint and the class as an upgrade (§3.3). Never read layout or the DOM of children in a constructor that can run on the server.
- Facts about specifications are for the date in
references/origin.md; re-read before relying.
Origin
Rewritten from the WHATWG HTML and DOM standards (CC BY 4.0), the W3C CSS Shadow, Cascade and CSSOM drafts and WAI-ARIA 1.2 (facts only), all read 2026-10-20, plus own craft knowledge; no text copied. Details and gaps in references/origin.md.
1---2name: web-components-forms-a11y-pitfalls3description: "Use when a native custom element must behave like a real control or sit inside a form, a shadow root, or a server-rendered page: form participation through ElementInternals (value, validity, reset, disabled, restore), default roles and labels, focus delegation, custom states, events that cross the shadow boundary (composed, retargeting, composedPath), shadow styling hooks, and declarative shadow DOM for server rendering."4metadata:5 source: https://skillmd.com/skills/techmefr/web-components-forms-a11y-pitfalls6---78# web-components-forms-a11y-pitfalls910Step 6 of the pipeline (`WORKFLOW.md`), for the second half of custom-element work: the part where an element stops being a private widget and has to cooperate with the page around it. The premise: **a custom element is a bare box to the platform; it is not focusable, not labelled, not submitted, not reset, and its events do not mean what they meant before the shadow root was added, until you wire each of those yourself**. Each rule gives the symptom, the check and the fix.1112Constructor, callbacks, registration and teardown are in `skills/web-components-lifecycle-pitfalls`; the library-level practice for Lit is in `skills/web-components-conventions`; general widget semantics are in `skills/accessibility` and `skills/nuxt-semantic-element-first`. This block does not repeat them.1314## When15- A custom element wraps an input and "the form does not send it", "reset does nothing" or "it stays enabled inside a disabled fieldset".16- A custom button, checkbox or select is announced as nothing, cannot be tabbed to, or has no accessible name.17- A listener on the host sees the wrong `event.target`, or an event never leaves the shadow root.18- Page styles do not reach into the element, or the element's styles leak out or lose to the page.19- The element must render on the server, then become interactive.2021**Skip when** the element only displays content and takes no input: §1 does not apply; say "not applicable: reason".2223## Steps2425**Read the section the task meets.** They are independent.2627| § | Covers | Read it when | File |28|---|---|---|---|29| 1 | Form participation: `formAssociated`, `setFormValue`, validity, reset, disabled, restore, attribute against property | the element holds a value that a form must submit or validate | [`01-form-participation.md`](./references/01-form-participation.md) |30| 2 | Default semantics, labels, focus, custom states, event retargeting and `composed` | the element is interactive, or events cross the shadow edge | [`02-semantics-focus-events.md`](./references/02-semantics-focus-events.md) |31| 3 | Styling hooks across the boundary, declarative shadow DOM, hydration, testing | styles must cross the boundary, or the element is server-rendered | [`03-styling-and-server-render.md`](./references/03-styling-and-server-render.md) |3233## Output / checkpoint34An element is done when: a native `<form>` with it inside submits the expected pair, resets, disables with its fieldset and reports invalid through the form's own validation (§1); with the keyboard alone and a screen reader it is reachable, named, and announces its state (§2); an outer listener receives the event with a target that names the host (§2); and, if server-rendered, the page is readable and the markup is stable before any script runs (§3). No checkpoint is written: a craft block, 🟡, nothing here was run in a browser by us.3536## Guardrails37- Make the element form-associated and give the form its value through the element's internals (§1.1). Never mirror the value into a hidden light-DOM input as a workaround that duplicates validation and reset.38- Set default role, label and state through the internals, and let the page override them with attributes (§2.1). Never leave a clickable box with no role, no name and no tab stop.39- Dispatch events from the host and state `bubbles` and `composed` on purpose (§2.4). Never rely on a retargeted `event.target` to find the inner node.40- Expose styling through custom properties and named parts (§3.1). Never ask page authors to reach into a shadow root, and do not reopen a closed root to allow it.41- Treat server-rendered markup as the first paint and the class as an upgrade (§3.3). Never read layout or the DOM of children in a constructor that can run on the server.42- Facts about specifications are for the date in `references/origin.md`; re-read before relying.4344## Origin45Rewritten from the WHATWG HTML and DOM standards (CC BY 4.0), the W3C CSS Shadow, Cascade and CSSOM drafts and WAI-ARIA 1.2 (facts only), all read 2026-10-20, plus own craft knowledge; no text copied. Details and gaps in [`references/origin.md`](./references/origin.md).