A <button> inside .rd needs no class: it gets the default look, as a form field does, and so does an <input> of type submit, button or reset. .button gives the same look to a link or any other element. Variants, sizes and layouts are classes on top. A button is inline, so buttons placed side by side share a line, and it is as wide as its label, in a card, a panel or a form group too.
<button type="button">Button element</button>
<a class="button" href="/styles/interactive/">Link as a button</a>
The default is a light grey control (--gray-lightest, its label --gray-dark) with rounded corners (--space-lg) and a light frame; under the pointer it turns white with a black frame and label, and grey while pressed. Its label stays dark on a dark surface such as .card-inverted, on a button and on a link alike: the card's link colour is for text links.
Until v0.7.2 a bare button was a block-level grey pill; it is inline now. To give one a line of its own, put it in a block (a <p>, a <div>), or take the full width with .button-block. The .block utility works on a <button> but not on a.button: .button comes after the utilities in the stylesheet and has the same weight.
Variants
.button-primary- The one action that matters on the screen, in the brand colour:
--brand-color,--brand-color-deepunder the pointer and darker still while pressed. The label is black (--primary-color) at rest, about 15:1 on the brand green, and turns white on the dark fills: under the pointer, while pressed, and on a pressed toggle in a group. A pressed toggle on its own keeps the brand fill and the black label. A project that re-maps--brand-colorsets--brand-color-deeptoo, to a shade that carries white text at 4.5:1 or more; otherwise the button turns the library green under the pointer. .button-ghost- No frame until the pointer is on it. For toolbars and secondary actions in a row. Its label is the text colour of the surface it sits on (
--primary-text-color) and its hover tint a share of that colour, so it reads on a light page and on.card-invertedalike. .button-danger- A destructive action, on
--dangershaded by 15%, so the white label reads at 5.3:1. .button-link- Reads as a text link: the link's underline, and under the pointer its fill rising behind the label. It keeps the button's box, so it lines up with the buttons next to it.
<button class="button-primary" type="submit">Save</button>
<a class="button button-ghost" href="…">Details</a>
On a link, a variant needs .button next to it; on a <button> it does not.
On a dark surface
The filled variants keep their colours. The ghost and link variants have no fill, so their labels take the text and link colours of the surface.
Sizes
.button-md is the default, named so it can be restored inside a container that sets another size. A size sets --button-padding-x, --button-padding-y and --button-font-size; at the default size a button is as tall as a text field.
<button class="button-sm" type="button">Small</button>
<button class="button-lg button-primary" type="button">Large</button>
Icons
An rd-icon-* glyph before or after the label sits at an even gap from it, whatever whitespace the markup has, and the button stays on the text line like one without a glyph. .button-icon is a square for a glyph alone: as tall as a text button of the same size. Give it a name with aria-label.
<button type="button"><span class="rd-icon-download"></span> Download</button>
<button type="button">Next <span class="rd-icon-arrow_forward"></span></button>
<button class="button-icon" type="button" aria-label="Settings">
<span class="rd-icon-settings"></span>
</button>
States
- Hover, pressed
- Each variant darkens its frame or its fill. The change is a 0.15s colour fade; nothing moves.
.button-linkraises its link fill instead, as a text link does, in 0.23s. With reduced motion it is instant. - Keyboard focus
- The library's focus ring, in
--signal. disabled- Faded in every variant, with the default pointer.
aria-disabled="true"looks the same and keeps the button focusable, so it can still explain why it is off. A link has nodisabled: give itaria-disabled="true"and remove itshref. aria-busy="true"- The label hides, so the button keeps its width, and a ring in the label colour turns in its place. With reduced motion the ring stands still. The script that sets the attribute also ignores clicks while it is set. The ring needs a
<button>or a.buttonlink: an<input>cannot draw it.
<button class="button-primary" type="submit" aria-busy="true">Save</button>
Group
.button-group joins buttons into one segmented row: neighbours share a border, and only the outer corners are rounded. A pressed toggle (aria-pressed="true") keeps the pressed look of its variant: grey under a black frame for the default, the darkest fill for a primary. The hovered or focused button is lifted, so its whole frame and the focus ring show.
<div class="button-group" role="group" aria-label="Period">
<button type="button" aria-pressed="false">Day</button>
<button type="button" aria-pressed="true">Week</button>
<button type="button" aria-pressed="false">Month</button>
</div>
Full width
.button-block takes the full width of its container, for a phone layout or a narrow column. A glyph and its label stay centred together.
<button class="button-block button-primary" type="button">Download the report</button>
Re-colouring a button
Buttons have no tokens of their own: the look is written with the library's spacing, type and colour tokens, and the corners are --space-lg. A variant re-colours a button through six slots on its class. The default look reads them, each with the default as its fallback:
| At rest | Under the pointer | |
|---|---|---|
| Fill | --button-bg (--gray-lightest) | --button-bg-hover (the --button-bg a variant sets, else --white) |
| Label | --button-text (--gray-dark) | --button-text (--primary-color) |
| Frame | --button-border-color (--border-color) | --button-border-color-hover (--primary-color) |
While pressed the fill is --button-bg-active (--bg-color); the label and the frame stay as under the pointer. Set the slots on a class or an element for a colour the library does not ship:
.button-signal {
--button-bg: var(--signal);
--button-text: var(--white);
--button-border-color: transparent;
--button-bg-hover: var(--blue-dark);
--button-border-color-hover: transparent;
}
The sizes work the same way: --button-padding-x (--space-md), --button-padding-y (--field-padding-y) and --button-font-size (--font-size-md). So a default button stays as tall as a field when a project changes the field's padding. The label sits 1px below the centre: 9px above and 7px below at the default.
A component's own buttons
The element defaults have type weight in every state, so one class overrides them, hover and press included. A text-like toggle drops the chrome with a single rule and keeps the focus ring:
.my-toggle {
padding: 0;
border: 0;
background: none;
color: inherit;
font: inherit;
}
A RareCharts card (.rc-chart) draws its own buttons, so the element defaults stop at it. A button the page places inside a chart's controls row takes the library look only when it asks for it with .button.