A free CSS toggle switch generator with live preview. Customize size, colors, border-radius, and transition speed, then copy the HTML, CSS, or React code instantly — no sign-up required.

Toggle Switch Generator is a free, browser-based tool that lets you build CSS toggle switches visually. Customize size, shape, colors, and transition speed, then copy production-ready HTML, CSS, or React code with one click. No sign-up, no install — just open and build.
A CSS toggle switch looks simple until you sit down to build one from scratch. The pattern involves a hidden checkbox, a ::before pseudo-element for the knob, a :checked + span selector for the active state, and transition timing that feels right at 300ms but wrong at 500ms. Getting the knob translate distance right requires arithmetic: width - knob - 2 × padding. Miss it by a pixel and the knob clips the track.
input:checked + .slider::before {
transform: translateX(28px); /* where does this number come from? */
}That 28px is 60 - 24 - 4 - 4. Width minus knob minus both paddings. Every size change breaks it. The math is mechanical, repetitive, and error-prone — exactly the kind of work that should be automated.
Three presets cover the common use cases:
translateX(20px)translateX(28px)translateX(36px)Select a size and all dimensions update together. The translate distance recalculates automatically.
Three border-radius styles:
border-radius: 9999px with a circular knob (border-radius: 50%) — the iOS-style defaultborder-radius: 8px with a rounded square knobborder-radius: 2px for flat, Material-style interfacesShape changes apply consistently to both the track and the knob.
Three independent color controls:
Each color picker shows both a visual swatch and a hex input field. Type a hex value directly or use the color picker — both update instantly.
Four options map to specific millisecond values:
0ms (instant)150ms300ms (recommended)600msThe live preview reflects the transition speed — click the toggle preview to feel the animation before copying the code.
Click the preview toggle to toggle it on and off. The animation plays in real time at the exact transition speed you configured. What you see is what your users will get.
CSS tab — the complete stylesheet for both the toggle component and the HTML structure it expects. Includes focus-visible styles for keyboard accessibility:
input:focus-visible + .toggle-slider {
outline: 2px solid #3b82f6;
outline-offset: 2px;
}HTML tab — the full markup plus the CSS embedded in a <style> tag, ready to paste into any plain HTML file.
React tab — a self-contained ToggleSwitch component using useState and inline styles. No external dependencies beyond React itself.
:checked pseudo-classThe tool maintains a single Config state object containing all six settings. Every change triggers re-generation of three code strings — CSS, HTML, and React — using pure functions with no side effects.
interface Config {
size: "sm" | "md" | "lg";
shape: "pill" | "rounded" | "square";
speed: "none" | "fast" | "normal" | "slow";
onColor: string;
offColor: string;
knobColor: string;
checked: boolean; // controls the preview state
}The translate distance is calculated programmatically:
function getTranslateX(size: Size): number {
const s = SIZES[size]; // { width, height, knob, pad }
return s.width - s.knob - s.pad * 2;
}This eliminates the hard-coded pixel arithmetic and makes all three size presets work correctly without manual calculation.
Toggle switches are the standard UI for binary settings — email notifications on/off, dark mode enabled/disabled, two-factor auth active/inactive. Generate a switch that matches your form's color scheme and size conventions, then drop in the code.
SaaS dashboards and admin panels often have 10–20 toggles in a settings view. Having a consistent toggle component reduces visual noise. Generate once, copy the CSS as a shared component style.
A designer hands you a Figma mockup with a custom toggle that uses brand blue (#3b82f6) and a slightly rounded square shape instead of the default pill. Instead of hand-coding the dimensions and calculating the knob translate, configure the generator to match, copy the CSS, and move on.
The Knob Color control lets you set a dark knob (e.g., #1f2937) for light-mode interfaces or a light knob for dark-mode ones. The off-state track color works the same way — set it to a dark #374151 for a dark theme.
The :checked + sibling pattern is a foundational CSS technique. The generated code shows exactly how it works — the hidden checkbox, the ::before pseudo-element as the knob, the sibling combinator for the state change. Reading the output is a quick way to understand the pattern without searching Stack Overflow.
The generated toggle switch is fully accessible without any additional changes:
<input type="checkbox"> is announced as a checkbox by all major screen readersfocus-visible styles are included in the generated CSS using the on colorToggle Switch Generator removes the friction from building custom toggle switches:
Try it now: toggle-switch-generator.tools.jagodana.com
The client needed a robust developer tools solution that could scale with their growing user base while maintaining a seamless user experience across all devices.
We built a modern application using CSS and Toggle Switch, focusing on performance, accessibility, and a delightful user experience.
Category
Developer Tools
Technologies
Date
May 2026
More work in Developer Tools