<div class="main">
<input type="range" min="0" max="100" value="50" id="slider">
<div id="selector">
<div class="selectBtn"></div>
<div id="selectValue"></div>
</div>
<div id="progressBar"></div>
</div>
* {
margin: 0;
padding: 0;
}
body {
background: #000;
font-family: sans-serif;
}
.main {
width: 60%;
margin: 14% auto;
position: relative;
}
#slider {
appearance: none;
width: 100%;
height: 7px;
border-radius: 3px;
}
/* Design slider button */
#slider::slider-thumb {
appearance: none;
width: 48px;
height: 48px;
cursor: pointer;
position: relative;
z-index: 3;
}
#selector {
height: 104px;
width: 48px;
position: absolute;
bottom: -20px;
left: 50%;
transform: translateX(-50%);
z-index: 2;
}
.selectBtn {
height: 48px;
width: 48px;
background-image: url(https://fadzrinmadu.github.io/hosted-assets/range-slider-using-html-and-css/icon.png);
background-size: cover;
background-position: center;
border-radius: 50%;
position: absolute;
bottom: 0;
}
#selectValue {
width: 48px;
height: 40px;
position: absolute;
top: 0;
background: #ffd200;
border-radius: 4px;
text-align: center;
line-height: 45px;
font-size: 20px;
font-weight: bold;
}
#selectValue::after {
content: '';
border-top: 17px solid #ffd200;
border-left: 24px solid #000;
border-right: 24px solid #000;
position: absolute;
bottom: -14px;
left: 0;
}
#progressBar {
width: 50%;
height: 7px;
background: #ffd200;
border-radius: 3px;
position: absolute;
bottom: 4px;
left: 0;
}
let slider = document.getElementById('slider')
let selector = document.getElementById('selector')
let selectValue = document.getElementById('selectValue')
let progressBar = document.getElementById('progressBar')
selectValue.innerHTML = slider.value
slider.oninput = function() {
selectValue.innerHTML = this.value
selector.style.left = this.value + '%'
progressBar.style.width = this.value + '%'
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.