Rost

← All components

component

Switch

A setting that's on or off and takes effect straight away. A pill track with a thumb that moves across. The label is SwitchField's.

In code Contract: review Guidance: agreed Contract on GitHub Figma 528:402 As markdown

Try it

Every variant

Default · Not checked
Disabled · Not checked
Default · Checked
Disabled · Checked

Hover, press or tab to one to see the other 6 states.

Install

npx github:Runceanu/rost add switch

It lands in src/rost/switch/, with what it needs and its contract. Install has the rest.

When to use

  • A setting that works at once

    A setting that's on or off and works the moment you flip it: email me receipts, show cents, dark charts.

When not to use

  • A choice that waits for Save

    A choice that waits for a Save button. That's a checkbox, and Rost doesn't have one yet.

  • Filtering the screen

    Filtering what's on screen. That's Chip, with selected.

    Use Chip

  • A button that stays pressed

    An icon button that stays pressed, like bold in an editor. That's Toggle.

    Use Toggle

Behaviour

Off is a faded track with the thumb on the left, the way an off Toggle is faded. On is a solid primary green track with a dark thumb on the right. Hover, press and focus come from the browser and follow Toggle's colours. Disabled fades it. I built it in code from Toggle's and Button's tokens, then drew it in the kit, on a page of its own, bound to the same variables. Its label moved to SwitchField on 2026-10-31. The ten variants match Figma.

Accessibility

  • Element

    <button type="button" role="switch"> with aria-checked. Switch sets both.

  • Name

    It has no text of its own. In a SwitchField the label names it; on its own it needs an aria-label.

  • Keyboard

    Tab reaches it. Space flips it, and so does Enter, since it's a button.

  • Focus

    focus-ring around the track, on :focus-visible.

  • Colour

    On and off aren't only green and grey: the thumb moves from one end to the other.

Content

The words go in SwitchField's label, or in aria-label. Say what's on when it's on, as a short phrase in sentence case: "Email me receipts", not "Receipts: on/off".

Props

PropTypeValuesDefault
checked boolean false

States: Default, Hover, Pressed, Focus, Disabled.

Values

Straight from the contract. Each value sits next to its token, because six tokens here all come out as #3a3a3a and the colour alone can't tell you which one is right.

Never changes

root

  • padding 0px spacing/gap/none

displayinline-flex · align-itemscenter · vertical-alignmiddle · positionrelative · backgroundnone · bordernone · fontinherit · cursorpointer · outlinenone

track

  • width 40px spacing/size/medium
  • height 24px spacing/size/small
  • border-radius 10000px spacing/radius/full
  • outline-width 1px spacing/outline/small
  • outline-offset calc(-1 * var(--spacing-outline-small)) on purpose: Composed from a token: the edge sits inside the track.

positionrelative · flex-shrink0 · outline-stylesolid · isolationisolate

background

  • border-radius 10000px spacing/radius/full

positionabsolute · inset0 · pointer-eventsnone · z-index-1

thumb

  • top 4px spacing/gap/2xsmall
  • left 4px spacing/gap/2xsmall
  • width 16px spacing/size/2xsmall
  • height 16px spacing/size/2xsmall
  • border-radius 10000px spacing/radius/full

positionabsolute · pointer-eventsnone

focus-ring

  • border-style solid no token yet
  • border-width 2px spacing/outline/medium
  • border-radius 10000px spacing/radius/full

displaynone · positionabsolute · insetcalc(-1 * var(--spacing-gap-2xsmall)) · pointer-eventsnone

Changes by variant

10 variants. Each table is what one thing changes with: a column per checked, a row per property. Where every row starts with the same token path, it's written once, under the property.

Follows checked

Focus

PropertyNot checkedChecked
focus-ring.border-colorswitch/… off/focus/focus-ring #999 on/focus/focus-ring #b6ffda
PropertyNot checkedChecked
track.outline-colorswitch/… off/edge #747573 on/edge #00d669

Follows state and checked

Not checked

PropertyDefaultHoverPressedFocusDisabled
background.backgroundswitch/off/… default/track #3a3a3a hover/track #555555 pressed/track #282828 focus/track #3a3a3a disabled/track #3a3a3a
background.opacityopacity/… gentle 0.24 mild 0.32 mild 0.32 gentle 0.24 gentle 0.24
thumb.backgroundswitch/off/… default/thumb #d3d9d5 hover/thumb #ededed pressed/thumb #d3d9d5 focus/thumb #d3d9d5 disabled/thumb #d3d9d5

Checked

PropertyDefaultHoverPressedFocusDisabled
background.backgroundswitch/on/… default/track #00d669 hover/track #00b450 pressed/track #00913a focus/track #00d669 disabled/track #00d669
background.opacityopacity/… solid 1 solid 1 solid 1 solid 1 solid 1
thumb.backgroundswitch/on/… default/thumb #060805 hover/thumb #060805 pressed/thumb #060805 focus/thumb #060805 disabled/thumb #060805

Only in some variants

These don't change: they're just set in some variants and not others.

Focus

  • focus-ring.display block layout

Disabled

  • root.cursor default Figma frame size
  • root.opacity 0.24 opacity/gentle

Checked

  • thumb.left calc(100% - var(--spacing-size-2xsmall) - var(--spacing-gap-2xsmall)) on purpose: Composed from tokens: the far end of the track, less the thumb and its 4px.

Part of Switch

SwitchField

A Switch with its label beside it, on the left or the right. A click on the words flips it too.

In code Contract: review Guidance: agreed Contract on GitHub Figma 545:57 As markdown

Try it

Every variant

Right · Not disabled
Left · Not disabled
Right · Disabled
Left · Disabled

Install

npx github:Runceanu/rost add switch-field

It lands in src/rost/switch-field/, with what it needs and its contract. Install has the rest.

When to use

  • A setting with its name

    Any switch that people read before they flip: email me receipts, show cents, dark charts.

  • Label on the left

    A settings panel where the labels are long: the switches line up down the right edge, where the eye finds them.

When not to use

  • A switch with no words

    A switch whose meaning comes from what's around it, like a row in a table. Use Switch with an aria-label.

    Use Switch

  • A label that changes

    "On" and "Off" as the label. The track says that; the label says what it's for.

Behaviour

The label is a <label> tied to the switch, so a click anywhere on the words flips it, the way a checkbox's label does. Hover, press and focus are the switch's own. Disabled fades both. I made it when I took the label out of Switch so it could go on either side. In Figma it's on the switch page, next to Switch, with a real Switch instance inside that you can set on or off.

Accessibility

  • Element

    A <span> holding the Switch's <button role="switch"> and a <label for> it.

  • Name

    The label. SwitchField ties the two with an id, so you don't.

  • Keyboard

    The switch's: Tab reaches it, Space and Enter flip it.

  • Focus

    The switch's ring, around the track.

Content

A short phrase in sentence case, saying what's on when it's on: "Email me receipts", not "Receipts: on/off".

Props

PropTypeValuesDefault
label slot
side enum Left · Right Right
switch node
disabled boolean false

Values

Straight from the contract. Each value sits next to its token, because six tokens here all come out as #3a3a3a and the colour alone can't tell you which one is right.

Never changes

root

  • gap 8px spacing/gap/small

displayinline-flex · align-itemscenter · vertical-alignmiddle

switch

flex-shrink0

label

  • font-family 'General Sans Variable' font-family/base
  • font-weight 400 typography/paragraph/font-weight/regular
  • font-size 14px typography/paragraph/font-size
  • line-height 20px typography/paragraph/line-height
  • letter-spacing 0px typography/paragraph/letter-spacing
  • color #d3d9d5 switch-field/label

cursorpointer

Changes by variant

3 variants. Each table is what one thing changes with: a column per side, a row per property. Where every row starts with the same token path, it's written once, under the property.

Follows side

All but Disabled

PropertyLeftRight
root.flex-direction row-reverse row

Only in some variants

These don't change: they're just set in some variants and not others.

Disabled

  • label.cursor default Figma frame size
  • label.opacity 0.24 opacity/gentle

Left

  • root.justify-content flex-end layout