<span class="csstoggle"><input type="checkbox" id="switch" /><label for="switch">Toggle</label></span>
.csstoggle {
display: inline-flex;
}
.csstoggle input[type=checkbox]{
height: 0;
width: 0;
visibility: hidden;
}
.csstoggle label {
cursor: pointer;
text-indent: -9999px;
width: 60px;
height: 30px;
background: #444;
display: block;
border-radius: 30px;
position: relative;
border: 1px solid black;
}
.csstoggle label:after {
content: '';
position: absolute;
top: 5px;
left: 5px;
width: 20px;
height: 20px;
background: #fff;
border-radius: 20px;
transition: 0.3s;
}
.csstoggle input:checked + label {
background: #bada55;
border: 1px solid #97b832;
}
.csstoggle input:checked + label:after {
left: calc(100% - 5px);
transform: translateX(-100%);
}
.csstoggle label:active:after {
width: 30px;
}
// centering
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.