Toggle button

Toggle button is a custom element that allows users to toggle between two states.

Examples Default tooltip

To make the button acitve use the active attribute. With a native button you can use the aria-pressed attribute also.

<dap-ds-stack direction="row">
  <dap-ds-toggle-button>
    Toggle me
  </dap-ds-toggle-button>
  <dap-ds-toggle-button active>
    Toggle me
  </dap-ds-toggle-button>

  <button
    class="dds-toggle-button dds-toggle-button--md dds-toggle-button--active"
    aria-pressed="true">
    Native toggle
  </button>

</dap-ds-stack>
Size
<dap-ds-stack direction="row">
  <dap-ds-toggle-button size="xs">
    Toggle me
  </dap-ds-toggle-button>
  <dap-ds-toggle-button size="sm">
    Toggle me
  </dap-ds-toggle-button>
  <dap-ds-toggle-button>
    Toggle me
  </dap-ds-toggle-button>
  <dap-ds-toggle-button size="lg">
    Toggle me
  </dap-ds-toggle-button>
</dap-ds-stack>
Shape

You can change the shape of the toggle button by using the shape attribute.

<dap-ds-stack direction="row">
  <dap-ds-toggle-button shape="button">
    Toggle me
  </dap-ds-toggle-button>
  <dap-ds-toggle-button shape="circle" active>
    <dap-ds-icon name="menu-line"></dap-ds-icon>
  </dap-ds-toggle-button>

  <button
    class="dds-toggle-button dds-toggle-button--md dds-toggle-button--circle dds-toggle-button--active"
    aria-pressed="true">
    <dap-ds-icon name="menu-line"></dap-ds-icon>
  </button>
</dap-ds-stack>
Importing
import { DapDSToggleButton } from 'dap-design-system'
Importing React
import { DapDSToggleButtonReact } from 'dap-design-system/react'
Tree-Shakeable Imports

For optimal bundle sizes, use the tree-shakeable import syntax:

import { DapDSToggleButton } from 'dap-design-system/components'
Attributes
PropertyTypeDefaultDescription
size'lg', 'md' , 'sm' , 'xs''md'The size of the button
activebooleanfalseWhether the button is active.
shape'button', 'circle''button'The shape of the button
sizeChildrenstring'true'
Slots
NameDescription
(default)The content of the toggle button.
Events

No custom events available.

CSS Parts
Part NameDescription
baseThe main button container.
high-contrastThe high contrast part of the button.
How to Use CSS Parts

You can style CSS parts using the ::part() pseudo-element selector:

/* Target a specific part */
.my-custom-dap-ds-toggle-button::part(base) {
  /* Your custom styles */
}

/* Target multiple parts */
.my-custom-dap-ds-toggle-button::part(base),
.my-custom-dap-ds-toggle-button::part(high-contrast) {
  /* Shared styles */
}

Example usage:

<dap-ds-toggle-button class="my-custom-dap-ds-toggle-button">
  Toggle button
</dap-ds-toggle-button>
.my-custom-dap-ds-toggle-button::part(base) {
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

CSS parts allow you to style internal elements of the component while maintaining encapsulation. Learn more in our styling guide.

CSS Custom Properties
Property NameDescription
--dds-toggle-button-min-width-lgMinimum width of the large toggle button
--dds-toggle-button-min-width-mdMinimum width of the medium toggle button
--dds-toggle-button-min-width-smMinimum width of the small toggle button
--dds-toggle-button-min-width-xsMinimum width of the extra small toggle button
--dds-toggle-button-height-lgHeight of the large toggle button
--dds-toggle-button-height-mdHeight of the medium toggle button
--dds-toggle-button-height-smHeight of the small toggle button
--dds-toggle-button-height-xsHeight of the extra small toggle button
--dds-toggle-button-padding-lgPadding of the large toggle button
--dds-toggle-button-padding-mdPadding of the medium toggle button
--dds-toggle-button-padding-smPadding of the small toggle button
--dds-toggle-button-padding-xsPadding of the extra small toggle button
--dds-toggle-button-font-size-lgFont size of the large toggle button
--dds-toggle-button-font-size-mdFont size of the medium toggle button
--dds-toggle-button-font-size-smFont size of the small toggle button
--dds-toggle-button-font-size-xsFont size of the extra small toggle button
--dds-toggle-button-border-enabledBorder color in enabled state
--dds-toggle-button-background-enabledBackground color in enabled state
--dds-toggle-button-content-enabledContent/text color in enabled state
--dds-toggle-button-border-hoverBorder color in hover state
--dds-toggle-button-background-hoverBackground color in hover state
--dds-toggle-button-border-pressedBorder color in pressed state
--dds-toggle-button-background-pressedBackground color in pressed state
--dds-toggle-button-background-selected-enabledBackground color in selected enabled state
--dds-toggle-button-content-selected-enabledContent/text color in selected enabled state
--dds-toggle-button-background-selected-hoverBackground color in selected hover state
--dds-toggle-button-background-selected-pressedBackground color in selected pressed state
--dds-toggle-button-border-disabledBorder color in disabled state
--dds-toggle-button-background-disabledBackground color in disabled state
--dds-toggle-button-content-disabledContent/text color in disabled state
--dds-toggle-button-highcontrast-borderHigh contrast border color
--dds-toggle-button-highcontrast-border-hoverHigh contrast border color on hover
How to Use CSS Custom Properties

CSS custom properties (CSS variables) can be set directly on the component or in your stylesheet:

Method 1: Inline styles (Quick customization)

<dap-ds-toggle-button
  style="--dds-toggle-button-min-width-lg: value; --dds-toggle-button-min-width-md: value;">
  Toggle button
</dap-ds-toggle-button>

Method 2: CSS classes (Reusable styles)

.my-custom-dap-ds-toggle-button {
  --dds-toggle-button-min-width-lg: value;
  --dds-toggle-button-min-width-md: value;
  --dds-toggle-button-min-width-sm: value;
}
<dap-ds-toggle-button class="my-custom-dap-ds-toggle-button">
  Toggle button
</dap-ds-toggle-button>

Method 3: Global theme customization

/* Apply to all instances */
dap-ds-toggle-button {
  --dds-toggle-button-min-width-lg: value;
  --dds-toggle-button-min-width-md: value;
}

CSS custom properties inherit through the Shadow DOM, making them perfect for theming. Changes apply immediately without rebuilding.