Components · Actions

Button

A button triggers an action or takes the user to another page. It lets the user make a choice with a single tap. Use a mix of styles on one page to point at the main action and still offer the alternatives.

How to add a button to a page. The file is components/css/button.css.

Basic Usage

Link the shared stylesheet once per page. Never copy the rules into a page, and never write a parallel version.

StepWhat to do
1. Link<link rel="stylesheet" href="/components/css/button.css">. Both templates already have it. The icons need the Material Symbols Outlined font, as in the templates.
2. MarkupA button.btn (or a.btn) with a variant and a size class, and the label in span.btn__label.
3. Variant and sizebtn--primary, btn--secondary, … and btn--lg, btn--md, btn--sm or btn--xs. The size switches at 769px by itself.
4. Focus ringAdd the small script once per page: it sets body.keyboard-nav on Tab.
5. Next to a fieldUse the matching size: Input Large with Medium, Small with Small, XSmall with XSmall.

Button

Copy the markup you need. Hover and focus come from :hover and the keyboard focus rule; the [data-state] selectors in the CSS exist only so the documentation can force a state.


Icon button


API

Classes

ClassUse
btnThe button. Needs a variant and a size.
btn--primary | primary-inverted | secondary | secondary-inverted | blank | blank-inverted | destructive | accent | systemVariant.
btn--lg | md | sm | xsSize.
btn--iconIcon only: a square. Needs aria-label.
btn__label, btn__icon, btn__badge, btn__dotParts of a button.
icon-btn, icon-btn--sm, icon-btn--filled, icon-btn--close, icon-btn--close-invertedThe icon button.

Things to know

  • Always wrap the label in span.btn__label, also for buttons built in JS (innerHTML, and set the text on the span, never button.textContent).
  • Breakpoint: the sizes switch at 769px; 640–768px is still mobile.
  • Cap the badge count in your code: n > 99 ? '99+' : n.
  • Never :focus-visible for buttons: use body.keyboard-nav.
  • Old prototype pages have their own .btn-primary and .btn-blank classes. New work uses the classes above.
  • The [data-state] selectors do nothing outside the documentation pages.

CSS / Tailwind

The component is one CSS file, shared by every page. Link it, never copy it. The CSS below is read from the file the page links, so it is always what you see.

CSS (components/css/button.css, button and icon button)

Focus ring script