CSS Toggle Switch and Checkbox Generator

Style switches, checkboxes and radios with appearance: none, keep keyboard, forms and screen readers working, and copy the CSS and HTML.

Runs in your browser. Your files never leave your device. See how to check

…

How to do it

  1. 1
    Choose the control

    Tap Toggle switch, Checkbox or Radio button; each keeps its own design.

  2. 2
    Start from a style

    Pick a preset such as iOS style or Rounded to load a full design.

  3. 3
    Set size and colours

    Adjust the size, radius, on and off colours, knob or tick colour and border.

  4. 4
    Set focus and motion

    Choose the focus ring colour, the animation time and the label side.

  5. 5
    Check visibility

    Read the contrast checks and try the controls with Tab and Space in the preview, on a light and a dark page.

  6. 6
    Copy the code

    Copy the CSS and the HTML pattern, then give each input its own id and label text.

About this tool

The default checkbox and radio button look different in every browser and rarely match a design, so people replace them with custom controls, and many replacements quietly break things: the checkbox can no longer be reached with Tab, the form stops sending its value, or a screen reader announces a clickable div with no state. This generator styles the real input element instead. It removes the browser's drawing with appearance: none and paints the control with the input's own background, border and a pseudo-element for the knob, tick or dot, so the input still takes focus, still toggles with Space, still sends its value with the form and still announces checked or not checked. There are three kinds, each with its own saved settings. The toggle switch has a track and a sliding knob, takes its width from the height you choose, and adds role="switch" so assistive technology says on or off. The checkbox draws an SVG tick on the checked state and a dash for the indeterminate state that select-all boxes use. The radio button draws a dot that grows in when chosen, inside a round or square ring. For every kind you set the size, corner radius, on and off colours, knob, tick, border, focus ring, animation time and whether the label sits left or right. A forced-colors rule keeps the controls visible in Windows High Contrast mode.

The preview shows every state

Each preview shows a checked control, an unchecked one and, if you keep the option on, a disabled one with a greyed label. The checkbox preview adds an indeterminate example, and the radio preview shows a group of three plans with one sold out. Switch the preview to a dark page to see how the colours hold up.

Checks for visibility

WCAG 1.4.11 asks that the parts of a control people need to see have a contrast of at least 3 to 1 with what is around them. The checks test the off track or unchecked border against a white page, the knob or tick against the on colour, and the focus ring. For switches, a warning appears when the on and off colours are too similar and no icons are shown, because people who cannot tell the colours apart need another clue; the tick and cross icons option adds one.

Presets

Switches come in iOS style, Material, square, with icons and large. Checkboxes come rounded, square, circular and as an outline tick. Radios come as a dot, a filled ring, a square option and large. A preset keeps your class name and label.

Limits

The generator does not make segmented controls, star ratings or toggle buttons built from button elements; those need different markup and ARIA. It does not add JavaScript, so the indeterminate state still has to be set from your script, as the preview does. The :has() rule that greys a disabled label is skipped by browsers released before 2023, which is harmless.

Worked example

The default switch is 24px high, so the track is 43px wide with a 3px inset, an 18px knob and 19px of travel. The off track #cbd5e1 has only 1.48 to 1 against white, so the checks suggest a border or a darker grey; the on colour #16a34a gives the white knob 3.30 to 1. A checkbox with a #64748b border reaches 4.76 to 1 against white and passes.

Quick facts

Frequently asked questions

Why keep a real input instead of a div?

A real input brings keyboard support, form submission, the checked state for screen readers, label clicking and browser autofill for free. A div needs JavaScript and ARIA to copy all of that and usually misses something.

What does role="switch" change?

It tells assistive technology to announce the control as a switch that is on or off, rather than a checkbox that is checked. Use a switch for settings that take effect immediately, such as notifications, and a checkbox for choices that are submitted with a form.

How do I set the indeterminate state?

It cannot be set in HTML. In JavaScript, set element.indeterminate = true, for example on a Select all box when only some items are chosen. The generated CSS already styles it with a dash.

Is the clickable area big enough on phones?

The whole label is the click target and the CSS gives it a minimum height of 44px, so tapping the text works as well as tapping the control. That meets the common 44 to 48 pixel advice even when the control itself is smaller.

Will the animation bother people?

The knob and dot transitions are short, and a prefers-reduced-motion rule turns them off for anyone who has asked their system for less motion.

Does it work in all browsers?

appearance: none and the pseudo-elements work in all current versions of Chrome, Edge, Firefox and Safari. Only the optional disabled-label rule needs :has(), and older browsers simply skip it.

Guides for this tool

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages