[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"verticals":3,"quiz-checkbox-switch-native-toggle":44,"search-suggestions":60,"quiz-article-checkbox-switch-native-toggle":109,"path-membership-checkbox-switch-native-toggle":321},[4,20,32],{"id":5,"slug":6,"name":7,"tagline":8,"description":9,"accentFrom":10,"accentTo":11,"icon":12,"defaultLocale":13,"locales":14,"features":16,"position":19},"019fe637-3d33-714b-b57f-23e163ffca0c","dev","Web Development","Read it. Run it. Prove it.","A post a day on modern web development — most with an editable playground and a quiz that explains every answer. Free, no account needed.","violet-500","cyan-400","◇","en",[13,15],"fa",{"courses":17,"paths":17,"articles":17,"exams":18,"flashcards":18,"packages":17,"community":17,"certificates":17,"teams":17,"commerce":17},true,false,0,{"id":21,"slug":22,"name":23,"tagline":24,"description":25,"accentFrom":26,"accentTo":10,"icon":27,"defaultLocale":13,"locales":28,"features":30,"position":31},"019fe637-3dc2-754c-8657-0f175bfee7c6","lang","Languages","Learn a language the way you learn a codebase.","Grammar explained the way good documentation explains an API — one idea at a time, each with a quiz.","amber-400","⌘",[13,15,29],"es",{"courses":18,"paths":18,"articles":17,"exams":18,"flashcards":17,"packages":18,"community":17,"certificates":17,"teams":18,"commerce":18},2,{"id":33,"slug":34,"name":35,"tagline":36,"description":37,"accentFrom":38,"accentTo":39,"icon":40,"defaultLocale":13,"locales":41,"features":42,"position":43},"7b3c16f2-931d-410e-802e-e1fa4edab7de","soft","Soft Skills","The half of the job nobody wrote documentation for.","Weekly, on the parts of working life that decide more than your code does — first weeks, meetings, interviews, promotions, and the people around you. Written from what actually happens, and recorded as a podcast you can listen to on the walk.","emerald-400","teal-300","◉",[13],{"courses":18,"paths":18,"articles":17,"exams":18,"flashcards":18,"packages":18,"community":17,"certificates":18,"teams":18,"commerce":18},3,{"id":45,"slug":46,"kind":47,"title":48,"description":49,"config":50,"verticalId":5,"vertical":55,"course":52,"_count":56,"access":57,"attempts":59,"questionCount":51},"01a21cc5-87bc-74f8-9456-8f54e2875309","checkbox-switch-native-toggle","PRACTICE_QUIZ","checkbox switch — test yourself","Checks the gap between a toggle switch that merely looks right and one that's announced right — and what the new switch attribute does and doesn't fix.",{"questionCount":51,"timeLimitSec":52,"shuffleQuestions":18,"shuffleOptions":17,"negativeMarking":19,"passScorePct":53,"maxAttempts":52,"revealAnswers":54,"allowFlagging":18,"allowBacktracking":17},8,null,70,"AFTER_SUBMIT",{"slug":6,"name":7},{"questions":51},{"allowed":17,"reason":58},"FREE",[],[61,65,69,73,77,81,85,89,93,97,101,105],{"slug":62,"name":63,"articles":64},"webdev","Webdev",202,{"slug":66,"name":67,"articles":68},"javascript","Javascript",159,{"slug":70,"name":71,"articles":72},"frontend","Frontend",105,{"slug":74,"name":75,"articles":76},"tutorial","Tutorial",91,{"slug":78,"name":79,"articles":80},"css","Css",59,{"slug":82,"name":83,"articles":84},"typescript","Typescript",37,{"slug":86,"name":87,"articles":88},"performance","Performance",34,{"slug":90,"name":91,"articles":92},"programming","Programming",27,{"slug":94,"name":95,"articles":96},"react","React",23,{"slug":98,"name":99,"articles":100},"node","Node",19,{"slug":102,"name":103,"articles":104},"browser","Browser",18,{"slug":106,"name":107,"articles":108},"nextjs","Nextjs",14,{"id":110,"slug":46,"title":111,"subtitle":52,"excerpt":112,"coverUrl":113,"locale":13,"readingMinutes":114,"publishedAt":115,"viewCount":104,"likeCount":19,"commentCount":19,"author":116,"vertical":121,"topic":122,"tags":125,"_count":133,"playground":135,"body":137,"bodyMd":307,"seo":308,"translationGroupId":311,"series":52,"podcastUrl":52,"verticalId":5,"thread":312,"assessments":314,"translations":317,"quiz":319},"01a21cc5-8784-732c-a79f-34ec3066e4d0","Your Toggle Switch Is Five Elements. `checkbox switch` Is One.","Every settings page has a toggle switch, and almost every one of them is a checkbox wearing a costume: a label, a span, a ::before, a transition, and — if someone remembered — a role=\"switch\". Safari shipped an attribute that does the whole job: checkbox switch.","\u002Fmedia\u002Fcovers\u002Fcheckbox-switch-native-toggle.png",6,"2026-12-03T06:41:45.272Z",{"id":117,"name":118,"username":119,"avatarUrl":52,"headline":120},"019fe637-3c25-7088-9034-39c9f15dc3c8","Parsa Jiravand","parsa","Frontend engineer · building bestpractic",{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":123,"name":124},"html","HTML",[126,128,129,132],{"slug":123,"name":127,"color":52},"Html",{"slug":78,"name":79,"color":52},{"slug":130,"name":131,"color":52},"accessibility","Accessibility",{"slug":62,"name":63,"color":52},{"assessments":134},1,{"slug":46,"title":136},"checkbox switch — interactive playground",{"blocks":138,"version":134},[139,143,146,149,152,156,159,162,165,168,171,176,180,183,186,189,192,196,199,202,205,209,212,219,222,225,230,233,236,240,244,247,250,253,256,259,262,265,268,271,274,277,280,283,289,292,295,298,301],{"id":140,"html":141,"type":142},"b1","\u003Cp>Open any settings page you&#39;ve shipped. Find the toggle switch next to &quot;Dark mode&quot; or &quot;Email notifications.&quot; Now open devtools and count the elements it took to build it.\u003C\u002Fp>","paragraph",{"id":144,"html":145,"type":142},"b2","\u003Cp>It&#39;s almost never one. It&#39;s a \u003Ccode>&lt;label&gt;\u003C\u002Fcode> wrapping a visually-hidden \u003Ccode>&lt;input type=&quot;checkbox&quot;&gt;\u003C\u002Fcode>, a \u003Ccode>&lt;span class=&quot;slider&quot;&gt;\u003C\u002Fcode> drawing the track, a \u003Ccode>::before\u003C\u002Fcode> pseudo-element drawing the thumb, a CSS transition moving it, and — if whoever built it remembered — an ARIA role telling assistive tech what it actually is.\u003C\u002Fp>",{"id":147,"html":148,"type":142},"b3","\u003Cp>That last part is the one that gets skipped. Here&#39;s the part that stings: even when it isn&#39;t, the browser&#39;s own form control can&#39;t just \u003Cem>be\u003C\u002Fem> a switch. You have to tell it to pretend.\u003C\u002Fp>",{"id":150,"html":151,"type":142},"b4","\u003C!-- playground:start -->",{"id":153,"html":154,"text":154,"type":155,"level":31},"b5","🎮 Try it yourself","heading",{"id":157,"html":158,"type":142},"b6","\u003Cp>\u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fcheckbox-switch-native-toggle\u002Fplayground\">▶️ Open the interactive playground →\u003C\u002Fa>\u003C\u002Fstrong>\u003C\u002Fp>",{"id":160,"html":161,"type":142},"b7","\u003Cp>\u003Cem>Runs right in your browser — poke at it and watch the concept react live.\u003C\u002Fem>\u003C\u002Fp>",{"id":163,"html":164,"type":142},"b8","\u003C!-- playground:end -->",{"id":166,"html":167,"text":167,"type":155,"level":31},"b9","The costume everyone builds",{"id":169,"html":170,"type":142},"b10","\u003Cp>The standard recipe looks like this, and you&#39;ve written some version of it:\u003C\u002Fp>",{"id":172,"code":173,"type":174,"language":123,"highlight":175},"b11","\u003Clabel class=\"switch\">\n  \u003Cinput type=\"checkbox\" \u002F>\n  \u003Cspan class=\"slider\">\u003C\u002Fspan>\n\u003C\u002Flabel>","code",[],{"id":177,"code":178,"type":174,"language":78,"highlight":179},"b12",".switch input { position: absolute; opacity: 0; }\n.switch .slider {\n  display: inline-block; width: 44px; height: 24px;\n  background: #ccc; border-radius: 999px; position: relative;\n  transition: background-color 0.2s;\n}\n.slider::before {\n  content: \"\"; position: absolute; width: 20px; height: 20px;\n  left: 2px; top: 2px; border-radius: 50%; background: white;\n  transition: transform 0.2s;\n}\ninput:checked + .slider { background: #2563eb; }\ninput:checked + .slider::before { transform: translateX(20px); }",[],{"id":181,"html":182,"type":142},"b13","\u003Cp>It works. It looks right. Click it, and it slides. Ship it, right?\u003C\u002Fp>",{"id":184,"html":185,"type":142},"b14","\u003Cp>Here&#39;s the question that doesn&#39;t get asked before shipping: what does a screen reader say when it lands on that control?\u003C\u002Fp>",{"id":187,"html":188,"type":142},"b15","\u003Cp>By default, VoiceOver and NVDA announce it as a \u003Cstrong>checkbox\u003C\u002Fstrong> — &quot;checked&quot; or &quot;not checked&quot; — because, structurally, that&#39;s exactly what it is. A \u003Ccode>&lt;span&gt;\u003C\u002Fcode> that \u003Cem>looks\u003C\u002Fem> like a switch doesn&#39;t change what the underlying \u003Ccode>&lt;input&gt;\u003C\u002Fcode> reports to the accessibility tree. A sighted user sees a switch flip to blue and &quot;ON.&quot; A screen reader user hears &quot;checkbox, checked,&quot; with zero indication that this control is binary state, not a list-item selection.\u003C\u002Fp>",{"id":190,"html":191,"type":142},"b16","\u003Cp>Fixing it means one more line most implementations forget:\u003C\u002Fp>",{"id":193,"code":194,"type":174,"language":123,"highlight":195},"b17","\u003Cinput type=\"checkbox\" role=\"switch\" \u002F>",[],{"id":197,"html":198,"type":142},"b18","\u003Cp>\u003Ccode>role=&quot;switch&quot;\u003C\u002Fcode> overrides the implicit ARIA role so the control announces &quot;on&quot; \u002F &quot;off&quot; instead of &quot;checked&quot; \u002F &quot;unchecked&quot; — functionally identical to checkbox semantics, just the right vocabulary for a binary state toggle rather than a selection. It&#39;s a one-line fix. It&#39;s also the line that&#39;s missing from a lot of toggle switches in production, because nothing fails loudly when you skip it. The control still \u003Cem>works\u003C\u002Fem>. It&#39;s just wrong for anyone who can&#39;t see it slide.\u003C\u002Fp>",{"id":200,"html":201,"text":201,"type":155,"level":31},"b19","Safari shipped the fix as an attribute",{"id":203,"html":204,"type":142},"b20","\u003Cp>In Safari 17.4, WebKit shipped a native switch control — not a new element, an attribute on the one you already have:\u003C\u002Fp>",{"id":206,"code":207,"type":174,"language":123,"highlight":208},"b21","\u003Cinput type=\"checkbox\" switch \u002F>",[],{"id":210,"html":211,"type":142},"b22","\u003Cp>Add \u003Ccode>switch\u003C\u002Fcode>, and three things happen in supporting browsers, for free:\u003C\u002Fp>",{"id":213,"type":214,"items":215,"ordered":18},"b23","list",[216,217,218],"\u003Cstrong>The implicit ARIA role flips from \u003Ccode>checkbox\u003C\u002Fcode> to \u003Ccode>switch\u003C\u002Fcode>.\u003C\u002Fstrong> VoiceOver announces &quot;on&quot; \u002F &quot;off,&quot; not &quot;checked&quot; \u002F &quot;unchecked&quot; — no \u003Ccode>role=\u003C\u002Fcode> attribute required.","\u003Cstrong>It renders as an actual toggle\u003C\u002Fstrong> — a track and a thumb, matching the platform&#39;s native switch look, not a checkbox with a CSS costume.","\u003Cstrong>It drops the indeterminate state.\u003C\u002Fstrong> A \u003Ccode>&lt;input type=&quot;checkbox&quot;&gt;\u003C\u002Fcode> can be put into a third, indeterminate visual state via JS (\u003Ccode>.indeterminate = true\u003C\u002Fcode>) for &quot;some of these are checked.&quot; A switch is binary by definition — on or off, nothing between — so that state doesn&#39;t apply to it. If your &quot;select all&quot; checkbox relies on indeterminate, that one stays a plain checkbox; the \u003Ccode>switch\u003C\u002Fcode> attribute is for genuinely binary toggles.",{"id":220,"html":221,"type":142},"b24","\u003Cp>Where Safari doesn&#39;t support it — and as of this writing, that&#39;s everywhere except Safari — the attribute is simply ignored. The element falls back to being exactly what it already was: a normal, unstyled checkbox. Nothing breaks. You don&#39;t get the switch look, but you don&#39;t get an error either. That&#39;s the detail that makes it safe to ship today, and the detail every single-browser feature on this blog gets tested on: does the unsupported path look \u003Cem>broken\u003C\u002Fem>, or just \u003Cem>plain\u003C\u002Fem>? Here, it&#39;s plain.\u003C\u002Fp>",{"id":223,"html":224,"type":142},"b25","\u003Cp>You can feature-detect it directly, no sniffing required:\u003C\u002Fp>",{"id":226,"code":227,"type":174,"language":228,"highlight":229},"b26","const supportsSwitch = \"switch\" in document.createElement(\"input\");","js",[],{"id":231,"html":232,"text":232,"type":155,"level":31},"b27","Ship the real thing everywhere, today",{"id":234,"html":235,"type":142},"b28","\u003Cp>Here&#39;s the part worth taking away even if you never ship to Safari-only users: you don&#39;t have to choose between &quot;wait for every browser&quot; and &quot;build the five-element costume.&quot; Combine the native attribute with the manual fix from two sections ago, and every browser gets a \u003Cem>correct\u003C\u002Fem> switch — Safari just gets a nicer-looking one for free:\u003C\u002Fp>",{"id":237,"code":238,"type":174,"language":123,"highlight":239},"b29","\u003Cinput type=\"checkbox\" switch role=\"switch\" \u002F>",[],{"id":241,"code":242,"type":174,"language":78,"highlight":243},"b30","input[type=\"checkbox\"][role=\"switch\"] {\n  appearance: none;\n  width: 44px; height: 24px;\n  background: #ccc; border-radius: 999px;\n  position: relative; transition: background-color 0.2s;\n  cursor: pointer;\n}\ninput[type=\"checkbox\"][role=\"switch\"]::before {\n  content: \"\"; position: absolute; width: 20px; height: 20px;\n  left: 2px; top: 2px; border-radius: 50%; background: white;\n  transition: transform 0.2s;\n}\ninput[type=\"checkbox\"][role=\"switch\"]:checked {\n  background: #2563eb;\n}\ninput[type=\"checkbox\"][role=\"switch\"]:checked::before {\n  transform: translateX(20px);\n}",[],{"id":245,"html":246,"type":142},"b31","\u003Cp>\u003Ccode>appearance: none\u003C\u002Fcode> strips the native checkbox box in \u003Cem>every\u003C\u002Fem> browser, Safari included — so your CSS draws the track and thumb everywhere, same costume as before, minus the extra \u003Ccode>&lt;span&gt;\u003C\u002Fcode> and extra markup, because the \u003Ccode>::before\u003C\u002Fcode> pseudo-element now draws directly on the real control. Worth being precise here: adding \u003Ccode>switch\u003C\u002Fcode> doesn&#39;t hand rendering to Safari on its own, because \u003Ccode>appearance: none\u003C\u002Fcode> opts your own CSS out of native rendering there too, the same as it does in every other engine. What the attribute buys you today, even underneath your own CSS, is the free implicit-role flip and the dropped indeterminate state — the same contract \u003Ccode>role=&quot;switch&quot;\u003C\u002Fcode> already gives you, just enforced by the platform instead of by you. If you actually want Safari&#39;s native track and thumb, leave \u003Ccode>appearance\u003C\u002Fcode> alone there and reach for the experimental, flag-gated \u003Ccode>::thumb\u003C\u002Fcode> and \u003Ccode>::track\u003C\u002Fcode> pseudo-elements instead — not something to depend on yet. Either way, \u003Ccode>role=&quot;switch&quot;\u003C\u002Fcode> guarantees the accessibility tree is right regardless of which path rendered the control.\u003C\u002Fp>",{"id":248,"html":249,"type":142},"b32","\u003Cp>One attribute removed the CSS hack&#39;s biggest failure mode — and it did it by fixing the markup, not by giving you a better \u003Ccode>&lt;span&gt;\u003C\u002Fcode> to style.\u003C\u002Fp>",{"id":251,"html":252,"text":252,"type":155,"level":31},"b33","The question worth asking about your own toggles",{"id":254,"html":255,"type":142},"b34","\u003Cp>Go find the toggle switches already live on something you&#39;ve shipped. Open devtools, click into the accessibility tree, and check what role is actually attached to the control under that slider.\u003C\u002Fp>",{"id":257,"html":258,"type":142},"b35","\u003Cp>If it says &quot;checkbox&quot; with no \u003Ccode>role=&quot;switch&quot;\u003C\u002Fcode> next to it, that&#39;s not a bug anyone will file — nobody files a bug for a control that visually works. It&#39;s just quietly wrong for a user you&#39;ve never heard from. Fix it today; it&#39;s one attribute, and unlike the Safari-only \u003Ccode>switch\u003C\u002Fcode> keyword, \u003Ccode>role=&quot;switch&quot;\u003C\u002Fcode> works everywhere right now.\u003C\u002Fp>",{"id":260,"html":261,"type":142},"b36","\u003Cp>What does yours say?\u003C\u002Fp>",{"id":263,"html":264,"type":142},"b37","\u003C!-- quiz:start -->",{"id":266,"html":267,"text":267,"type":155,"level":31},"b38","🧠 Test yourself",{"id":269,"html":270,"type":142},"b39","\u003Cp>Think it clicked? \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fcheckbox-switch-native-toggle\u002Fquiz\">Take the 8-question quiz →\u003C\u002Fa>\u003C\u002Fstrong>\u003C\u002Fp>",{"id":272,"html":273,"type":142},"b40","\u003Cp>\u003Cem>Instant feedback, a hint on every question, and an explanation for each answer — right or wrong.\u003C\u002Fem>\u003C\u002Fp>",{"id":275,"html":276,"type":142},"b41","\u003C!-- quiz:end -->",{"id":278,"html":279,"type":142},"b42","\u003C!-- related:start -->",{"id":281,"html":282,"text":282,"type":155,"level":31},"b43","📚 Read next",{"id":284,"type":214,"items":285,"ordered":18},"b44",[286,287,288],"\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fcustomizable-select-appearance-base-select\">The Dropdown You&#39;ve Been Faking for a Decade\u003C\u002Fa>","\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fdetails-name-exclusive-accordion\">Stop Hand-Rolling an Exclusive Accordion. \u003Ccode>&lt;details name&gt;\u003C\u002Fcode> Does It\u003C\u002Fa>","\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Finert-attribute-disable-interaction\">The Modal Was Open. So Was Everything Behind It.\u003C\u002Fa>",{"id":290,"html":291,"type":142},"b45","\u003C!-- related:end -->",{"id":293,"type":294},"b46","divider",{"id":296,"html":297,"type":142},"b47","\u003Cp>🚀 \u003Cstrong>Want more like this?\u003C\u002Fstrong> Every guide, playground, and quiz lives on \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002F\">bestpractic.org\u003C\u002Fa>\u003C\u002Fstrong> — open it and \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002F\">sign up free\u003C\u002Fa>\u003C\u002Fstrong> so the next one finds you.\u003C\u002Fp>",{"id":299,"html":300,"type":142},"b48","\u003Cp>\u003Cem>Thanks for reading! Let&#39;s stay connected:\u003C\u002Fem>\u003C\u002Fp>",{"id":302,"type":214,"items":303,"ordered":18},"b49",[304,305,306],"⭐ \u003Cstrong>GitHub\u003C\u002Fstrong> — follow me and star the projects: \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fparsajiravand\">github.com\u002Fparsajiravand\u003C\u002Fa>","💬 \u003Cstrong>Discord\u003C\u002Fstrong> — join the frontend best-practices community: \u003Ca href=\"https:\u002F\u002Fdiscord.gg\u002Fd9KRhuAwQ\">discord.gg\u002Fd9KRhuAwQ\u003C\u002Fa>","📸 \u003Cstrong>Instagram\u003C\u002Fstrong> — frontend best practices, daily: \u003Ca href=\"https:\u002F\u002Fwww.instagram.com\u002Fbestpractice___\u002F\">@bestpractice___\u003C\u002Fa>","Open any settings page you've shipped. Find the toggle switch next to \"Dark mode\" or \"Email notifications.\" Now open devtools and count the elements it took to build it.\n\nIt's almost never one. It's a `\u003Clabel>` wrapping a visually-hidden `\u003Cinput type=\"checkbox\">`, a `\u003Cspan class=\"slider\">` drawing the track, a `::before` pseudo-element drawing the thumb, a CSS transition moving it, and — if whoever built it remembered — an ARIA role telling assistive tech what it actually is.\n\nThat last part is the one that gets skipped. Here's the part that stings: even when it isn't, the browser's own form control can't just *be* a switch. You have to tell it to pretend.\n\n\u003C!-- playground:start -->\n\n## 🎮 Try it yourself\n\n**[▶️ Open the interactive playground →](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fcheckbox-switch-native-toggle\u002Fplayground)**\n\n_Runs right in your browser — poke at it and watch the concept react live._\n\n\u003C!-- playground:end -->\n\n## The costume everyone builds\n\nThe standard recipe looks like this, and you've written some version of it:\n\n```html\n\u003Clabel class=\"switch\">\n  \u003Cinput type=\"checkbox\" \u002F>\n  \u003Cspan class=\"slider\">\u003C\u002Fspan>\n\u003C\u002Flabel>\n```\n\n```css\n.switch input { position: absolute; opacity: 0; }\n.switch .slider {\n  display: inline-block; width: 44px; height: 24px;\n  background: #ccc; border-radius: 999px; position: relative;\n  transition: background-color 0.2s;\n}\n.slider::before {\n  content: \"\"; position: absolute; width: 20px; height: 20px;\n  left: 2px; top: 2px; border-radius: 50%; background: white;\n  transition: transform 0.2s;\n}\ninput:checked + .slider { background: #2563eb; }\ninput:checked + .slider::before { transform: translateX(20px); }\n```\n\nIt works. It looks right. Click it, and it slides. Ship it, right?\n\nHere's the question that doesn't get asked before shipping: what does a screen reader say when it lands on that control?\n\nBy default, VoiceOver and NVDA announce it as a **checkbox** — \"checked\" or \"not checked\" — because, structurally, that's exactly what it is. A `\u003Cspan>` that *looks* like a switch doesn't change what the underlying `\u003Cinput>` reports to the accessibility tree. A sighted user sees a switch flip to blue and \"ON.\" A screen reader user hears \"checkbox, checked,\" with zero indication that this control is binary state, not a list-item selection.\n\nFixing it means one more line most implementations forget:\n\n```html\n\u003Cinput type=\"checkbox\" role=\"switch\" \u002F>\n```\n\n`role=\"switch\"` overrides the implicit ARIA role so the control announces \"on\" \u002F \"off\" instead of \"checked\" \u002F \"unchecked\" — functionally identical to checkbox semantics, just the right vocabulary for a binary state toggle rather than a selection. It's a one-line fix. It's also the line that's missing from a lot of toggle switches in production, because nothing fails loudly when you skip it. The control still *works*. It's just wrong for anyone who can't see it slide.\n\n## Safari shipped the fix as an attribute\n\nIn Safari 17.4, WebKit shipped a native switch control — not a new element, an attribute on the one you already have:\n\n```html\n\u003Cinput type=\"checkbox\" switch \u002F>\n```\n\nAdd `switch`, and three things happen in supporting browsers, for free:\n\n- **The implicit ARIA role flips from `checkbox` to `switch`.** VoiceOver announces \"on\" \u002F \"off,\" not \"checked\" \u002F \"unchecked\" — no `role=` attribute required.\n- **It renders as an actual toggle** — a track and a thumb, matching the platform's native switch look, not a checkbox with a CSS costume.\n- **It drops the indeterminate state.** A `\u003Cinput type=\"checkbox\">` can be put into a third, indeterminate visual state via JS (`.indeterminate = true`) for \"some of these are checked.\" A switch is binary by definition — on or off, nothing between — so that state doesn't apply to it. If your \"select all\" checkbox relies on indeterminate, that one stays a plain checkbox; the `switch` attribute is for genuinely binary toggles.\n\nWhere Safari doesn't support it — and as of this writing, that's everywhere except Safari — the attribute is simply ignored. The element falls back to being exactly what it already was: a normal, unstyled checkbox. Nothing breaks. You don't get the switch look, but you don't get an error either. That's the detail that makes it safe to ship today, and the detail every single-browser feature on this blog gets tested on: does the unsupported path look *broken*, or just *plain*? Here, it's plain.\n\nYou can feature-detect it directly, no sniffing required:\n\n```js\nconst supportsSwitch = \"switch\" in document.createElement(\"input\");\n```\n\n## Ship the real thing everywhere, today\n\nHere's the part worth taking away even if you never ship to Safari-only users: you don't have to choose between \"wait for every browser\" and \"build the five-element costume.\" Combine the native attribute with the manual fix from two sections ago, and every browser gets a *correct* switch — Safari just gets a nicer-looking one for free:\n\n```html\n\u003Cinput type=\"checkbox\" switch role=\"switch\" \u002F>\n```\n\n```css\ninput[type=\"checkbox\"][role=\"switch\"] {\n  appearance: none;\n  width: 44px; height: 24px;\n  background: #ccc; border-radius: 999px;\n  position: relative; transition: background-color 0.2s;\n  cursor: pointer;\n}\ninput[type=\"checkbox\"][role=\"switch\"]::before {\n  content: \"\"; position: absolute; width: 20px; height: 20px;\n  left: 2px; top: 2px; border-radius: 50%; background: white;\n  transition: transform 0.2s;\n}\ninput[type=\"checkbox\"][role=\"switch\"]:checked {\n  background: #2563eb;\n}\ninput[type=\"checkbox\"][role=\"switch\"]:checked::before {\n  transform: translateX(20px);\n}\n```\n\n`appearance: none` strips the native checkbox box in *every* browser, Safari included — so your CSS draws the track and thumb everywhere, same costume as before, minus the extra `\u003Cspan>` and extra markup, because the `::before` pseudo-element now draws directly on the real control. Worth being precise here: adding `switch` doesn't hand rendering to Safari on its own, because `appearance: none` opts your own CSS out of native rendering there too, the same as it does in every other engine. What the attribute buys you today, even underneath your own CSS, is the free implicit-role flip and the dropped indeterminate state — the same contract `role=\"switch\"` already gives you, just enforced by the platform instead of by you. If you actually want Safari's native track and thumb, leave `appearance` alone there and reach for the experimental, flag-gated `::thumb` and `::track` pseudo-elements instead — not something to depend on yet. Either way, `role=\"switch\"` guarantees the accessibility tree is right regardless of which path rendered the control.\n\nOne attribute removed the CSS hack's biggest failure mode — and it did it by fixing the markup, not by giving you a better `\u003Cspan>` to style.\n\n## The question worth asking about your own toggles\n\nGo find the toggle switches already live on something you've shipped. Open devtools, click into the accessibility tree, and check what role is actually attached to the control under that slider.\n\nIf it says \"checkbox\" with no `role=\"switch\"` next to it, that's not a bug anyone will file — nobody files a bug for a control that visually works. It's just quietly wrong for a user you've never heard from. Fix it today; it's one attribute, and unlike the Safari-only `switch` keyword, `role=\"switch\"` works everywhere right now.\n\nWhat does yours say?\n\n\u003C!-- quiz:start -->\n\n## 🧠 Test yourself\n\nThink it clicked? **[Take the 8-question quiz →](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fcheckbox-switch-native-toggle\u002Fquiz)**\n\n_Instant feedback, a hint on every question, and an explanation for each answer — right or wrong._\n\n\u003C!-- quiz:end -->\n\n\u003C!-- related:start -->\n\n## 📚 Read next\n\n- [The Dropdown You've Been Faking for a Decade](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fcustomizable-select-appearance-base-select)\n- [Stop Hand-Rolling an Exclusive Accordion. `\u003Cdetails name>` Does It](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fdetails-name-exclusive-accordion)\n- [The Modal Was Open. So Was Everything Behind It.](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Finert-attribute-disable-interaction)\n\n\u003C!-- related:end -->\n\n---\n\n🚀 **Want more like this?** Every guide, playground, and quiz lives on **[bestpractic.org](https:\u002F\u002Fbestpractic.org\u002F)** — open it and **[sign up free](https:\u002F\u002Fbestpractic.org\u002F)** so the next one finds you.\n\n*Thanks for reading! Let's stay connected:*\n\n- ⭐ **GitHub** — follow me and star the projects: [github.com\u002Fparsajiravand](https:\u002F\u002Fgithub.com\u002Fparsajiravand)\n- 💬 **Discord** — join the frontend best-practices community: [discord.gg\u002Fd9KRhuAwQ](https:\u002F\u002Fdiscord.gg\u002Fd9KRhuAwQ)\n- 📸 **Instagram** — frontend best practices, daily: [@bestpractice___](https:\u002F\u002Fwww.instagram.com\u002Fbestpractice___\u002F)",{"title":111,"canonical":309,"description":310},"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fcheckbox-switch-native-toggle","Every settings page has a toggle switch, and almost every one of them is a checkbox wearing a costume: a label, a span, a ::before, a transition, and — if someone remembered — a ro","01a21cc5-8784-732c-a79f-3a5d5f835dd4",{"id":313,"locked":18},"01a21cc5-879f-75bf-b786-23f192a7b7fe",[315],{"id":45,"slug":46,"title":48,"_count":316},{"questions":51},[318],{"locale":13,"slug":46},{"id":45,"slug":46,"title":48,"_count":320,"questionCount":51},{"questions":51},[]]