Skip to main content
Login

Sign in to access your account

Button - National Design System

A button runs an action, such as save, submit or open a menu

Overview

A button is a <button> or an <a> with the nds-btn class, a variant class and a label. Add an icon before or after the label, or show the icon only. The variant sets the emphasis, from primary for the main action to transparent for the least. Size and shape are more classes, and a state is an attribute, such as disabled. A button needs no JavaScript.

A button can also open a Dropmenu or copy text with Copy.

Pick another component when:

Markup

Options
Structure
Variant
Size
Content
Built-in icon
State
Ring
Direction
More
Preview
<button type="button" class="nds-btn nds-primary"> <span class="nds-label">Add item</span> </button>

Built-in Features

  • Pure CSS

    No JavaScript needed. Every variant, size and state comes from classes and attributes.

  • Six Variants

    Primary, neutral, secondary, secondary outline, subtle and transparent, each with its hover, pressed, selected, focused and disabled look.

  • Three Sizes

    24px, 32px and 40px high. The label, the icon and the indicator scale with the size.

  • Layout Options

    An icon before or after the label, icon only, label only, stacked, circle and full width, and a loading state.

  • Accessibility

    A focus ring for keyboard users, thicker borders in high contrast mode, no motion when the user asks for reduced motion, and plain print styles.

  • Composable

    Combines with destructive, on color, loading, progress, status, badge, indicator and groups.

Best Practices

  • Use a <button> for an action on the page, and an <a class="nds-btn"> when the click opens another page. The classes are the same.
  • Use a button group for a short row of related actions.
  • Use one primary button per view, for the main action. Use neutral, secondary or secondary outline for the actions beside it, and subtle or transparent for cancel and dismiss.
  • Use destructive for delete and other actions that cannot be undone. Ask the user to confirm in a Modal first.
  • Add nds-oncolor to a button on a deep primary or dark background. Without it, the button can be hard to see.
  • Write type="submit" on the button that sends a form. Write type="button" on every other button in a form, or it sends the form too.
  • Keep the nds-label span on an icon-only button. It is hidden on screen and names the button for screen readers. A button with no label element needs an aria-label.
  • Add nds-loading and disabled while a request runs, so a second press does not send it again. A form.nds-form does this for its submit button: see Text Fields, Submit Validation.
  • Keep labels short: a verb and a noun, such as “Save draft”. A long label does not wrap, except in a stacked button.
  • Use a status for feedback on the button itself, and remove it after about two seconds. For a message the user must read, use an Alert.

API

Other Classes

Class Element Effect
nds-trail-icon .nds-btn Puts the icon after the label, with the icon first in the markup
nds-lead-icon .nds-btn Puts the icon before the label. Use it to undo a reversed order, such as the one nds-prev sets
nds-label-only .nds-btn, or any parent Hides every icon inside, so the same markup shows labels only

Data Attributes

Attribute Element Effect
data-state .nds-btn selected, open, active or current gives the selected look. open and opening also turn the menu chevron. loading is the same as nds-loading, and disabled the same as the disabled attribute. hover, pressed and focused show that look without a pointer or a keyboard, for a design review
data-status .nds-btn Feedback for a moment after an action: success, error, info or warning. It sets the colors in every state, swaps each nds-icon icon for the status icon, and colors the border of a secondary outline button. Copy, Share and the accessibility panel set success for about two seconds. Set it for your own actions with NDS.status, as in the example below. Do not write it in the markup
aria-expanded .nds-menu-btn true turns the chevron, the same as data-state~="open"
aria-disabled .nds-btn true gives the disabled look and blocks clicks. Use it on an <a>, which has no disabled attribute

CSS Custom Properties

Set these on the button itself. There, a size property wins over the size classes. A --btn-size, --btn-gap or --btn-indicator-size set on a parent does not reach a button, because buttons sit inside other components. The variant classes set the colors on the button, so a color set on a parent does not reach it either.

Property Default Controls
--btn-size 40px Height, and the width of an icon-only button. The label and icon sizes follow it. nds-md and nds-sm set 32px and 24px
--btn-height var(--btn-size) Height alone, without the label and icon sizes
--btn-height-min fit-content Minimum height
--btn-width fit-content Width
--btn-padding (size - 8px) / 2 Padding on the start and end sides
--btn-gap var(--spacing-md) Space between the icon and the label. nds-md sets var(--spacing-sm), nds-sm sets var(--spacing-xs)
--btn-radius var(--radius-sm) Corner radius
--btn-FS, --btn-LH from --btn-size Label font size and line height
--btn-icon-size size / 2 + 4px, size / 2 + 2px on a progress button Icon size
--btn-bg, --btn-bg-hover, --btn-bg-active, --btn-bg-selected, --btn-bg-disabled set by the variant Background in each state
--btn-color, --btn-color-hover, --btn-color-disabled set by the variant Text and icon color
--btn-border, --btn-border-hover, --btn-border-active, --btn-border-selected, --btn-border-disabled set by the variant Border color in each state
--btn-indicator-size 3px, 2px on SM Height of the indicator bar
--btn-loading-color, --btn-loading-track set by the variant Spinner colors
--btn-group-radius var(--radius-md) Corner radius of a group, the same at every button size
--progress-duration 4000ms Time the ring takes to fill
--progress-value 0 Fill of a nds-progress-static ring, from 0 to 100
--progress-size size - 8px Size of the ring
--progress-circumference 62.83 Length of the ring for a fixed value. It matches stroke-dasharray on the circle: change it only with the circle’s radius

Tokens

Set a token at :root, or on a wrapper to reach every button inside it. Give a token with a Dark mode value a dark override too: see Tokens.

Source: the button group in _sass/tokens/_components.scss.

TokenPreviewValue
--button-background-neutral-defaultvar(--colors-neutral-950)
--button-background-neutral-hovered
var(--colors-neutral-800)
Dark mode var(--colors-neutral-900)
--button-background-neutral-pressedvar(--colors-neutral-600)
--button-background-neutral-selectedvar(--colors-neutral-700)
--button-background-primary-defaultvar(--colors-primary-600)
--button-background-primary-hoveredvar(--colors-primary-700)
--button-background-primary-pressedvar(--colors-primary-900)
--button-background-primary-selectedvar(--colors-primary-800)
--button-background-secondary-default
var(--colors-neutral-100)
Dark mode var(--colors-neutral-700)
--button-background-secondary-hovered
var(--colors-neutral-100)
Dark mode var(--colors-neutral-700)
--button-background-secondary-pressed
var(--colors-neutral-200)
Dark mode var(--colors-neutral-600)
--button-background-secondary-selected
var(--colors-neutral-200)
Dark mode var(--colors-neutral-600)
--button-background-danger-primary-defaultvar(--colors-red-600)
--button-background-danger-primary-hoveredvar(--colors-red-700)
--button-background-danger-primary-pressedvar(--colors-red-900)
--button-background-danger-primary-selectedvar(--colors-red-800)
--button-label-danger-oncolor-defaultvar(--colors-red-200)
--button-label-danger-oncolor-hoveredvar(--colors-red-300)
--button-label-danger-oncolor-pressedvar(--colors-red-400)
--button-label-danger-oncolor-selectedvar(--colors-red-300)
--button-background-danger-secondary-default
var(--colors-red-50)
Dark mode var(--colors-red-alpha-10)
--button-background-danger-secondary-hovered
var(--colors-red-100)
Dark mode var(--colors-red-alpha-20)
--button-background-danger-secondary-pressed
var(--colors-red-200)
Dark mode var(--colors-red-950)
--button-background-danger-secondary-selected
var(--colors-red-100)
Dark mode var(--colors-red-alpha-20)
--button-label-danger-secondary-default
var(--colors-red-700)
Dark mode var(--colors-red-300)
--button-label-danger-transparent-default
var(--colors-red-600)
Dark mode var(--colors-red-300)
--button-label-danger-transparent-hovered
var(--colors-red-700)
Dark mode var(--colors-red-400)
--button-label-danger-transparent-pressed
var(--colors-red-900)
Dark mode var(--colors-red-500)
--button-label-danger-transparent-selected
var(--colors-red-800)
Dark mode var(--colors-red-400)
--button-background-danger-secondary-oncolor-defaultvar(--colors-red-50)
--button-background-danger-secondary-oncolor-hoveredvar(--colors-red-100)
--button-background-danger-secondary-oncolor-pressedvar(--colors-red-200)
--button-background-danger-secondary-oncolor-selectedvar(--colors-red-100)
--button-label-danger-secondary-oncolor-defaultvar(--colors-red-600)
--button-label-danger-secondary-oncolor-hoveredvar(--colors-red-700)
--button-label-danger-secondary-oncolor-pressedvar(--colors-red-900)
--button-label-danger-secondary-oncolor-selectedvar(--colors-red-800)
--button-border-danger-oncolorvar(--colors-red-200)
--button-background-oncolor-defaultvar(--colors-base-white)
--button-background-oncolor-hoveredvar(--colors-alpha-white-80)
--button-background-oncolor-pressedvar(--colors-alpha-white-60)
--button-background-oncolor-selectedvar(--colors-alpha-white-70)
--button-background-oncolor-disabledvar(--colors-alpha-white-20)
--button-background-transparent-defaultvar(--colors-alpha-white-0)
--button-background-transparent-hoveredvar(--colors-alpha-white-20)
--button-background-transparent-pressedvar(--colors-alpha-white-40)
--button-background-transparent-selectedvar(--colors-alpha-white-30)
--button-label-transparent-oncolor-defaultvar(--text-oncolor-primary)
--button-label-transparent-oncolor-hoveredvar(--colors-primary-400)
--button-label-transparent-oncolor-pressedvar(--colors-primary-300)
--button-label-transparent-oncolor-selectedvar(--colors-primary-400)
--button-indicator-defaultvar(--colors-neutral-400)
--button-indicator-pressed
var(--colors-neutral-800)
Dark mode var(--background-surface-oncolor)
--button-indicator-selected
var(--colors-neutral-800)
Dark mode var(--background-surface-oncolor)
--button-indicator-primaryvar(--colors-primary-400)
--button-indicator-mark
var(--background-primary)
Dark mode var(--colors-primary-500)
--button-indicator-oncolor-defaultvar(--colors-alpha-white-40)
--button-indicator-oncolor-pressedvar(--colors-base-white)
--button-indicator-oncolor-selectedvar(--colors-base-white)
--button-status-success-bg
var(--background-success-light)
Dark mode var(--colors-green-alpha-10)
--button-status-success-text
var(--text-success)
Dark mode var(--colors-green-400)
--button-status-error-bg
var(--background-error-light)
Dark mode var(--colors-red-alpha-10)
--button-status-error-text
var(--text-error)
Dark mode var(--colors-red-400)
--button-status-info-bg
var(--background-info-light)
Dark mode var(--colors-blue-alpha-10)
--button-status-info-text
var(--text-info)
Dark mode var(--colors-blue-400)
--button-status-warning-bg
var(--background-warning-light)
Dark mode var(--colors-yellow-alpha-10)
--button-status-warning-text
var(--text-warning)
Dark mode var(--colors-yellow-400)
--button-border-danger
var(--colors-red-200)
Dark mode var(--colors-red-300)
--button-border-error
var(--border-error-light)
Dark mode var(--colors-red-400)
--button-border-success
var(--border-success-light)
Dark mode var(--colors-green-400)
--button-border-warning
var(--border-warning-light)
Dark mode var(--colors-yellow-400)
--button-border-info
var(--border-info-light)
Dark mode var(--colors-blue-400)

It also reads these shared tokens. A change to one also changes other components.

Source: the var() reads in _sass/components/_buttons.scss.

TokenPreviewValue
--background-primary
Read by --btn-loading-color
var(--colors-primary-600)
--background-error
Read by background-color
var(--colors-red-600)
--background-disabled
Read by --btn-bg-disabled

var(--colors-neutral-200)
Dark mode var(--colors-neutral-700)
--text-default
Read by --btn-color, --btn-loading-color, --btn-color-hover

var(--colors-base-black)
Dark mode var(--colors-neutral-200)
--text-oncolor-primary
Read by --btn-color, --btn-loading-color, color
var(--colors-base-white)
--text-default-disabled
Read by --btn-color-disabled
var(--colors-neutral-400)
--text-default-oncolor-disabled
Read by --btn-color-disabled
var(--colors-alpha-white-40)
--border-oncolor
Read by --btn-border, --btn-border-hover, --btn-border-active, --btn-border-selected
var(--colors-alpha-white-40)
--border-neutral-primary
Read by --btn-border, --btn-border-active, --btn-border-selected

var(--colors-neutral-300)
Dark mode var(--colors-neutral-600)
--border-neutral-secondary
Read by --btn-border-hover, --btn-border-disabled

var(--colors-neutral-200)
Dark mode var(--colors-neutral-700)
--divider-color
Read by border-inline-start-color, border-block-start-color

var(--colors-alpha-black-10)
Dark mode var(--colors-alpha-white-10)

JavaScript

A button has no script of its own. Set its state with NDS.state and its status with NDS.status.

var btn = document.querySelector('#save'); // Lock the button while the request runs NDS.state.add(btn, 'loading'); btn.disabled = true; save().then(function () { // Show success for two seconds NDS.status.set(btn, 'success'); setTimeout(function () { NDS.status.clear(btn); }, 2000); }).finally(function () { NDS.state.remove(btn, 'loading'); btn.disabled = false; });
Last Modified Date: 20/11/2026 - 04:28 PM
Was this page useful?
60% of users said Yes from 2843 Feedbacks