Skip to main content

What are you looking for?

Try searching for…

Components

Button

Button allows users to perform actions.

Press Enter to start editing
Unable to parse html
const PreviewEn = () => {
  return <Button>My button</Button>;
};

render(<PreviewEn />)

Usage

The class name ds-button is set on <button>.

There are three data attributes you can use for customization:

  • data-icon - add if the button only has an icon.
  • data-variant - sets the variant of the button (primary, secondary, tertiary).
  • data-fullwidth - add if the button should be full width.

CSS variables and data attributes

Sizes are controlled with data-size and colors with data-color. The component will inherit the closest parent where these are set.

Data Attributes
NameValue
data-fullwidth
data-icon
data-variantsecondary, tertiary
CSS Variables
NameValue
--dsc-button-backgroundvar(--ds-color-base-default)
--dsc-button-background--activevar(--ds-color-base-active)
--dsc-button-background--hovervar(--ds-color-base-hover)
--dsc-button-border-colortransparent
--dsc-button-border-radiusvar(--ds-border-radius-default)
--dsc-button-border-stylesolid
--dsc-button-border-widthvar(--ds-border-width-default)
--dsc-button-colorvar(--ds-color-base-contrast-default)
--dsc-button-color--activevar(--dsc-button-color--hover)
--dsc-button-color--hovervar(--dsc-button-color)
--dsc-button-gapvar(--ds-size-2)
--dsc-button-paddingvar(--ds-size-2) var(--ds-size-4)
--dsc-button-sizevar(--ds-size-12)

Example

Variants

variant is used to change the appearance of the button.

Icon

If you only have an icon in the button, you can set data-icon="true" to make it square. If you have other content, such as text, the button will automatically get spacing around the icon.

Buttons that load

If you want a button that loads, you have to add a loading indicator and aria-busy="true" yourself.

Note: aria-busy does not prevent the button from triggering interactions. It only affects appearance and accessibility, not functionality. If the button should not be able to perform actions, you must add logic yourself to prevent the callback function from running.

Disabled buttons

As far as possible, you should avoid disabled buttons. If you have a <button>, you can disable it with the disabled attribute. If you have an <a>, you can disable it with the aria-disabled="true" attribute. Note: aria-disabled does not prevent the button from triggering interactions. It only affects appearance and accessibility, not functionality. If the button should not be able to perform actions, you must add logic yourself to prevent the callback function from running.

React

In React, we also set type="button" by default, to avoid unexpected submits in forms.

Button

variant
Description

Specify which variant to use

Type
"primary" | "secondary" | "tertiary"
Default
'primary'
icon
Description

Toggle icon only styling, pass icon as children When combined with loading, the loading-icon will be shown instead of the icon.

Type
boolean
Default
false
loading
Description

Toggle loading state. Pass an element if you want to display a custom loader.

Type
ReactNode
Default
false
asChild
Description

Change the default rendered element for the one passed as a child, merging their props and behavior.

Type
boolean
Default
false
type
Description

Specify the type of button. Unset when `asChild` is true

Type
"button" | "submit" | "reset"
Default
'button'
NameTypeDefaultDescription
variant"primary" | "secondary" | "tertiary"'primary'

Specify which variant to use

iconbooleanfalse

Toggle icon only styling, pass icon as children When combined with loading, the loading-icon will be shown instead of the icon.

loadingReactNodefalse

Toggle loading state. Pass an element if you want to display a custom loader.

asChildbooleanfalse

Change the default rendered element for the one passed as a child, merging their props and behavior.

type"button" | "submit" | "reset"'button'

Specify the type of button. Unset when `asChild` is true

Extra logic for buttons that load

In React, we use loading={true} to show that the button is loading something. Here you can also pass in your own loading component if our Spinner does not fit.

In the example above, aria-busy="true" is automatically set when loading={true}. This is the recommended way to show that a button is loading.

Links can be styled to look like a button, but consider whether the Link component is a better choice first. To change the button to a link, use asChild. Read more about composition in Designsystemet.

Edit this page on github.com (opens in a new tab)