<div class="custom-checkbox">
<input id="status"
type="checkbox"
name="status">
<label for="status">
<div class="status-switch"
data-unchecked="Off"
data-checked="On">
</div>
</label>
</div>
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
display: flex;
justify-content: center;
align-items: center;
font-family: Helvetica, Arial, sans-serif;
}
.custom-checkbox {
width: 340px;
height: 80px;
input#status {
display: none;
// Unchecked State
+ label {
height: 100%;
width: 100%;
> .status-switch {
cursor: pointer;
width: 100%;
height: 100%;
position: relative;
background-color: grey;
color: white;
transition: all 0.5s ease;
padding: 3px;
border-radius: 3px;
&:before,
&:after {
border-radius: 2px;
height: calc(100% - 6px);
width: calc(50% - 3px);
display: flex;
align-items: center;
position: absolute;
justify-content: center;
transition: all 0.3s ease;
}
&:before {
background-color: white;
color: black;
box-shadow: 0 0 4px 4px rgba(#000, 0.2);
left: 3px;
z-index: 10;
content: attr(data-unchecked);
}
&:after {
right: 0;
content: attr(data-checked);
}
}
}
// Checked stae
&:checked + label > .status-switch {
background-color: #40c253;
&:after {
left: 0;
content: attr(data-unchecked);
}
&:before {
color: #40c253;
left: 50%;
content: attr(data-checked);
}
}
}
}
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.