JSFiddle - React, Tailwind, and code Playground
by kairavthakar2016
HTML
<input type="range" min="5" max="100" step="1" value="50">
CSS
input[type='range'] {
width: 400px;
}
input[type='range'],
input[type='range']::-webkit-slider-runnable-track,
input[type='range']::-webkit-slider-thumb {
-webkit-appearance: none;
}
input[type='range']::-webkit-slider-runnable-track {
height: 3px;
background: linear-gradient(to right, #fff, #293043), #D7D7D7;
background-size: var(--background-size, 0%) 100%;
background-repeat: no-repeat;
border-radius: 5px;
}
input[type='range']::-webkit-slider-thumb {
width: 50px;
height: 50px;
cursor: pointer;
background: #293043;
border: solid white 1px;
border-radius: 50%;
margin-top: -6px;
box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.4);
}
/** FF*/
input[type="range"]::-moz-range-progress {
background-color: #293043;
border-radius: 5px;
}
input[type="range"]::-moz-range-track {
background-color: #D7D7D7;
border-radius: 5px;
}
input[type="range"]::-moz-range-thumb {
width: 50px;
height: 50px;
cursor: pointer;
background: #293043;
border: solid white 1px;
border-radius: 50%;
margin-top: 0px;
box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.4);
}
JavaScript
const input = document.querySelector("input");
function setBackgroundSize(input) {
input.style.setProperty("--background-size", `${getBackgroundSize(input)}%`);
}
setBackgroundSize(input);
input.addEventListener("input", () => setBackgroundSize(input));
function getBackgroundSize(input) {
const min = +input.min || 0;
const max = +input.max || 100;
const value = +input.value;
const size = (value - min) / (max - min) * 100;
return size;
}