# Icon Toggle Switch

> A toggle switch whose knob shows a cross when off and a check mark when on, so state is not shown by color alone.

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

## HTML

```html
<label class="tgl-icon">
  <input type="checkbox" role="switch">
  <span class="tgl-icon-track" aria-hidden="true"></span>
  Email alerts
</label>
```

## CSS

```css
.tgl-icon {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #500724;
  font: 500 15px system-ui, sans-serif;
  cursor: pointer;
}

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

.tgl-icon-track {
  position: relative;
  width: 56px;
  height: 32px;
  border-radius: 999px;
  background: #e4e4e7;
  transition: background 0.3s ease;
}

.tgl-icon-track::before {
  content: "✕";
  position: absolute;
  top: 4px;
  left: 4px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  color: #71717a;
  font-size: 12px;
  font-weight: 800;
  transition: transform 0.3s cubic-bezier(0.4, 1.4, 0.6, 1);
}

.tgl-icon input:checked + .tgl-icon-track {
  background: #db2777;
}

.tgl-icon input:checked + .tgl-icon-track::before {
  content: "✓";
  color: #db2777;
  transform: translateX(24px);
}

.tgl-icon input:focus-visible + .tgl-icon-track {
  outline: 2px solid #db2777;
  outline-offset: 3px;
}

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

## Notes

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