1001Ferramentas
🎚️Utilities

HTML Toggle Switch Builder

Builds an iOS-style toggle switch with label using <input type=checkbox> and inline CSS.



  

Toggle switch markup you can style

You need an on/off switch in a screen and you would rather not pull in an entire CSS framework for it. The native HTML checkbox already behaves correctly, it just does not look like a switch. The sensible route is to keep the real checkbox and restyle its appearance, and that is exactly what comes out of this page.

Type the label text, write yes or no for the initial state, and the output is an inline-flex label with the input inside it and the text beside it. The input carries appearance:none, a 36 by 20 pixel box, a grey background, and rounded corners. Be clear about the limit: there is no checked-state rule and no sliding knob, so the pill looks the same grey whether it is on or off. You get the skeleton and finish the visuals yourself.

To make it behave like a switch, move the snippet into a stylesheet and add two rules: one on input:checked to change the background, and an ::after pseudo-element for the knob that slides with a transform. Pseudo-elements cannot live in an inline style attribute, which is why they are missing here. Keep the label wrapping the input, since that is what makes the text clickable and names the control. Label text is not escaped, so fix any quotes or angle brackets first. It all builds in the browser.

Frequently asked questions

Why does my toggle not change color when clicked?
Because the snippet ships no input:checked rule. The checked attribute sets the logical state, but the visual change needs CSS you add afterwards.
Can I pick colors or sizes in the tool itself?
No. The only fields are the label and the initial state. Colors and dimensions get edited directly in the generated CSS.
Is this pattern accessible?
The foundation is, because it uses a real input inside a label, which gives you keyboard focus and correct announcement. Swapping the input for a div would break both.

Related Tools