JSFiddle - React, Tailwind, and code Playground
by jwerre
HTML
<h3>AM/PM Switch</h3>
<label class="toggle-switch">
<input type="checkbox" id="" name="" value="" checked="">
<div class="toggle-button"></div>
</label>
CSS
label.toggle-switch {
z-index: 1;
position: relative;
display: inline-block;
vertical-align: middle;
padding: 0 10px;
border-radius: 50px;
overflow: hidden;
width: 50px;
height: 22px;
margin: 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
cursor: pointer;
background-color: #97a1b7;
}
label.toggle-switch input {
position: absolute;
overflow: hidden;
clip: rect(0 0 0 0);
margin: 0;
padding: 0;
border: 0;
-ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0.1);
filter: alpha(opacity=0.1);
opacity: .001;
filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0);
}
label.toggle-switch input:checked + .toggle-button {
left: 32px;
}
abel.toggle-switch .toggle-button {
position: absolute;
display: inline-block;
padding: 0;
margin: 0;
background: transparent;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
background-clip: padding-box;
white-space: nowrap;
height: 14px;
width: 14px;
border-radius: 30px;
color: #454545;
background-color: #fff;
left: 4px;
top: 4px;
-webkit-transition: left .05s ease-in-out;
-moz-transition: left .05s ease-in-out;
-o-transition: left .05s ease-in-out;
-ms-transition: left .05s ease-in-out;
transition: left .05s ease-in-out;
}