47 CSS Toggles & Switches24 / 47
Outline Minimal currentColor Toggle
A stroke-only switch drawn entirely in currentColor: hollow track, hollow thumb that fills solid when on. Because it inherits its color from surrounding text, the SAME markup works on light cards, dark cards and brand-colored banners with zero per-theme CSS.
Published
The code
<section class="tgl-24" aria-label="Outline currentColor toggles">
<div class="tgl-24__chips">
<label class="tgl-24__chip tgl-24__chip--light"><span>Autosave</span><input type="checkbox" class="tgl-24__sw" role="switch" checked></label>
<label class="tgl-24__chip tgl-24__chip--dark"><span>Autosave</span><input type="checkbox" class="tgl-24__sw" role="switch" checked></label>
<label class="tgl-24__chip tgl-24__chip--brand"><span>Autosave</span><input type="checkbox" class="tgl-24__sw" role="switch"></label>
</div>
<p class="tgl-24__cap">One switch · three themes · zero theme CSS</p>
</section><section class="tgl-24" aria-label="Outline currentColor toggles">
<div class="tgl-24__chips">
<label class="tgl-24__chip tgl-24__chip--light"><span>Autosave</span><input type="checkbox" class="tgl-24__sw" role="switch" checked></label>
<label class="tgl-24__chip tgl-24__chip--dark"><span>Autosave</span><input type="checkbox" class="tgl-24__sw" role="switch" checked></label>
<label class="tgl-24__chip tgl-24__chip--brand"><span>Autosave</span><input type="checkbox" class="tgl-24__sw" role="switch"></label>
</div>
<p class="tgl-24__cap">One switch · three themes · zero theme CSS</p>
</section>.tgl-24,
.tgl-24 *,
.tgl-24 *::before,
.tgl-24 *::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.tgl-24 {
font-family: 'Segoe UI',system-ui,sans-serif;
width: 100%;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 26px;
padding: 60px 20px;
background: #f4f4f2;
}
.tgl-24__chips {
display: flex;
flex-wrap: wrap;
gap: 16px;
justify-content: center;
}
.tgl-24__chip {
display: flex;
align-items: center;
gap: 18px;
padding: 16px 22px;
border-radius: 14px;
cursor: pointer;
font-size: 15px;
font-weight: 600;
}
.tgl-24__chip--light {
background: #fff;
color: #26292f;
border: 1px solid #e3e3df;
}
.tgl-24__chip--dark {
background: #1d1f24;
color: #e8e9ec;
}
.tgl-24__chip--brand {
background: oklch(0.55 0.15 265);
color: #fff;
}
.tgl-24__sw {
appearance: none;
-webkit-appearance: none;
flex: none;
width: 56px;
height: 32px;
border-radius: 17px;
border: 2px solid currentColor;
background: transparent;
color: inherit;
position: relative;
cursor: pointer;
}
.tgl-24__sw::before {
content: "";
position: absolute;
top: 3px;
left: 3px;
width: 20px;
height: 20px;
border-radius: 50%;
border: 2px solid currentColor;
background: transparent;
transition: transform .3s cubic-bezier(.3,1,.35,1.05),background-color .3s;
}
.tgl-24__sw:checked::before {
transform: translateX(24px);
background: currentColor;
}
.tgl-24__sw:focus-visible {
outline: 3px solid currentColor;
outline-offset: 3px;
}
.tgl-24__cap {
font-size: 12px;
letter-spacing: .12em;
text-transform: uppercase;
color: #a2a29a;
}
@media (prefers-reduced-motion: reduce) {
.tgl-24__sw::before {
transition: none;
}
}.tgl-24,
.tgl-24 *,
.tgl-24 *::before,
.tgl-24 *::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.tgl-24 {
font-family: 'Segoe UI',system-ui,sans-serif;
width: 100%;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 26px;
padding: 60px 20px;
background: #f4f4f2;
}
.tgl-24__chips {
display: flex;
flex-wrap: wrap;
gap: 16px;
justify-content: center;
}
.tgl-24__chip {
display: flex;
align-items: center;
gap: 18px;
padding: 16px 22px;
border-radius: 14px;
cursor: pointer;
font-size: 15px;
font-weight: 600;
}
.tgl-24__chip--light {
background: #fff;
color: #26292f;
border: 1px solid #e3e3df;
}
.tgl-24__chip--dark {
background: #1d1f24;
color: #e8e9ec;
}
.tgl-24__chip--brand {
background: oklch(0.55 0.15 265);
color: #fff;
}
.tgl-24__sw {
appearance: none;
-webkit-appearance: none;
flex: none;
width: 56px;
height: 32px;
border-radius: 17px;
border: 2px solid currentColor;
background: transparent;
color: inherit;
position: relative;
cursor: pointer;
}
.tgl-24__sw::before {
content: "";
position: absolute;
top: 3px;
left: 3px;
width: 20px;
height: 20px;
border-radius: 50%;
border: 2px solid currentColor;
background: transparent;
transition: transform .3s cubic-bezier(.3,1,.35,1.05),background-color .3s;
}
.tgl-24__sw:checked::before {
transform: translateX(24px);
background: currentColor;
}
.tgl-24__sw:focus-visible {
outline: 3px solid currentColor;
outline-offset: 3px;
}
.tgl-24__cap {
font-size: 12px;
letter-spacing: .12em;
text-transform: uppercase;
color: #a2a29a;
}
@media (prefers-reduced-motion: reduce) {
.tgl-24__sw::before {
transition: none;
}
}/* No JavaScript — every stroke and fill is currentColor, so the identical switch inherits each container's text color; checked fills the hollow thumb solid. */
/* No JavaScript — every stroke and fill is currentColor, so the identical switch inherits each container's text color; checked fills the hollow thumb solid. */Here's a working CSS Toggles & Switche from CodeFronts. Use it as-is or adapt to your framework. All classes are scoped under a unique prefix so the code won't collide with your existing styles. MIT licensed.
Demo: Outline Minimal currentColor Toggle
Source: https://codefronts.com/components/css-toggles-switches/outline-minimal-currentcolor-toggle/
A stroke-only switch drawn entirely in currentColor: hollow track, hollow thumb that fills solid when on. Because it inherits its color from surrounding text, the SAME markup works on light cards, dark cards and brand-colored banners with zero per-theme CSS.
## HTML
```html
<section class="tgl-24" aria-label="Outline currentColor toggles">
<div class="tgl-24__chips">
<label class="tgl-24__chip tgl-24__chip--light"><span>Autosave</span><input type="checkbox" class="tgl-24__sw" role="switch" checked></label>
<label class="tgl-24__chip tgl-24__chip--dark"><span>Autosave</span><input type="checkbox" class="tgl-24__sw" role="switch" checked></label>
<label class="tgl-24__chip tgl-24__chip--brand"><span>Autosave</span><input type="checkbox" class="tgl-24__sw" role="switch"></label>
</div>
<p class="tgl-24__cap">One switch · three themes · zero theme CSS</p>
</section>
```
## CSS
```css
.tgl-24,
.tgl-24 *,
.tgl-24 *::before,
.tgl-24 *::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.tgl-24 {
font-family: 'Segoe UI',system-ui,sans-serif;
width: 100%;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 26px;
padding: 60px 20px;
background: #f4f4f2;
}
.tgl-24__chips {
display: flex;
flex-wrap: wrap;
gap: 16px;
justify-content: center;
}
.tgl-24__chip {
display: flex;
align-items: center;
gap: 18px;
padding: 16px 22px;
border-radius: 14px;
cursor: pointer;
font-size: 15px;
font-weight: 600;
}
.tgl-24__chip--light {
background: #fff;
color: #26292f;
border: 1px solid #e3e3df;
}
.tgl-24__chip--dark {
background: #1d1f24;
color: #e8e9ec;
}
.tgl-24__chip--brand {
background: oklch(0.55 0.15 265);
color: #fff;
}
.tgl-24__sw {
appearance: none;
-webkit-appearance: none;
flex: none;
width: 56px;
height: 32px;
border-radius: 17px;
border: 2px solid currentColor;
background: transparent;
color: inherit;
position: relative;
cursor: pointer;
}
.tgl-24__sw::before {
content: "";
position: absolute;
top: 3px;
left: 3px;
width: 20px;
height: 20px;
border-radius: 50%;
border: 2px solid currentColor;
background: transparent;
transition: transform .3s cubic-bezier(.3,1,.35,1.05),background-color .3s;
}
.tgl-24__sw:checked::before {
transform: translateX(24px);
background: currentColor;
}
.tgl-24__sw:focus-visible {
outline: 3px solid currentColor;
outline-offset: 3px;
}
.tgl-24__cap {
font-size: 12px;
letter-spacing: .12em;
text-transform: uppercase;
color: #a2a29a;
}
@media (prefers-reduced-motion: reduce) {
.tgl-24__sw::before {
transition: none;
}
}
```
## JavaScript
```js
/* No JavaScript — every stroke and fill is currentColor, so the identical switch inherits each container's text color; checked fills the hollow thumb solid. */
```Here's a working CSS Toggles & Switche from CodeFronts. Use it as-is or adapt to your framework. All classes are scoped under a unique prefix so the code won't collide with your existing styles. MIT licensed.
Demo: Outline Minimal currentColor Toggle
Source: https://codefronts.com/components/css-toggles-switches/outline-minimal-currentcolor-toggle/
A stroke-only switch drawn entirely in currentColor: hollow track, hollow thumb that fills solid when on. Because it inherits its color from surrounding text, the SAME markup works on light cards, dark cards and brand-colored banners with zero per-theme CSS.
## HTML
```html
<section class="tgl-24" aria-label="Outline currentColor toggles">
<div class="tgl-24__chips">
<label class="tgl-24__chip tgl-24__chip--light"><span>Autosave</span><input type="checkbox" class="tgl-24__sw" role="switch" checked></label>
<label class="tgl-24__chip tgl-24__chip--dark"><span>Autosave</span><input type="checkbox" class="tgl-24__sw" role="switch" checked></label>
<label class="tgl-24__chip tgl-24__chip--brand"><span>Autosave</span><input type="checkbox" class="tgl-24__sw" role="switch"></label>
</div>
<p class="tgl-24__cap">One switch · three themes · zero theme CSS</p>
</section>
```
## CSS
```css
.tgl-24,
.tgl-24 *,
.tgl-24 *::before,
.tgl-24 *::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.tgl-24 {
font-family: 'Segoe UI',system-ui,sans-serif;
width: 100%;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 26px;
padding: 60px 20px;
background: #f4f4f2;
}
.tgl-24__chips {
display: flex;
flex-wrap: wrap;
gap: 16px;
justify-content: center;
}
.tgl-24__chip {
display: flex;
align-items: center;
gap: 18px;
padding: 16px 22px;
border-radius: 14px;
cursor: pointer;
font-size: 15px;
font-weight: 600;
}
.tgl-24__chip--light {
background: #fff;
color: #26292f;
border: 1px solid #e3e3df;
}
.tgl-24__chip--dark {
background: #1d1f24;
color: #e8e9ec;
}
.tgl-24__chip--brand {
background: oklch(0.55 0.15 265);
color: #fff;
}
.tgl-24__sw {
appearance: none;
-webkit-appearance: none;
flex: none;
width: 56px;
height: 32px;
border-radius: 17px;
border: 2px solid currentColor;
background: transparent;
color: inherit;
position: relative;
cursor: pointer;
}
.tgl-24__sw::before {
content: "";
position: absolute;
top: 3px;
left: 3px;
width: 20px;
height: 20px;
border-radius: 50%;
border: 2px solid currentColor;
background: transparent;
transition: transform .3s cubic-bezier(.3,1,.35,1.05),background-color .3s;
}
.tgl-24__sw:checked::before {
transform: translateX(24px);
background: currentColor;
}
.tgl-24__sw:focus-visible {
outline: 3px solid currentColor;
outline-offset: 3px;
}
.tgl-24__cap {
font-size: 12px;
letter-spacing: .12em;
text-transform: uppercase;
color: #a2a29a;
}
@media (prefers-reduced-motion: reduce) {
.tgl-24__sw::before {
transition: none;
}
}
```
## JavaScript
```js
/* No JavaScript — every stroke and fill is currentColor, so the identical switch inherits each container's text color; checked fills the hollow thumb solid. */
```How this works
Every visible part uses currentColor: the track is a 2px border with transparent fill; the thumb a 2px-bordered circle that gains background:currentColor when checked. No hex codes appear in the switch rules at all — drop it into any container and it matches that container's text color, including hover and dark-mode recolors, for free.
State is double-encoded despite the minimalism: thumb position AND fill density (hollow = off, solid = on), so it survives grayscale and low vision. The demo shows one identical switch inside three differently-themed chips to prove the inheritance.
Make it yours
- Thicken to 3px strokes for display contexts.
- Let the on-state tint: add color:var(--accent) on :checked to shift only when on.
- Square variant: radius 6px on track and thumb.
- Animate the fill with a scale-up ::after instead of background for a pop-in.
Gotchas — read before shipping
- currentColor resolves at the element — if the switch sits in muted 50%-gray text, the control is 50% gray too; wrap it or reset color where contrast would fail.
- Keep the hollow/solid distinction — position-only state in a monochrome control fails color-independence.
- Border+transparent backgrounds hit sub-pixel rounding at odd zoom levels; even stroke widths (2px) render cleanest.
Browser support
| Chrome | Safari | Firefox | Edge |
|---|---|---|---|
| 111+ | 15.4+ | 113+ | 111+ |
Floor set by oklch() as this demo is written. The core technique itself goes back further — Chrome 1+.
currentColor is CSS2-era; this is the most portable demo in the collection.