Skip to content
ZeroServer.tools

CSS Switch Generator

Generate pure CSS toggle switch styles with live preview. No JavaScript required.

#22d3ee
#d1d5db
#ffffff

Left: OFF  |  Right: ON

<label class="switch">
  <input type="checkbox">
  <span class="slider"></span>
</label>
/* CSS Toggle Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 28px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  background-color: #d1d5db;
  border-radius: 14px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.slider::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 4px;
  top: 4px;
  background-color: #ffffff;
  border-radius: 50%;
  transition: transform 0.3s;
}

input:checked + .slider {
  background-color: #22d3ee;
}

input:checked + .slider::before {
  transform: translateX(24px);
}

How CSS toggle switches work

A CSS switch uses a hidden checkbox input paired with a styled label. The :checked pseudo-class triggers background and transform changes. The knob is the ::before pseudo-element that slides via translateX. No JavaScript needed — accessibility is preserved because the real checkbox handles keyboard and screen reader interaction.

Private & free — this tool runs entirely in your browser.

Recommended: Kinsta Fast managed hosting — up to $500 + 10% recurring.affiliate

Related Design & CSS tools