JSFiddle - React, Tailwind, and code Playground
HTML
<div class="demo demo-1">
<input type="checkbox" id="checkbox" class="checkbox"/>
<div class="checkbox-wrapper">
<label for="checkbox" class="checkbox-label"></label>
</div>
</div>
<div class="demo demo-2">
<input type="checkbox" id="checkbox-2" class="checkbox"/>
<div class="checkbox-wrapper">
<label for="checkbox-2" class="checkbox-label"></label>
</div>
</div>
CSS
.demo {
margin: 15px;
}
/* Metro UI Style */
.demo-1 .checkbox-wrapper {
width: 80px;
height: 32px;
position: relative;
display: inline-block;
overflow: hidden;
}
.demo-1 .checkbox {
display: none;
}
.demo-1 .checkbox-label:before,
.demo-1 .checkbox-label:after {
font-family: sans-serif;
font-size: 13px;
color: #ffffff;
position: absolute;
font-weight: bold;
line-height: 32px;
height: 32px;
width: 40px;
text-align: center;
}
.demo-1 .checkbox-label:before {
content: 'ON';
left: -40px;
background: #45b6af;
}
.demo-1 .checkbox-label:after {
content: 'OFF';
right: -40px;
background: #f3565d;
}
.demo-1 .checkbox-label {
display: block;
position: absolute;
left: 0;
width: 40px;
height: 32px;
transition: all .4s ease;
cursor: pointer;
background: #dddddd;
}
.demo-1 .checkbox:checked + .checkbox-wrapper .checkbox-label {
left: 40px;
}
/* iOS 7 Style */
.demo-2 .checkbox-wrapper {
width: 58px;
height: 32px;
position: relative;
display: inline-block;
background: #ffffff;
border-radius: 16px;
transition: all .3s ease-out;
box-shadow: 0px 0px 0px 2px #ddd;
}
.demo-2 .checkbox {
display: none;
}
.demo-2 .checkbox-label {
display: block;
position: absolute;
left: 0px;
top: 0px;
width: 32px;
height: 32px;
cursor: pointer;
background: #ffffff;
border-radius: 16px;
box-shadow: 0px 2px 3px rgba(0,0,0,0.2);
transition: all .3s ease-out;
}
.demo-2 .checkbox:checked + .checkbox-wrapper {
background: #0bd318;
box-shadow: 0px 0px 0px 2px #0bd318;
}
.demo-2 .checkbox:checked + .checkbox-wrapper .checkbox-label {
left: 26px;
}