JSFiddle - React, Tailwind, and code Playground
animated switch checkbox replacement
by Travis Almand
HTML
<label id="switch">
<input type="checkbox" />
<span></span>
</label>
CSS
#switch {
cursor: pointer;
display: inline-block;
height: 20px;
position: relative;
width: 40px;
}
#switch input {
position: absolute;
}
#switch input:checked + span {
background-color: #81A36C;
}
#switch input:checked + span:before {
-webkit-transform: translate3d(20px, 0, 0);
transform: translate3d(20px, 0, 0);
}
#switch span {
background-color: #C4C4C4;
border-radius: 20px;
display: block;
height: 100%;
left: 0;
position: absolute;
right: 0;
-webkit-transition: all 0.25s;
transition: all 0.25s;
width: 100%;
}
#switch span:before {
background-color: #FFF;
border-radius: 50%;
content: '';
display: block;
height: 16px;
left: 2px;
position: absolute;
top: 2px;
-webkit-transition: all 0.25s;
transition: all 0.25s;
width: 16px;
}