StartFoundationsComponentsContent

Toggle button

A toggle button is a button that stays on or off. Click it once to turn a mode on, again to turn it off.

Stable Figma
OverviewUsageAPIAccessibility
Bold Italic
<tk-toggle-button pressed><tk-button>Bold</tk-button></tk-toggle-button>
<tk-toggle-button><tk-button>Italic</tk-button></tk-toggle-button>

Anatomy

Part What it is
tk-toggle-button the element; holds the on or off state and flips it
default slot one tk-button or tk-icon-button; it draws the look and is the Tab stop

Variants

Show grid Show grid Show grid
<tk-toggle-button pressed><tk-button>Show grid</tk-button></tk-toggle-button>
<tk-toggle-button pressed><tk-button variant="outline">Show grid</tk-button></tk-toggle-button>
<tk-toggle-button pressed><tk-button variant="ghost">Show grid</tk-button></tk-toggle-button>

Set the variant on the inner button: secondary (default), outline, or ghost. Off, the button looks as usual. On, it takes a neutral tint and a neutral label; outline also gets a stronger border. Don't use primary or tone="danger" for a toggle.

Shape

Set shape="round" on the inner button for a pill. In a joined Toggle button group, set it on the group instead.

Following
<tk-toggle-button pressed><tk-button shape="round">Following</tk-button></tk-toggle-button>

States

Pin to top Pin to top
<tk-toggle-button pressed><tk-button disabled>Pin to top</tk-button></tk-toggle-button>
<tk-toggle-button><tk-button disabled>Pin to top</tk-button></tk-toggle-button>
  • pressed: on. A click, Space, or Enter flips it and fires change.
  • Disabled: set disabled on the inner button. It can't flip, and an on toggle keeps a dimmed tint so it still reads as on.
  • Hover, press, and focus come from the button. An on toggle under the pointer darkens one step.

Icon toggle

Put a tk-icon-button inside for an icon-only toggle. Give it a filled twin in its pressed slot, if the icon has one.

<tk-toggle-button>
  <tk-icon-button label="Bookmark">
    <tk-icon name="bookmark"></tk-icon>
    <tk-icon slot="pressed" name="bookmark-filled"></tk-icon>
  </tk-icon-button>
</tk-toggle-button>

Controlled and uncontrolled

  • Uncontrolled (default): a click flips pressed and fires change. Read event.target.pressed.
  • Controlled: set pressed on tk-toggle-button from your state. Setting it in code fires no change; only a user flip does.
  • Don't set pressed on the inner button. The toggle sets it.