Skip to content

Add Switch Attribute Explainer#1470

Draft
andresrega-msft wants to merge 2 commits into
openui:mainfrom
andresrega-msft:switch-attribute
Draft

Add Switch Attribute Explainer#1470
andresrega-msft wants to merge 2 commits into
openui:mainfrom
andresrega-msft:switch-attribute

Conversation

@andresrega-msft

Copy link
Copy Markdown

Add Switch Attribute Explainer

@netlify

netlify Bot commented Jul 2, 2026

Copy link
Copy Markdown

👷 Deploy request for open-ui pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 41be3b3


| Vendor | Position | Notes |
|---|---|---|
| WebKit/Safari | **Positive** (shipped) | Available behind flag since Safari 17.4 |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flag is only for the pseudo-elements. The feature itself has no guard.

@annevk

annevk commented Jul 2, 2026

Copy link
Copy Markdown

Also how does this relate to #1376?

@lukewarlow lukewarlow left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Anne has pointed out there's an existing explainer. This should redirect from the old explainer and the old one should be moved, deleted or otherwise handled so we don't have two show up. Feel free to link back to the old one from the new one


There is a [switch element proposal at Open UI](https://open-ui.org/components/switch.explainer/) that would introduce a standalone `<switch>` element. This explainer focuses on the attribute approach (`<input type="checkbox" switch>`). See [Alternatives Considered](#alternatives-considered) for a comparison.

An implementation of the attribute approach was already introduced by Safari Technology Preview and Safari Beta (https://github.com/whatwg/html/pull/9546#issuecomment-1865357407).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's shipped in stable Safari.

Adding the `switch` attribute to a checkbox changes its appearance to a switch control. The control exposes two pseudo-elements for styling:

- **`::track`** — the background track of the switch
- **`::thumb`** — the sliding knob/indicator

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are out of sync with what is proposed in css-forms I think we should defer to that spec for what's actually proposed and just write the explainer on the basis of what is proposed there. If we need to make changes we can as the pseudos never shipped.

@gregwhitworth

Copy link
Copy Markdown
Member

As Anne has pointed out there's an existing explainer. This should redirect from the old explainer and the old one should be moved, deleted or otherwise handled so we don't have two show up. Feel free to link back to the old one from the new one

Let's keep and link to it, don't delete it but keep the same URL so that anyone that linked to the prior one it still functions as expected. There's valid research in the prior one that we should retain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants