ZaidanHomeDocsComponentsBlocksChartsTypesetCreate

Command Palette

Search for a command to run...

GitHub
New
Sections
  • Introduction
  • Components
  • Blocks
  • Installation
  • Customization
  • Dark Mode
  • Typeset
  • Zaidan Skills
  • FAQ
  • Roadmap
  • Changelog
Installation
  • Astro
  • Manual
  • Solid Start
  • TanStack Router
  • TanStack Start
  • Vite
Blocks
  • Data Grid
  • Event Calendar
  • Filters
  • Gantt
  • Image Crop
  • Kanban
  • Message Scroller
  • Questionnaire
  • Sortable
Components
  • Accordion
  • Alert
  • Alert Dialog
  • Aspect Ratio
  • Attachment
  • Avatar
  • Badge
  • Breadcrumb
  • Bubble
  • Button
  • Button Group
  • Calendar
  • Card
  • Carousel
  • Chart
  • Checkbox
  • Collapsible
  • Combobox
  • Command
  • Context Menu
  • Dialog
  • Drawer
  • Dropdown Menu
  • Empty
  • Field
  • Hover Card
  • Input
  • Input Group
  • Input OTP
  • Item
  • Kbd
  • Label
  • Marker
  • Menubar
  • Message
  • Native Select
  • Navigation Menu
  • Pagination
  • Popover
  • Progress
  • Radio Group
  • Resizable
  • Scroll Area
  • Select
  • Separator
  • Sheet
  • Sidebar
  • Skeleton
  • Slider
  • Spinner
  • Switch
  • Table
  • Tabs
  • Textarea
  • Toast
  • Toggle
  • Toggle Group
  • Tooltip

Toggle

A two-state button that can be either on or off.

Kobalte
Kobalte

The Toggle component is built on top of Kobalte Toggle Button, which provides accessible pressed, disabled, and keyboard interaction behavior.

1
import { BookmarkIcon } from "lucide-solid";
2
import { Toggle } from "~/components/ui/toggle";
3
4
export default function ToggleDemo() {
5
return (
6
<Toggle aria-label="Toggle bookmark" size="sm" variant="outline">
7
<BookmarkIcon class="group-aria-pressed/toggle:fill-foreground" />
8
Bookmark
9
</Toggle>
10
);
11
}

Installation

pnpm dlx shadcn@latest add @zaidan/toggle
npx shadcn@latest add @zaidan/toggle
yarn dlx shadcn@latest add @zaidan/toggle
bunx --bun shadcn@latest add @zaidan/toggle

Usage

1
import { Toggle } from "~/components/ui/toggle";
1
<Toggle>Toggle</Toggle>

Outline

Use variant="outline" for an outline style.

1
import { BoldIcon, ItalicIcon } from "lucide-solid";
2
import { Toggle } from "~/components/ui/toggle";
3
4
export default function ToggleOutline() {
5
return (
6
<div class="flex flex-wrap items-center gap-2">
7
<Toggle variant="outline" aria-label="Toggle italic">
8
<ItalicIcon />
9
Italic
10
</Toggle>
11
<Toggle variant="outline" aria-label="Toggle bold">
12
<BoldIcon />
13
Bold
14
</Toggle>
15
</div>
16
);
17
}

With Text

1
import { ItalicIcon } from "lucide-solid";
2
import { Toggle } from "~/components/ui/toggle";
3
4
export default function ToggleText() {
5
return (
6
<Toggle aria-label="Toggle italic">
7
<ItalicIcon />
8
Italic
9
</Toggle>
10
);
11
}

Size

Use the size prop to change the size of the toggle.

1
import { Toggle } from "~/components/ui/toggle";
2
3
export default function ToggleSizes() {
4
return (
5
<div class="flex flex-wrap items-center gap-2">
6
<Toggle variant="outline" aria-label="Toggle small" size="sm">
7
Small
8
</Toggle>
9
<Toggle variant="outline" aria-label="Toggle default" size="default">
10
Default
11
</Toggle>
12
<Toggle variant="outline" aria-label="Toggle large" size="lg">
13
Large
14
</Toggle>
15
</div>
16
);
17
}

Disabled

Add the disabled prop to prevent interaction.

1
import { Toggle } from "~/components/ui/toggle";
2
3
export default function ToggleDisabled() {
4
return (
5
<div class="flex flex-wrap items-center gap-2">
6
<Toggle aria-label="Toggle disabled" disabled>
7
Disabled
8
</Toggle>
9
<Toggle variant="outline" aria-label="Toggle disabled outline" disabled>
10
Disabled
11
</Toggle>
12
</div>
13
);
14
}

API Reference

For primitive props and keyboard behavior, see the Kobalte Toggle Button API reference.

On This Page

  • Installation
  • Usage
  • Outline
  • With Text
  • Size
  • Disabled
  • API Reference
Built by Kevin Abatan. The source code is available on GitHub.