20 Pure CSS Toggles & Switches
Sliding Pill with Label
A track containing both labels (ON / OFF) with a thumb that slides over the active one. Common SaaS-dashboard pattern — the label IS the indicator.
Sliding Pill with Label the 14th of 20 designs in the 20 Pure CSS Toggles & Switches collection. The design is implemented in pure CSS — no JavaScript required. Copy the HTML and CSS panels below into your project. Because the demo is pure CSS, it works in any framework or templating engine you happen to use. The design honours prefers-reduced-motion and uses real semantic markup, so it ships accessibility-ready out of the box.
Live preview
The code
<label class="tg-pill">
<input class="tg-pill-input" type="checkbox" checked>
<span class="tg-pill-track" aria-hidden="true">
<span class="tg-pill-text tg-pill-on">ON</span>
<span class="tg-pill-text tg-pill-off">OFF</span>
<span class="tg-pill-thumb"></span>
</span>
<span class="tg-pill-label">Public profile</span>
</label> .tg-pill {
display: inline-flex;
align-items: center;
gap: 12px;
cursor: pointer;
font-family: "Inter", "Segoe UI", system-ui, sans-serif;
font-size: 14px;
color: #f0eeff;
user-select: none;
}
.tg-pill-input {
position: absolute;
width: 1px; height: 1px;
padding: 0; margin: -1px;
overflow: hidden; clip: rect(0,0,0,0);
white-space: nowrap; border: 0;
}
.tg-pill-track {
position: relative;
width: 76px;
height: 28px;
background: #2a2a30;
border-radius: 999px;
display: grid;
grid-template-columns: 1fr 1fr;
align-items: center;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
transition: background 0.25s ease;
}
.tg-pill-text {
position: relative;
z-index: 2;
text-align: center;
transition: color 0.25s ease;
pointer-events: none;
}
.tg-pill-on { color: #7c6cff; }
.tg-pill-off { color: #6a6a7a; }
.tg-pill-thumb {
position: absolute;
top: 2px;
left: 2px;
width: calc(50% - 2px);
height: calc(100% - 4px);
background: #f0eeff;
border-radius: 999px;
z-index: 1;
transition: left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.tg-pill-input:checked ~ .tg-pill-track .tg-pill-on { color: #1a1a1a; }
.tg-pill-input:checked ~ .tg-pill-track .tg-pill-off { color: #6a6a7a; }
.tg-pill-input:not(:checked) ~ .tg-pill-track .tg-pill-on { color: #6a6a7a; }
.tg-pill-input:not(:checked) ~ .tg-pill-track .tg-pill-off { color: #1a1a1a; }
.tg-pill-input:not(:checked) ~ .tg-pill-track .tg-pill-thumb {
left: 50%;
}
.tg-pill-input:focus-visible ~ .tg-pill-track {
outline: 2px solid #7c6cff;
outline-offset: 3px;
}
@media (prefers-reduced-motion: reduce) {
.tg-pill-thumb,
.tg-pill-text,
.tg-pill-track { transition: none; }
}