|$ curl https://forge-ai.dev/api/markdown?path=docs/components/toggle
$cat docs/toggles-&-switches.md
updated Recently·11 min read·published

Toggles & Switches

CSSHTMLUIIntermediate🎯Free Tools

iOS-style toggle switches, labeled toggles, disabled states, sizes, color variants, and grouped toggle controls.

Basic Toggle

A simple iOS-style toggle switch with smooth sliding animation. Click to toggle between on and off states.

basic-toggle
Live
untitled.html
HTML
1<div class="wrap">
2 <label class="toggle">
3 <input type="checkbox" checked>
4 <span class="track">
5 <span class="thumb">
6 </span>
7 </span>
8 </label>
9 <label class="toggle">
10 <input type="checkbox">
11 <span class="track">
12 <span class="thumb">
13 </span>
14 </span>
15 </label>
16</div>
preview

info

Always pair a toggle with a visible label. Users should never have to guess what the toggle controls. Consider adding state text like "On" / "Off" for accessibility.
Labeled Toggles

Toggles with descriptive labels and current state indicator. Labels appear on either side of the switch.

labeled-toggle
Live
untitled.html
HTML
1<div class="list">
2 <label class="toggle-row">
3 <span class="label">
4 <strong>
5 Dark Mode
6 </strong>
7 <span class="desc">
8 Enable dark theme across the app
9 </span>
10 </span>
11 <label class="toggle">
12 <input type="checkbox" checked>
13 <span class="track">
14 <span class="thumb">
15 </span>
16 </span>
17 </label>
18 </label>
19 <label class="toggle-row">
20 <span class="label">
21 <strong>
22 Notifications
23 </strong>
24 <span class="desc">
25 Receive push notifications
26 </span>
27 </span>
28 <label class="toggle">
29 <input type="checkbox">
30 <span class="track">
31 <span class="thumb">
32 </span>
33 </span>
34 </label>
35 </label>
36 <label class="toggle-row">
37 <span class="label">
38 <strong>
39 Auto-save
40 </strong>
41 <span class="desc">
42 Save changes every 30 seconds
43 </span>
44 </span>
45 <label class="toggle">
46 <input type="checkbox" checked>
47 <span class="track">
48 <span class="thumb">
49 </span>
50 </span>
51 </label>
52 </label>
53 <label class="toggle-row">
54 <span class="label">
55 <strong>
56 Two-Factor Auth
57 </strong>
58 <span class="desc">
59 Extra security for your account
60 </span>
61 </span>
62 <label class="toggle">
63 <input type="checkbox">
64 <span class="track">
65 <span class="thumb">
66 </span>
67 </span>
68 </label>
69 </label>
70</div>
preview
Disabled States

Disabled toggles that cannot be interacted with — dimmed appearance signals non-interactive state.

disabled-toggle
Live
untitled.html
HTML
1<div class="wrap">
2 <label class="toggle">
3 <input type="checkbox" disabled>
4 <span class="track">
5 <span class="thumb">
6 </span>
7 </span>
8 <span class="lbl">
9 Off &amp; Disabled
10 </span>
11 </label>
12 <label class="toggle">
13 <input type="checkbox" checked disabled>
14 <span class="track">
15 <span class="thumb">
16 </span>
17 </span>
18 <span class="lbl">
19 On &amp; Disabled
20 </span>
21 </label>
22</div>
preview

warning

Disabled toggles should still convey their current state (on/off) visually. Avoid hiding them entirely — dim them instead so users understand the setting exists but is controlled elsewhere.
Sizes

Small, medium, and large toggles to fit different UI densities — from compact tables to spacious settings panels.

toggle-sizes
Live
untitled.html
HTML
1<div class="wrap">
2 <label class="toggle sm">
3 <input type="checkbox" checked>
4 <span class="track">
5 <span class="thumb">
6 </span>
7 </span>
8 </label>
9 <label class="toggle md">
10 <input type="checkbox" checked>
11 <span class="track">
12 <span class="thumb">
13 </span>
14 </span>
15 </label>
16 <label class="toggle lg">
17 <input type="checkbox" checked>
18 <span class="track">
19 <span class="thumb">
20 </span>
21 </span>
22 </label>
23 <label class="toggle xl">
24 <input type="checkbox" checked>
25 <span class="track">
26 <span class="thumb">
27 </span>
28 </span>
29 </label>
30</div>
preview
Color Variants

Custom accent colors for toggles — use semantic colors to match the action context.

toggle-colors
Live
untitled.html
HTML
1<div class="wrap">
2 <label class="toggle">
3 <input type="checkbox" checked>
4 <span class="track green">
5 <span class="thumb">
6 </span>
7 </span>
8 </label>
9 <label class="toggle">
10 <input type="checkbox" checked>
11 <span class="track blue">
12 <span class="thumb">
13 </span>
14 </span>
15 </label>
16 <label class="toggle">
17 <input type="checkbox" checked>
18 <span class="track purple">
19 <span class="thumb">
20 </span>
21 </span>
22 </label>
23 <label class="toggle">
24 <input type="checkbox" checked>
25 <span class="track red">
26 <span class="thumb">
27 </span>
28 </span>
29 </label>
30 <label class="toggle">
31 <input type="checkbox" checked>
32 <span class="track orange">
33 <span class="thumb">
34 </span>
35 </span>
36 </label>
37</div>
preview

best practice

Use green for positive/safe toggles (dark mode, notifications), red for destructive or security-sensitive actions (delete protection, public visibility), and blue for neutral feature flags.
Icon Toggle

Toggle switches with icons inside the track — sun/moon for theme, lock for security, volume for sound.

icon-toggle
Live
untitled.html
HTML
1<div class="wrap">
2 <label class="toggle icon">
3 <input type="checkbox" checked>
4 <span class="track">
5 <span class="thumb">
6 <svg width="10" height="10" viewBox="0 0 24 24" fill="currentColor">
7 <path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
8 </svg>
9 </span>
10 </span>
11 </label>
12 <label class="toggle icon">
13 <input type="checkbox">
14 <span class="track">
15 <span class="thumb">
16 <svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
17 <circle cx="12" cy="12" r="5"/>
18 <line x1="12" y1="1" x2="12" y2="3"/>
19 <line x1="12" y1="21" x2="12" y2="23"/>
20 <line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/>
21 <line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/>
22 <line x1="1" y1="12" x2="3" y2="12"/>
23 <line x1="21" y1="12" x2="23" y2="12"/>
24 <line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/>
25 <line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/>
26 </svg>
27 </span>
28 </span>
29 </label>
30 <label class="toggle icon">
31 <input type="checkbox" checked>
32 <span class="track">
33 <span class="thumb">
34 <svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
35 <path d="M11 5L6 9H2v6h4l5 4V5z"/>
36 <path d="M19.07 4.93a10 10 0 0 1 0 14.14"/>
37 <path d="M15.54 8.46a5 5 0 0 1 0 7.07"/>
38 </svg>
39 </span>
40 </span>
41 </label>
42</div>
preview
Loading State

Toggles with a spinner inside the track while the state change is being processed on the server.

loading-toggle
Live
untitled.html
HTML
1<div class="wrap">
2 <label class="toggle">
3 <input type="checkbox" checked>
4 <span class="track loading">
5 <span class="thumb spinner">
6 <svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3">
7 <circle cx="12" cy="12" r="10" stroke-dasharray="31.42" stroke-dashoffset="10"/>
8 </svg>
9 </span>
10 </span>
11 </label>
12 <label class="toggle">
13 <input type="checkbox">
14 <span class="track loading">
15 <span class="thumb spinner">
16 <svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3">
17 <circle cx="12" cy="12" r="10" stroke-dasharray="31.42" stroke-dashoffset="20"/>
18 </svg>
19 </span>
20 </span>
21 </label>
22</div>
preview
🔥

pro tip

When toggling state triggers an API call, disable the toggle and show a spinner. Re-enable once the response arrives. This prevents double-taps and gives clear feedback that something is happening.
Grouped Toggles

Multiple toggles organized in a card-style group with section headers — ideal for settings panels.

grouped-toggle
Live
untitled.html
HTML
1<div class="card">
2 <div class="card-header">
3 <h3>
4 Settings
5 </h3>
6 </div>
7 <div class="card-body">
8 <div class="section">
9 <div class="section-title">
10 Appearance
11 </div>
12 <label class="toggle-row">
13 <span>
14 Dark Mode
15 </span>
16 <label class="toggle">
17 <input type="checkbox" checked>
18 <span class="track">
19 <span class="thumb">
20 </span>
21 </span>
22 </label>
23 </label>
24 <label class="toggle-row">
25 <span>
26 Compact View
27 </span>
28 <label class="toggle">
29 <input type="checkbox">
30 <span class="track">
31 <span class="thumb">
32 </span>
33 </span>
34 </label>
35 </label>
36 <label class="toggle-row">
37 <span>
38 Animations
39 </span>
40 <label class="toggle">
41 <input type="checkbox" checked>
42 <span class="track">
43 <span class="thumb">
44 </span>
45 </span>
46 </label>
47 </label>
48 </div>
49 <div class="divider">
50 </div>
51 <div class="section">
52 <div class="section-title">
53 Privacy
54 </div>
55 <label class="toggle-row">
56 <span>
57 Public Profile
58 </span>
59 <label class="toggle">
60 <input type="checkbox">
61 <span class="track">
62 <span class="thumb">
63 </span>
64 </span>
65 </label>
66 </label>
67 <label class="toggle-row">
68 <span>
69 Activity Status
70 </span>
71 <label class="toggle">
72 <input type="checkbox" checked>
73 <span class="track">
74 <span class="thumb">
75 </span>
76 </span>
77 </label>
78 </label>
79 </div>
80 </div>
81</div>
preview
📝

note

Grouped toggles work well inside cards or panels. Use section dividers and titles to organize related settings. Consider batching API calls if multiple toggles in a group trigger server updates.
Toggle with Status Text

Toggles that display their current state as text next to the switch — useful for forms and accessibility.

status-toggle
Live
untitled.html
HTML
1<div class="wrap">
2 <label class="toggle-status">
3 <label class="toggle">
4 <input type="checkbox" checked>
5 <span class="track">
6 <span class="thumb">
7 </span>
8 </span>
9 </label>
10 <span class="status on">
11 Enabled
12 </span>
13 </label>
14 <label class="toggle-status">
15 <label class="toggle">
16 <input type="checkbox">
17 <span class="track">
18 <span class="thumb">
19 </span>
20 </span>
21 </label>
22 <span class="status off">
23 Disabled
24 </span>
25 </label>
26</div>
preview
Toggle Button Group

Button-style toggles where one option is active at a time — similar to radio buttons but with toggle styling.

toggle-button-group
Live
untitled.html
HTML
1<div class="wrap">
2 <div class="btn-toggle">
3 <button class="active">
4 All
5 </button>
6 <button>
7 Active
8 </button>
9 <button>
10 Inactive
11 </button>
12 </div>
13 <div class="btn-toggle">
14 <button class="active">
15 Light
16 </button>
17 <button>
18 Dark
19 </button>
20 <button>
21 System
22 </button>
23 </div>
24</div>
preview

best practice

Toggle button groups are ideal for mutually exclusive options (like view modes or themes). For independent on/off settings, use standard toggle switches instead.
Keyboard Accessible

All toggles are keyboard accessible — use Tab to focus and Space to toggle. Focus ring is visible for clarity.

keyboard-toggle
Live
untitled.html
HTML
1<div class="wrap">
2 <label class="toggle focusable">
3 <input type="checkbox" checked>
4 <span class="track">
5 <span class="thumb">
6 </span>
7 </span>
8 <span class="lbl">
9 Tab to me, press Space
10 </span>
11 </label>
12</div>
preview

info

Always add a visible focus indicator for keyboard users. The native checkbox handles keyboard interaction automatically — just style the focus-visible state with an outline or ring. Never remove the underlying checkbox input.