Components

Switch

On/off control that applies a setting right away

Overview

Switch turns a setting on or off immediately, without a save button. It renders a button with the switch role, so screen readers announce it as a switch and read whether it is on or off.

Give it a name. When there is visible text next to it, point to that text with aria-labelledby. Otherwise use aria-label.

States

Anonymous Error Reporting

Both states keep at least 3:1 contrast against the background: the off track has a visible border and thumb, and the on track uses the brand color.

Props

PropTypeDefaultRequiredDescription
checkedboolean-Yestrue when on
onCheckedChange(checked: boolean) => void-NoReceives the value after the press (the opposite of the current one)
disabledbooleanfalseNoDisabled
aria-labelstring-NoAccessible name. Use aria-labelledby when there is visible text next to it
aria-labelledbystring-NoId of the text that names it
classNamestring-NoExtra CSS class
refRef<HTMLButtonElement>-NoRef to the button element

Specification

base

상태요소속성값
enabledrootborderRadius$size.radius.full
enabledrootborderWidth$size.stroke.border
enabledrootborderColor$color.border.default.secondary
enabledrootbackgroundColor$color.background.default.default
enabledrootwidth44px토큰 아님 — no sizing token scale
enabledrootheight24px토큰 아님 — no sizing token scale
enabledthumbbackgroundColor$color.icon.default.secondary
hoverrootbackgroundColor$color.background.default.defaultHover
checkedrootborderColor$color.background.brand.default
checkedrootbackgroundColor$color.background.brand.default
checkedthumbbackgroundColor$color.icon.brand.onBrand
disabledrootborderColor$color.border.disabled.default
disabledrootbackgroundColor$color.background.disabled.default
disabledthumbbackgroundColor$color.icon.disabled.default
focusVisiblerootoutlineWidth$size.stroke.focus
focusVisiblerootoutlineStylesolid토큰 아님 — no line style token
focusVisiblerootoutlineColor$color.border.focus.default
focusVisiblerootoutlineOffset2px토큰 아님 — no ring offset token

Usage Guidelines

Do

  • Use Switch for settings that take effect immediately
  • Name it with the visible label next to it through aria-labelledby

Don't

  • Don't put the state in the name, such as Enable or Disable. The switch already announces on or off
  • Don't use Switch for choices that need a submit button. Use a checkbox in a form