Question
What's the simplest and most native way to make a HTML slider?
Answer
Based on a post at blog post here...
The HTML Code
<label>
<input type="checkbox" />
Text for the slider
</label>
The CSS
input {
appearance: none;
position: relative;
display: inline-block;
background: lightgrey;
height: 1.65rem;
width: 2.75rem;
vertical-align: middle;
border-radius: 2rem;
box-shadow: 0px 1px 3px #0003 inset;
transition: 0.25s linear background;
}
input::before {
content: "";
display: block;
width: 1.25rem;
height: 1.25rem;
background: #fff;
border-radius: 1.2rem;
position: absolute;
top: 0.2rem;
left: 0.2rem;
box-shadow: 0px 1px 3px #0003;
transition: 0.25s linear transform;
transform: translateX(0rem);
}
:checked {
background: green;
}
:checked::before {
transform: translateX(1rem);
}