Field
Label, control, hint and error message wired with aria-describedby and aria-invalid.
Live example
With a hint
<div data-field>
<label for="f-name">Display name</label>
<input id="f-name" name="display-name" type="text" autocomplete="nickname" aria-describedby="f-name-hint">
<p id="f-name-hint" data-field-hint>Shown next to your comments.</p>
</div>
With a hint and an error
<div data-field>
<label for="f-email">Email</label>
<input id="f-email" name="email" type="email" autocomplete="email" value="ada@" aria-invalid="true" aria-describedby="f-email-hint f-email-error">
<p id="f-email-hint" data-field-hint>We only use this to reply.</p>
<p id="f-email-error" data-field-error>Error: enter an email address like name@example.com.</p>
</div>
Native validation
<form action="#native-title" class="stack">
<div data-field>
<label for="f-code">Invite code</label>
<input id="f-code" name="code" type="text" required minlength="6" aria-describedby="f-code-hint">
<p id="f-code-hint" data-field-hint>Six characters or more.</p>
</div>
<div class="cluster">
<button type="submit">Join</button>
</div>
</form>
A group with an error
<fieldset data-field aria-describedby="f-size-error">
<legend>Size</legend>
<label><input type="radio" name="size" value="s"> Small</label>
<label><input type="radio" name="size" value="m"> Medium</label>
<p id="f-size-error" data-field-error>Error: choose a size.</p>
</fieldset>
Attributes
data-field on the wrapper, data-field-hint and data-field-error on the messages
| Attribute or value | Where | Effect |
|---|---|---|
data-field | the wrapper (a <div>, or a <fieldset> for groups) | |
data-field-hint | the hint | |
data-field-error | the error message |
- The wrapper is a
<div>, or a<fieldset>for a group of controls. - Hide an error that does not apply with
hidden, and remove its id fromaria-describedby.
- Our choice: the secondary button sits on the page surface with a softer border (
--dui-color-border-button, neutral step 7) and a 1px shadow. Its visible text label identifies it, so WCAG 1.4.11 does not require a 3:1 boundary; fields, selects, checkboxes, radios and switches keep the 3:1--dui-color-border-control. - Our choice: buttons, fields, selects and badges use the 14px interface size (
--dui-font-size-ui). Fields, selects and text areas use--dui-font-size-field, which is at least 16px under a coarse pointer, because iOS Safari zooms into a focused field with smaller text. - Our choice: default buttons and fields are 36px tall and large ones 40px, and a coarse (touch) pointer restores 44px, between Primer and Radix (32px) and Material (40px), for comparison.
- Our choice: the field's error text starts with the word "Error:" in the markup, rather than a CSS icon, so every user and every screen reader gets it with no extra API. Invalid controls also get a 3px halo around them, a shape change as well as a color change.
- Our choice: a field is an atom here, not a molecule, because a control is not usable without its label, hint and error. Larger compositions (forms, cards, headers) are molecules and organisms for later milestones.
Accessibility
<label for>names the control (WCAG 1.3.1, 3.3.2).- Hint and error ids go in the control's
aria-describedby. - On a wrong value, set
aria-invalid="true"and show the error as text (WCAG 3.3.1). - Native validation gets the same look through
:user-invalid, only after the user interacts.
Specifications
- WCAG 3.3.1
- WCAG 3.3.2
- WCAG 1.3.1
- MDN
aria-describedby - MDN
aria-invalid - MDN
:user-invalid - ui.shadcn.com input
- WCAG Use of color
See also
- Atoms
- Component API convention
- Accessibility baseline
- Source:
css/components/atoms/field.css,examples/atoms/field.html
How other systems do it
For comparison only; these are not the standard this system follows.
- Apple Human Interface Guidelines: No equivalent
- Material Design 3: No equivalent
- Vercel Geist: No equivalent