Skip to content

<input type=checkbox switch> #4180

Open

Description

@atishay

This is a feature request on the behalf of all web developers targeting mobile. Here are reasons the toggle switch element should be natively available in HTML forms:

  • Switch is a standard and popular UI control in both Android and iOS mobile platforms.
  • Checkbox is used in websites due to the absence of the switch. Checkbox is absent from iOS and is not considered a good part of the human interface for forms on mobile. Checkbox has a smaller hit area than switches.
  • Switch is very popular in UI frameworks that have been providing this as a component to use - Material Design, Bootstrap, React Native
  • Switches are non-trivial to implement properly in CSS. See Codepen, W3Schools. Most frameworks that are provided to generate HTML on the server do not have a switch causing developers, especially enterprise using checkbox in the place of a switch. PWAs without switches appear non-native on mobile platforms.
  • Implementing switches should have no performance overhead for the browsers (separate component in the UI).

I am happy to help writing a spec for the <input type="switch" /> element if that can help getting it into the browsers.

Toggle Switch

Activity

  1. annevk commented on Nov 19, 2018

    @annevk
    Member

    Shouldn't this be a checkbox with a different style? E.g., appearance: switch?

    cc @whatwg/rendering

  2. atishay commented on Nov 19, 2018

    @atishay
    Author

    Definitely makes more sense as we get backwards compatibility.

  3. annevk commented on Nov 19, 2018

    @annevk
    Member

    Apologies for not welcoming you by the way, I missed this is your first issue. Belatedly, welcome! https://whatwg.org/working-mode#changes and https://whatwg.org/faq#adding-new-features provide some context for the way work is done. I think for this particular request there is enough to go on as this is clearly an established UI widget that makes sense to expose the web in some form. Thanks for raising it.

  4. domenic commented on Nov 19, 2018

    @domenic
    Member

    Indeed, welcome. I'm glad @annevk pointed you to the adding new features FAQ, as it helps keep specific solutions (e.g. <input type="switch">) separate from the problem statement ("displaying a control that looks like a switch").

    Coincidentally we have been having some discussions internally in Chrome about better built-in UI widgets and form controls. At this point I don't have much to report beyond tentative interest in the general program. But there's a lot to still figure out in the specifics: e.g. theme-ability, whether we can do this in a layered way that does not require more browser magic (like appearance does), etc.

  5. sideshowbarker commented on Nov 20, 2018

    @sideshowbarker
    Member

    👍 It also seems worth mentioning that ARIA (since ~1.1 I think) now has a switch role:

    https://w3c.github.io/aria/#switch

  6. atishay commented on Nov 20, 2018

    @atishay
    Author

    I am happy to work with the team if any help in needed in getting this spec'ed or implemented, in whatever form it makes sense to get a toggle switch control into the browsers. I will be careful about not having a solution but only a problem in the future.
    Really glad to see how active the HTML WG is on their github channel.

  7. annevk commented on Nov 20, 2018

    @annevk
    Member

    @sideshowbarker that's very interesting, that almost suggests there is some semantic related to the presentation of a switch checkbox. Using a CSS property at that point wouldn't work well as that couldn't map to ARIA cleanly.

    cc @whatwg/a11y

  8. LJWatson commented on Nov 20, 2018

    @LJWatson

    The ARIA 'switch' role maps to the accessibility APIs, so an element with 'role="switch"' has semantic meaning to screen readers.

    • MSAA + IA2: Role: ROLE_SYSTEM_CHECKBUTTON, Role: IA2_ROLE_TOGGLE_BUTTON
    • UIA: Control Type: Button, Localized Control Type: toggleswitch
    • ATK/AT-ASPI: Role: ROLE_TOGGLE_BUTTON, Object Attribute: xml-roles:switch
    • AX API: AXRole: AXCheckBox, AXSubrole: AXSwitch
  9. malchata commented on Nov 20, 2018

    @malchata

    I don't think this is a bad idea, but proposals for new browser features can take a long time between conception and implementation across platforms—assuming universal adoption is ever achieved.

    Because of this, the question that immediately springs to mind for me is "what does a reliable non-JavaScript fallback pattern look like for this?", and appearance: switch; in combination with <input type="checkbox"> seems to provide a foundation for a progressively enhanced and accessible switch element.

  10. annevk commented on Nov 20, 2018

    @annevk
    Member

    I agree that's a good consideration, but note that <input type=checkbox switch> would provide that too and is probably more apt given the slight semantic implication.

  11. malchata commented on Nov 20, 2018

    @malchata

    Good point @annevk. I can't see any reason why that wouldn't work as well!

  12. 66 remaining items

  13. eqiu8 commented on Mar 27, 2024

    @eqiu8
  14. pepelsbey commented on Nov 5, 2024

    @pepelsbey

    Given that Safari 17.4 shipped <input type="checkbox" switch> eight months ago, I wonder what’s the status of this feature from WHATWG’s point of view.

  15. annevk commented on Nov 5, 2024

    @annevk
    Member

    Hey @pepelsbey! There's a PR for this feature over at #9546 but there's disagreement over to what extent it needs to describe rendering-related requirements. WebKit's opinion is that it's sufficient to say as much as way for other form controls (which is to say not much) whereas other engines prefer a higher bar. I looked into that and the higher bar essentially requires solving it for most form controls as they are all rather similar in their opaqueness which makes it a bit of a tall order. And we also haven't gotten engagement on the related CSS WG issues to solving that (despite assurances to the contrary above), putting it all in a bit of limbo state unfortunately.

  16. mfreed7 commented on Nov 6, 2024

    @mfreed7
    Contributor

    ...requires solving it for most form controls as they are all rather similar in their opaqueness which makes it a bit of a tall order.

    I'm not sure that's required here, since this is a brand-new control. There shouldn't be compat issues.

    And we also haven't gotten engagement on the related CSS WG issues to solving that (despite assurances to the contrary above), putting it all in a bit of limbo state unfortunately.

    The last conversation that I'm aware of was the Sept 19 TPAC meeting, at which Apple said there was a forthcoming specific proposal that needed "1 month of legal review" and then would be made public. If we missed the publication of this proposal, awesome - can you please provide a link? I had been assuming it'd get linked on w3c/csswg-drafts#10866. Chromium is very much supportive of solving the general form stylability problem, so it'd be unfortunate if there's been a miscommunication.

  17. annevk commented on Nov 7, 2024

    @annevk
    Member

    There shouldn't be compat issues.

    It's not about compatibility issues though. It's about deciding which properties apply and do not apply for appearance: auto (and same for none). That should be the same across controls.

    @mfreed7 I'm not sure what you mean. @chrishtr post above cites a number of CSS WG issues I brought up that lack replies from Google and Mozilla and we were told we would get replies on. The problem here is not appearance: base, or at least I thought it was not.

  18. chrishtr commented on Nov 7, 2024

    @chrishtr
    Contributor

    @chrishtr post above cites a number of CSS WG issues I brought up that lack replies from Google and Mozilla and we were told we would get replies on.

    I didn't cite them, I just quoted your comment listing them. I do still agree it would be good to make progress on them.

    Just enumerating them and suggesting next steps:

    For w3c/csswg-drafts#9830 my suggestion is for you to propose names and Agenda+ the issue, since bikeshedding like that is best done in WG calls. I've Agenda+'d it.

    For w3c/csswg-drafts#9825 is quite broad, do we need to do anything for that or is 9830 sufficient?

    For w3c/csswg-drafts#9832 I'm not sure and a good next step is to ask the CSSWG for feedback. I've Agenda+'ed it.

    For w3c/csswg-drafts#4410, is it relevant to checkbox switch?

  19. annevk commented on Nov 8, 2024

    @annevk
    Member

    Oh right, I'll blame that on not being a native speaker.

    You missed w3c/csswg-drafts#10039 which I think is the most relevant as the other issues are more about base appearance and pseudo-elements, which we should do, but I don't think were the actual blocker?

    The range-related issues can probably be ignored for now in favor of 9830, although I suppose it really depends on how we end up deciding on the pseudo-elements and what they need to be consistently named with.

  20. chrishtr commented on Nov 8, 2024

    @chrishtr
    Contributor

    You missed w3c/csswg-drafts#10039 which I think is the most relevant

    Ok. It looks like you asked two questions when filing that issue, which Mason answered in order to unblock your proposed path to specifying them from my perspective.

  21. added a commit that references this issue on Sep 3, 2025
  22. added and removed
    agenda+To be discussed at a triage meeting
    on Jul 23, 2026
  23. annevk commented on Aug 20, 2026

    @annevk
    Member

    @leotlee @jstenback I'm not entirely sure why we are using the stages process for this. We have a PR that modulo rebasing is ready to land, provided there is implementer interest.

  24. added a commit that references this issue on Oct 9, 2026
    0d4da8d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions