Live demo
Demo source
Use a button for an action on the current page, such as saving, sending or opening a dialog.
Anatomy
A button labelled Button, with a people icon before the label and an arrow after it. Callouts 1, 2 and 3 mark the leading icon, label and trailing icon.
- Leading icon (optional) reinforces the action.
- Label names the action.
- Trailing icon (optional) shows direction or outcome.
States and themes
Buttons provide default, hover, keyboard-focus, pressed and disabled styles in
Spark and Ocean. Keep a visible focus indicator so keyboard users can locate
the current action. The active prop represents a lasting active selection
or current page; the pressed style appears during activation.
The design state list includes read-only, but nv-button has no read-only
prop. Use disabled when the action is unavailable and explain why nearby.
Emphasis and size
Four emphasis levels, high, medium, low and lower, set the hierarchy
between actions. Give the main action the most emphasis, and avoid placing
high-emphasis buttons next to each other. Mark actions that cannot be undone,
such as deleting, with danger; it works with every emphasis level.
Sizes xs, sm, md (default) and lg match the density of the layout and
the touch target you need.
Loading and disabled
Set loading while an action runs: a spinner appears and the button is
disabled until it finishes. Disable an action that is unavailable, and explain
why next to it. Buttons have no read-only state.
Icons and accessibility
Use the leading-icon and trailing-icon slots for symbols that reinforce
the label. The label should still explain the action without the icons. Mark
purely decorative icons with aria-hidden="true".
Enter and Space activate a focused button. Use type="submit" for submitting
a form; the default type="button" performs an ordinary action. Danger is a
separate danger flag that works with all four emphasis levels, rather than
an emphasis="danger" value.