Stable
A field wraps every form control: the label, an optional hint, an error message when the answer is wrong, and the control itself. Using it everywhere keeps forms evenly spaced and makes errors look the same on every screen.
Show errors after the manager tries to save, not while they are still typing.
In pounds, before VAT.
Enter a price, like 12.50
Specifications
Anatomy
In pounds, before VAT.
Enter a price, like 12.50
Anatomy
In pounds, before VAT.
Enter a price, like 12.50
Size and spacing
Field
Label and control. Add a hint only when it helps.
Example
Example
Field with hint
A hint between the label and the control explains format or limits. Link it with aria-describedby.
Example
In pounds, before VAT.
Example
In pounds, before VAT.
Field with error
Add .at-field--error and an .at-error message above the control. Set aria-invalid="true" and add the error id to aria-describedby.
Example
Enter an email address, like name@example.com
Example
Enter an email address, like name@example.com
Usage
When to use
- Around every text input, textarea, select and date input.
When not to use
- Checkboxes and radios: use a fieldset with a legend instead.
Content
- Error messages say how to fix it: "Enter a price, like 12.50", not "Invalid".
- Hints describe format or limits; they do not repeat the label.
- If a form has several errors, also show an error alert at the top.
Do and don't
Enter a price, like 12.50
Invalid input
Do
- Say how to fix it: "Enter a price, like 12.50".
Don't
- Show errors before the user has submitted.
- Only colour the border: always show the message.
Implementation
HTML
<div class="at-field at-field--error">
<label class="at-label" for="amount">Monthly price</label>
<p class="at-hint" id="amount-hint">In pounds, before VAT.</p>
<p class="at-error" id="amount-error">Enter a price, like 12.50</p>
<input class="at-input" id="amount" type="text" inputmode="decimal" aria-describedby="amount-hint amount-error" aria-invalid="true" />
</div>Classes
| Class | What it does |
|---|---|
at-field | Wrapper |
at-field--error | Error state: red, thicker border |
at-label | Label |
at-hint | Help text |
at-error | Error message |
Tokens used
--at-text-subtle, --at-text-danger
Accessibility
- Point aria-describedby at the hint and error; set aria-invalid="true" on error.
Related
Text input
A single line of text, with its label above.
View componentTextarea
Several lines of text.
View componentSelect
Choose one option from a list of more than about five.
View componentInline alert
A message about the whole page or a section: information, success, a warning or an error.
View component