Patterns
Forms
How the form components work together. Each control has its own page; this page is about choosing between them and putting them in a form.
Which control to use
| The user needs to… | Use | Why |
|---|---|---|
| Type free text, a number, an email | Text field | The only control for open answers. |
| Pick one of five or more options | Select | Saves space; a native picker on phones. |
| Pick one of two to four options | Radio group | All options visible at a glance. |
| Turn one thing on or off, or pick several | Checkbox | Independent choices. |
| Filter or narrow a list | Chip | Instant and reversible. Not a form answer. |
| Submit the form | Button | One primary action at the end. |
Why
Each control tells the user what kind of answer is expected before they touch it: a box invites typing, a round dot says "only one", a square says "any number". Using the right shape is the cheapest usability win a form has.
How it is built
AtomsCheckbox, Radio, Chip, Button
MoleculesText field (label + input + hint), Select (label + control + hint)
PatternA form: molecules stacked with space-6 between, atoms for choices, one Button at the end
Layout
| Topic | Web | Mobile |
|---|---|---|
| Columns | One column for most forms, up to about 480px wide. Two columns only for short, related fields (first and last name). | Always one column, full width. |
| Space between fields | space-6 (24px) | space-6 (24px) |
| Space inside a group | space-2 between label, input and hint. | Same. |
| Submit button | At the end, left aligned with the fields, hugging its content. | Full width, at the end. |
| Label position | Above the field, never inside it as the only label. | Above the field. |
Validation and messages
Why
An error is only useful if the person can see it, understand it and fix it. So every error has an icon, the word that names the problem, and what to do, never red alone and never just "Invalid".
| Topic | Guidance |
|---|---|
| When to validate | When the person leaves the field (blur) or submits, not on every keystroke. Clear the error as soon as the value is fixed. |
| Hint vs error | A hint says what is expected before the mistake ("8 characters or more"). An error replaces the hint, in the same place, and says how to fix it. |
| Required fields | Say "(optional)" on the few optional fields instead of marking required ones with an asterisk. |
| Error summary | On submit, move focus to the first invalid field, and name the problem next to it. |
Accessibility
- Every control has a visible label, connected with
forandid(or by wrapping). A placeholder is never the label. - Errors are announced:
aria-invalid="true"andaria-describedbypointing to the message. - Groups have a name: radios and related checkboxes sit in a
<fieldset>with a<legend>. - Keyboard: the whole form can be completed with Tab, arrow keys, Space and Enter, in reading order.
- Target size: every control row is at least 44px tall.
Rules
| Rule | Reason |
|---|---|
| One primary action per form. | One clear next step. |
| Ask only for what you need. | Every field is a reason to leave. |
| Group related fields; separate groups with more space. | Spacing shows what belongs together. |
| Keep the user\'s input after an error. | Nobody wants to retype. |