跳转到主内容

仅 CSS Tailwind CSS 切换开关,具有主要、次要、重音和语义颜色变体。尺寸 xs – xl。 WCAG AA 可访问,可与 Django、HTMX、Laravel、React 和任何堆栈配合使用。

Toggle components are binary switches that allow users to turn features or settings on and off. Built with native HTML checkbox inputs and enhanced with Tailwind CSS animations, toggles provide an intuitive way to control boolean states. The Frutjam toggle system supports multiple colors, sizes, and disabled states—perfect for settings panels, feature flags, and preference controls.

CSS-only, no JavaScript required. WCAG AA accessible and framework-agnostic — works with Django, HTMX, Laravel, React, and any stack.

Class Type Description
toggleBaseAnimated on/off switch input
toggle-xsSizeExtra small
toggle-smSizeSmall
toggle-mdSizeMedium (default)
toggle-lgSizeLarge
toggle-xlSizeExtra large
toggle-primaryColorPrimary theme color
toggle-secondaryColorSecondary theme color
toggle-accentColorAccent theme color
toggle-neutralColorNeutral theme color
toggle-infoColorInfo semantic color
toggle-successColorSuccess semantic color
toggle-warningColorWarning semantic color
toggle-errorColorError semantic color

Basic Usage

1
2
<input type="checkbox" class="toggle">
<input type="checkbox" class="toggle" checked>
1
2
<input type="checkbox" className="toggle">
<input type="checkbox" className="toggle" checked>

Toggle Sizes

html
1
2
3
4
5
<input type="checkbox" class="toggle toggle-xs">
<input type="checkbox" class="toggle toggle-sm">
<input type="checkbox" class="toggle toggle-md">
<input type="checkbox" class="toggle toggle-lg">
<input type="checkbox" class="toggle toggle-xl">

Toggle Colors

html
1
2
3
4
5
6
7
8
<input type="checkbox" class="toggle" checked>
<input type="checkbox" class="toggle toggle-primary" checked>
<input type="checkbox" class="toggle toggle-secondary" checked>
<input type="checkbox" class="toggle toggle-accent" checked>
<input type="checkbox" class="toggle toggle-info" checked>
<input type="checkbox" class="toggle toggle-success" checked>
<input type="checkbox" class="toggle toggle-warning" checked>
<input type="checkbox" class="toggle toggle-error" checked>

Disabled Toggle

html
1
2
<input type="checkbox" class="toggle" disabled>
<input type="checkbox" class="toggle" disabled checked>

Toggle with Label

html
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<label class="flex items-center gap-2">
  <input type="checkbox" class="toggle toggle-primary" checked>
  <span>Enable notifications</span>
</label>

<label class="flex items-center gap-2">
  <input type="checkbox" class="toggle toggle-success" checked>
  <span>Dark mode</span>
</label>

<label class="flex items-center gap-2">
  <input type="checkbox" class="toggle toggle-warning">
  <span>Analytics</span>
</label>

Toggle States

Off

On

Disabled

html
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<div class="flex gap-4 items-center">
  <div>
    <p class="text-sm font-medium mb-2">Off</p>
    <input type="checkbox" class="toggle toggle-primary">
  </div>
  <div>
    <p class="text-sm font-medium mb-2">On</p>
    <input type="checkbox" class="toggle toggle-primary" checked>
  </div>
  <div>
    <p class="text-sm font-medium mb-2">Disabled</p>
    <input type="checkbox" class="toggle toggle-primary" disabled>
  </div>
</div>