# Labeled Toggle Switch

> A toggle switch with ON and OFF text inside the track and a visible label, built on a role="switch" checkbox.

- Category: [CSS Form Elements](https://copy-css.com/category/forms)
- Tags: toggle, switch, on off, role switch, checkbox, settings
- Live preview: https://copy-css.com/snippets/labeled-toggle-switch
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<label class="tgl-text">
  <span>Wi-Fi</span>
  <input type="checkbox" role="switch" checked>
  <span class="tgl-text-track" aria-hidden="true"></span>
</label>
```

## CSS

```css
.tgl-text {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: #0f172a;
  font: 600 15px system-ui, sans-serif;
  cursor: pointer;
}

.tgl-text input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.tgl-text-track {
  position: relative;
  width: 64px;
  height: 30px;
  border-radius: 999px;
  background: #cbd5e1;
  transition: background 0.25s ease;
}

.tgl-text-track::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.25s ease;
}

.tgl-text-track::after {
  content: "OFF";
  position: absolute;
  top: 50%;
  right: 9px;
  color: #475569;
  font-size: 10px;
  font-weight: 800;
  transform: translateY(-50%);
}

.tgl-text input:checked + .tgl-text-track {
  background: #2563eb;
}

.tgl-text input:checked + .tgl-text-track::before {
  transform: translateX(34px);
}

.tgl-text input:checked + .tgl-text-track::after {
  content: "ON";
  right: auto;
  left: 11px;
  color: #fff;
}

.tgl-text input:focus-visible + .tgl-text-track {
  outline: 2px solid #2563eb;
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  .tgl-text-track,
  .tgl-text-track::before {
    transition: none;
  }
}
```

## Notes

- This CSS Labeled Toggle Switch is 75 lines of pure CSS (1.3 KB) with no JavaScript and no dependencies. It uses transitions, transforms, box shadows and Flexbox.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
