CSS Switch Generator
Build custom CSS toggle switches with live preview — pill or rectangular, any color and size.
4096
Live preview
HTML
<label class="switch">
<input type="checkbox">
<span class="slider"></span>
</label>CSS
.switch {
position: relative;
display: inline-block;
width: 60px;
height: 30px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.switch .slider {
position: absolute;
inset: 0;
cursor: pointer;
background: #cbd5e1;
border-radius: 15px;
transition: background 0.3s ease;
}
.switch .slider::before {
content: "";
position: absolute;
width: 24px;
height: 24px;
left: 3px;
top: 3px;
background: #ffffff;
border-radius: 50%;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
transition: transform 0.3s ease;
}
.switch input:checked + .slider {
background: #6366f1;
}
.switch input:checked + .slider::before {
transform: translateX(30px);
}