JSFiddle - React, Tailwind, and code Playground
by Dru Dro
HTML
<div class="price-slider">
<input value="0" min="0" max="100" step="0.5" type="range" oninput="updatePriceLabels()">
<input value="100" min="0" max="100" step="0.5" type="range" oninput="updatePriceLabels()">
</div>
<div id="re"></div>
<script>
function updatePriceLabels() {
//avoids slider overlap
const sliders = document.querySelectorAll(".price-slider input"),
val1 = parseInt(sliders[0].value),
val2 = parseInt(sliders[1].value),
re = document.querySelector('#re');
let from, to;
from = val1 < val2 ? val1 : val2;
to = val1 < val2 ? val2 : val1;
re.innerHTML = `From: ${from} to ${to}`
}
</script>
CSS
html,
body {
margin: 0;
padding: 0
}
.price-slider {
position: relative;
width: 100%;
padding: 0;
height: 35px;
text-align: center;
box-sizing: border-box;
}
.price-slider input {
pointer-events: none;
position: absolute;
left: 15px;
top: 15px;
width: calc(100% - 30px);
outline: none;
height: 18px;
margin: 0;
padding: 0;
border-radius: 8px;
}
.price-slider input::-webkit-slider-thumb {
pointer-events: all;
position: relative;
z-index: 1;
outline: 0;
-webkit-appearance: none;
height: 24px;
width: 24px;
border-radius: 12px;
background-color: white;
border: 2px solid black;
}