Button
BetaActionsOpen in the workshop
The action a view exists for: save, create, launch, apply.
.xg-btn · variant --secondary --ghost --danger · size --sm --lg · --icon · --block. States: :hover :focus-visible :active :disabled, aria-busy="true".Example and markup
Live, from xg-ui.css and xg-ui.js. Switch the brand and mode on the example itself, or for the whole site in the header.
Markup
<div class="xg-row">
<button class="xg-btn" type="button">
<svg class="xg-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<path d="M12 5v14"/>
<path d="M5 12h14"/>
</svg>Create campaign</button>
<button class="xg-btn xg-btn--secondary" type="button">Cancel</button>
<button class="xg-btn xg-btn--ghost" type="button">Skip for now</button>
<button class="xg-btn xg-btn--danger" type="button">Delete</button>
</div>States
Hover, focus and pressed are forced here with .is-hover, .is-focus and .is-active so they can be seen side by side; in a product they come from :hover, :focus-visible and :active.
| State | Primary | Secondary | Ghost | Danger |
|---|---|---|---|---|
| Default | ||||
| Hover | ||||
| Pressed | ||||
| Focus | ||||
| Disabled | ||||
| Busy |
Variants
Markup
<div class="xg-row">
<button class="xg-btn xg-btn--sm" type="button">Small · 32</button>
<button class="xg-btn" type="button">Medium · 40</button>
<button class="xg-btn xg-btn--lg" type="button">Large · 48</button>
</div>When to use it
Use it for
the one action a view exists for: Save, Create campaign, Apply filters, Launch.
Not for
navigation (use Link); on/off (use Switch or Segmented control); two primary buttons in one view.
Rules
- One primary button per view or dialog. Everything else is secondary or ghost.
- Labels are a verb first, sentence case, no ending period: “Create campaign”, not “CREATE” or “New”.
- The primary action sits last (right) in a button row; Cancel is secondary and sits before it.
- Danger is for destructive, irreversible actions only, and always comes through a confirmation (Alert dialog).
- Disabled buttons explain themselves nearby (a hint or tooltip). When an action is only “not ready yet”, prefer an enabled button that validates on click.
- While an action runs, keep the button width, show a spinner and set aria-busy="true"; never swap the label for “Loading…”.
Accessibility
- Native <button> (or <a> for links styled as buttons). Focus ring: 2 px, focus-ring token, 3:1 on every surface.
- Label contrast: white on primary fill passes 4.5:1 in both brands and modes (see Accessibility).
- Icon-only buttons need aria-label.
Every color pair this component uses is measured for both brands in light and dark on the Accessibility page.
Related
Also in Actions: Icon button, Button group, Link. Used in the patterns Onboarding and sign-up, Loading, empty and error states.
Status Beta: usable; class names may still change in a minor release, with a note (see Releasing).