Components

Toggle

A two-state button that stays down: a whisper of pencil box at rest, and a highlighter body that snaps into register when it is on. Same Radix behavior and variants as shadcn.

Install

terminal
npx shadcn@latest add @wobko/toggle

First time here? Add the registry to components.json first. How to install

Examples

Variants

Default is a whisper of pencil that becomes a highlighted, boxed button when it is on. Outline keeps its ink box the whole time. Icon-only toggles need an aria-label.

Sizes, tones and disabled

Three heights, the terracotta marker for a louder switch, and disabled toggles: a dashed pencil box, and a pale wash if it is on.

A follow button

A controlled toggle: the state lives in your component, the label says what pressing does, and a status line says what happened, so nothing depends on the highlighter.

Demo

Official `toggle-demo`: a small outline toggle with a bookmark and a word. shadcn fills the bookmark blue when it is on; this one keeps its highlighter body and writes the bookmark in blue felt tip, because a drawn line has no fill to change. Space or Enter toggles it.

Disabled

Official `toggle-disabled`: an icon-only toggle with `disabled`. It is drawn as a dashed pencil-gray box and takes no pointer or keyboard. (The original's label says "italic" on an underline; this one says what it shows.)

Large

Official `toggle-lg`: `size="lg"`, 40 px tall (36 in compact density, 32 in calm), for touch-first toolbars.

Outline

Official `toggle-outline`: `variant="outline"` keeps a felt-tip box around the toggle whether it is on or off; the default variant is only a whisper of pencil until it is pressed.

Small

Official `toggle-sm`: `size="sm"`, 32 px tall, for dense toolbars.

With text

Official `toggle-with-text`: an icon and a word. With a visible word the toggle needs no `aria-label`, and the highlighter body stretches to fit both.

API reference

Toggle

A Radix Toggle (a real <button aria-pressed>) with a hand-drawn layer behind its content. Pressed state is data-state=on in CSS, so pressing never redraws anything: the highlighter body fades in, settles from a slight turn and snaps into register while the pointer is down.

PropTypeDefaultDescription
variant"default" | "outline""default"default = a whisper of pencil box that turns into a fine-liner box with a highlighter body when on; outline = an inked box at rest that gets the body inside it.
size"default" | "sm" | "lg""default"36, 32 and 40 px high, with the same minimum widths (icon squares). Compact density is one step tighter, calm two.
tone"hi" | "marker""hi"The color of the body when on: yellow highlighter, or terracotta marker for a louder switch.
pressed / defaultPressed / onPressedChangeRadix-Controlled and uncontrolled state, exactly as Radix Toggle.
asChildbooleanfalseRender your own element with the toggle's classes, state attributes and drawing inside it (Radix Slot).
seedstring | number-Pins the hand: the same seed always draws the same toggle, also across remounts. Default: derived from useId().

toggleVariants

The cva function behind Toggle (also used by ToggleGroupItem). Layout and typography classes only: the drawing comes from the component.

PropTypeDefaultDescription
variant"default" | "outline""default"Same values as Toggle.
size"default" | "sm" | "lg""default"Same values as Toggle.
classNamestring-Merged last.

Accessibility

  • Renders a native <button> with aria-pressed: Enter and Space press it, Tab focuses it, disabled removes it from the tab order.
  • An icon-only toggle needs a name: pass aria-label ("Bold"). Keep the label the same when the state changes, and let aria-pressed say on or off.
  • On is never told by hue alone: the toggle gains a solid fine-liner box and a filled body, and the drawn body sits under the label at 12:1 (highlighter) or 4.6:1 (marker).
  • Keyboard focus draws the blue felt ring (3:1 against paper and desk); Windows high contrast swaps the drawing for a real border and the browser's own pressed styling.
  • aria-invalid draws the box in red pencil (again over the body when the toggle is down), so the cue is a line and not only a color.
  • Reduced motion removes the settle, the hover tilt and the snap.

Source

The files the CLI copies into your project.

Loading the source