Toggle Switch Generator
Create custom toggle switch components with CSS
Presets
Sizing
Off State Colors
On State Colors
Border & Shape
Labels
Handle Icon
Effects
Live Preview
All States
Generated CSS
/* Toggle Switch Styles */
.toggle-switch {
position: relative;
display: inline-flex;
align-items: center;
gap: 10px;
}
.toggle-switch input {
position: absolute;
opacity: 0;
width: 0;
height: 0;
}
.toggle-track {
position: relative;
display: inline-block;
width: 52px;
height: 28px;
background: #d1d5db;
border-radius: 999px;
cursor: pointer;
transition: all 0.2s ease;
}
/* Handle */
.toggle-track::after {
content: '';
position: absolute;
top: 3px;
left: 3px;
width: 22px;
height: 22px;
background: #ffffff;
border-radius: 50%;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
transition: all 0.2s ease;
}
/* Checked State */
.toggle-switch input:checked + .toggle-track {
background: #3b82f6;
}
.toggle-switch input:checked + .toggle-track::after {
left: 27px;
background: #ffffff;
}
/* Focus State */
.toggle-switch input:focus-visible + .toggle-track {
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
}
/* Disabled State */
.toggle-switch input:disabled + .toggle-track {
opacity: 0.5;
cursor: not-allowed;
}HTML Usage
<label class="toggle-switch"> <input type="checkbox" /> <span class="toggle-track"></span> </label>
About Toggle Switches
Accessibility
Toggle switches use a hidden checkbox input for accessibility. Screen readers announce the state as "checked" or "unchecked". Use role="switch"for even clearer semantics.
When to Use
Use toggle switches for binary on/off settings that take effect immediately. Unlike checkboxes, toggles suggest instant action. Common uses: dark mode, notifications, and feature flags.
iOS vs Android
iOS toggles are traditionally green when on, while Android/Material uses the brand primary color. Both platforms use a sliding animation and rounded pill shape.
Labels & Icons
Consider adding labels or icons for clarity, especially for important settings. Inside labels work for larger switches, while outside labels provide more context.
Need Custom Toggle Components?
Our team at Brix340 designs beautiful, accessible UI components that match your brand and enhance user experience across all platforms.
Get a Free Consultation