Sub topic 8
Documenting component states
This chapter assumes you can build components in a design tool such as Figma and read basic CSS. It also assumes you have already named your values as design tokens, as covered in the earlier chapter on tokens. A component state is one way a component looks and behaves under a given condition. A developer needs every state spelled out, because a missing state gets guessed.
Why states need their own documentation
A static mockup shows a button at rest. Real users hover over it, tab to it, click it, and sometimes cannot use it at all. If the file shows only the resting look, the developer fills the gaps with personal judgment. The result is inconsistent and often fails accessibility checks.
Document these states for each interactive component:
| State | When it appears | What to specify |
|---|---|---|
| Default | Resting, no interaction | Base tokens for color, space, radius |
| Hover | Pointer is over the component | Changed background or border |
| Focus | Reached by keyboard | Visible outline, its offset and color |
| Active | Pointer or key is pressed | Pressed color or small shift |
| Disabled | Action is unavailable | Muted color, cursor, no hover |
| Loading | Waiting on a response | Spinner, label, whether clicks are blocked |
| Error | Input or action failed | Error color, message text and position |
| Empty | No data to show | Message, illustration, next action |
Not every component needs every state. A static card has no focus state. A text field needs almost all of them. Mark the states that do not apply, so the developer knows you considered them.
Show states as a matrix
Place all states of one component side by side in a single frame. Label each one with the state name. Use your tool's variants feature so the states are properties of one component and not separate drawings. This makes missing states visible at a glance, since an empty cell in the grid is an obvious gap.
A diagram like this answers questions the visuals cannot, such as which states can follow which.
Map each state to tokens
Describe every state by token names, not raw values. Hover uses color.brand.primary-hover, not #174aa6. Then the spec and the code share one vocabulary, and a later color change happens in one place.
Each documented state maps to one CSS selector. This is the CSS a developer would write for the button:
.button:hover {
background: var(--color-brand-primary-hover);
}
.button:focus-visible {
outline: 2px solid var(--color-brand-primary);
outline-offset: 2px;
}
.button:disabled {
background: transparent;
color: var(--color-text-disabled);
cursor: not-allowed;
}Checking your spec against this list is a quick test. If you documented hover, focus, and disabled, you should be able to point to a selector for each.
Common errors
- Hover only. Touch devices have no hover, and keyboard users never trigger it. Always pair a hover design with a focus design.
- Removing the focus outline. A default browser outline can be restyled, but it must stay visible. Specify the replacement.
- Disabled that looks like default. If the disabled state differs only slightly, users cannot tell the control is off. Use a clear change, and check contrast for text that must still be readable.
- Forgetting data states. Loading, error, and empty states are easy to skip because they are not part of the happy path. Lists, tables, and forms need all three.
- Unspecified transitions. If a state change should animate, note the duration and easing, or state that it should be instant.
Writing the annotation
For each state, write a short note beside it. Name the trigger, the tokens, and any behavior that is not visible. For a loading button: "On click, replace the label with a spinner, keep the button width fixed, and ignore further clicks until the request ends."
Exercise
A designer hands off a text input that shows only a default and a hover design. List four more states to document, and give one detail to specify for each.
Show answer
Any four of these. Focus: a visible outline with its color and offset. Disabled: muted text and background tokens, and a not-allowed cursor. Error: error border color and the message text and position. Loading: a spinner placement and whether typing is blocked. Empty or placeholder: placeholder text color and wording.