Alert
A message that stays on the page with the content it is about.
In Accessible first
See it live
npm run storybookWhen to use it
In Accessible first: Errors and important notes that stay on the page.
- Use it when: People need to read a standing notice or how to recover, on this page, tied to what they are doing.
- Not when: A short confirmation that can go away by itself, or one notice for the whole site.
Instead:
- Toast: Short, non-blocking, goes away.
- Dialog: Needs an answer before going on.
- Site banner: One full-width notice for the whole site.
Variants
What each variant is for in any design system, then what Accessible first decided and why. Each sample is the live story with that variant set.
defaultvariantUsed in Accessible firstWhat it is for
A notice that stays on the page: information or a heads-up.
In Accessible first
Important notes that stay on the page while people answer.
destructivevariantUsed in Accessible firstWhat it is for
Something failed or will be lost, and people must act to recover.
In Accessible first
Errors, with what went wrong, where, and exactly how to fix it, next to the field.
How Accessible first uses it
Why it works this way
Alert looks the way it does because of 5 answers about this product. Each card is one answer, in three steps: the answer, what it decided for Alert, and what would move if it changed.
outcomes.q11The answer
Completion without errors is the measure.
2So Alert
- ✓uses default: Important notes that stay on the page while people answer.
Badge: success3If it changed
and 2 answers that follow from it: Links and actions, Form steps and errors.
human.q11The answer
Low effort to understand each step.
2So Alert
- ✓uses default: Important notes that stay on the page while people answer.
Empty: default3If it changed
and 15 answers that follow from it: Calm and clear, Quiet, Core: heading, body, label, and 12 more.
accessibility.count1The answer
Never color alone.
2So Alert
- ✓uses destructive: Errors, with what went wrong, where, and exactly how to fix it, next to the field.
Badge: neutral Badge: success Badge: warning Badge: danger Item: muted3If it changed
and 1 answer that follow from it: Status and messages.
outcomes.q21The answer
A failed form can cost someone a benefit.
2So Alert
- ✓uses destructive: Errors, with what went wrong, where, and exactly how to fix it, next to the field.
Button: secondary Button: danger Badge: warning Badge: danger3If it changed
No other answer follows from it.
voice.values1The answer
Every sentence is easy to read on the first try.
2So Alert
- ✓uses destructive: Errors, with what went wrong, where, and exactly how to fix it, next to the field.
Empty: icon3If it changed
No other answer follows from it.
Words
- Use common words. Explain any term you must use.
- One idea per sentence. Put the action first.
- Never blame the person.
- Use: Continue, Change, Start, You. Avoid: Invalid, Utilise, Submit, Error code.
The labels components use, from the voice tokens:
content.action.commit: Continuecontent.action.cancel: Go backcontent.action.destroy: Deletecontent.action.retry: Try againcontent.action.empty-action: Start a new application
See Voice and tone for the whole voice.
Accessibility and keyboard
Test before you ship:
- An error that appears after an action is announced (role alert); a standing note is not. undefined
- The tone also shows as an icon and words, never color alone. undefined
Use it in code
npx open-ds add alert
The component reads only component keys and semantic tokens, so it follows the brand and mode on <html>.
Tokens it reads
Alert reads 15 tokens of its own, each an alias of a semantic token. Each row is one part: its own token, the semantic it aliases, and the value it ends at. Change a semantic and every component that reads it follows; override one of Alert's tokens to change Alert alone.
Accessible first decides what changes when you switch theme. Here a switch changes colors only, so the marked rows differ between light and dark; everything else holds steady.
| Part | Its token and the semantic it aliases | Value |
|---|---|---|
| Alert | ||
| Gap y | component.alert.gap-ycomponent-spacing-map.hairlinevar(--alert-gap-y) | space.2:0.125rem |
| Corner | component.alert.radiusradius.containervar(--alert-radius) | radius.8:0.5rem |
| Padding, left and right | component.alert.padding-xspace.inset.containervar(--alert-padding-x) | space.24:1.5rem |
| Padding, top and bottom | component.alert.padding-ycomponent-spacing-map.x3var(--alert-padding-y) | space.20:1.25rem |
| Text size | component.alert.font-sizetype.body.font-sizevar(--alert-font-size) | font.size.19:1.1875rem |
| Gap x | component.alert.gap-xcomponent-spacing-map.x3var(--alert-gap-x) | space.20:1.25rem |
| Icon size | component.alert.icon-sizesize.iconvar(--alert-icon-size) | size.20:1.25rem |
| Default | ||
| Fill Changes with theme | component.alert.default.backgroundcolor.surface.defaultvar(--alert-default-background) | Lightgray.light.0:#FFFFFFDarkgray.dark.50:#141414 |
| Text Changes with theme | component.alert.default.labelcolor.text.primaryvar(--alert-default-label) | Lightgray.light.900:#141414Darkgray.dark.900:#F7F7F7 |
| Destructive | ||
| Fill Changes with theme | component.alert.destructive.backgroundcolor.surface.defaultvar(--alert-destructive-background) | Lightgray.light.0:#FFFFFFDarkgray.dark.50:#141414 |
| Text Changes with theme | component.alert.destructive.labelcolor.status.dangervar(--alert-destructive-label) | Lightred.light.600:#C42B2BDarkred.dark.600:#F28B8B |
| Title | ||
| Weight | component.alert.title.font-weighttype.label.font-weightvar(--alert-title-font-weight) | font.weight.700:700 |
| Description | ||
| Gap | component.alert.description.gapspace.gap.tightvar(--alert-description-gap) | space.12:0.75rem |
| Text size | component.alert.description.font-sizetype.body.font-sizevar(--alert-description-font-size) | font.size.19:1.1875rem |
| Text Changes with theme | component.alert.description.labelcolor.text.mutedvar(--alert-description-label) | Lightgray.light.500:#595959Darkgray.dark.500:#949494 |
| From the system | ||
| Edge Changes with theme | color.border.default straight from the system, through --border | Lightgray.light.200 · #D6D6D6Darkgray.dark.100 · #222222 |