<input type="checkbox" switch> is coming to Chromium-based browsers!
My team is currently adding the implementation at https://chromium-review.googlesource.com/c/chromium/src/+/8190074/1
<input type="checkbox" switch> is coming to Chromium-based browsers!
My team is currently adding the implementation at https://chromium-review.googlesource.com/c/chromium/src/+/8190074/1
@patrickbrosset And for those who can't wait: I have a polyfill that lets you use the new `switch` attribute today: https://blog.tomayac.com/2026/01/12/a-polyfill-for-the-html-switch-element/.
@patrickbrosset so they are adding a bit of CSS that most sites have been adding for a bit over a decade.
Is there a way in HTML/CSS to detect that this new 'switch' option is there natively and thus that one can disable the CSS people have, or enable the compat part?
@jeroen I’m not expert on this new thing yet, but I would say:
- In JavaScript: create an input, set its type to checkbox and set the switch attribute, then test if `"switch" in inputˋ is true. The fact that the IDL property is set probably indicates support.
- in CSS: maybe a directory like ˋ input[type="checkbox"][switch][role="switch"]` would detect support, since the browser adds the switch role. But I’m not 100% sure.
The switch attribute was made to silently progressively enhance any checkbox. But you’re right that detecting support would avoid loading unnecessary code for those who already have custom switches.
@tomayac might be able to help further.
@patrickbrosset @jeroen Feature detection in JS is via `if ('switch' in HTMLInputElement.prototype) {}`. I don't think you can reliably detect support from CSS.
@jeroen @patrickbrosset The switch "handle" is draggable in native switches, which is something you can't do in CSS. The polyfill also adds support for that.