EN
PortuguêsEnglishEspañol
All tools
Developer tools 100% free

CSS toggle switch generator (on/off button)

Adjust the size and colors and test the preview. The code uses a real checkbox, so it works in forms and with the keyboard.

How to use

Thank you so much for helping!

Every donation helps pay for the servers and keeps the tools free for everyone. Pick or type an amount:

Secure payment by Stripe. Opens in a new tab.

Back to CSS and design

An on/off switch without JavaScript


Available in: PortuguêsEnglish

Advertisement

CSS toggle switch generator (on/off button): what it is for

On/off switches are used in preferences, sign-up forms and settings. This generator makes the switch with a real checkbox styled with CSS, without JavaScript: it stores the state, works with keyboard and touch, is submitted with the form and is announced as on or off by screen readers thanks to role=switch.

You adjust width, height, corners and colors and test the result on, off and disabled. The code includes visible focus, a smooth transition that respects people who prefer less motion and high-contrast mode.

How to use

  1. Adjust the size and corners.
  2. Choose the colors and the label text.
  3. Copy the HTML and CSS.

When to use it

  • Notification preferences.
  • A site's dark mode.
  • Accepting terms in a form.

Frequently asked questions

Why use a checkbox?

A checkbox already does everything a switch needs: it stores the state, receives focus, toggles with the space bar and is submitted with the form. The CSS only changes how it looks, and the role=switch attribute makes screen readers announce on and off.

Does it need JavaScript?

Not to work. Only if you want to do something the moment the switch changes, like saving the preference; then just listen for the input's change event.

What size should I use on phones?

The touch target should be at least 24 by 24 px according to WCAG 2.2, and around 44 px is recommended for fingers. Since the text next to it is part of the label, it increases the clickable area.

Is it really free?

Yes, 100% free. No sign-up, no subscription and no usage limits. All Tools123 tools are free and run right in your browser.

Similar tools

The tools are provided as is, without warranty. We are not responsible for the results or for how they are used.