I would like to customize input type range like this.
I tried to use the following code to change the thumb and as below but selected range color is not changed.
HTML:
<input type="range" />
CSS:
input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
height: 20px;
width: 20px;
border-radius: 10px;
background: red;
cursor: pointer;
border: none;
margin-top: -8px;
}
input[type=range] {
-webkit-appearance: none;
outline: 0;
margin: 0;
padding: 0;
height: 30px;
width: 100%;
}
Could anybody please suggest me to change the selected runnable track background color?
Interesting approach being used by the Ionic framework for styling the range input track with just CSS. They are adding a
::before
pseudo-element to the::-webkit-slider-thumb
, making it as wide as possible and then positioning it on top of the track. (I couldn't getborder-radius
to work with it.)As far as I am aware there is no pure CSS way to do this for Webkit powered browsers (and FF). IE provides a way to style the two portions of the track using-ms-fill-lower
and-ms-fill-upper
but there are no equivalents in WebKit and hence JavaScript will be needed.You could use a
linear-gradient
as background image for the runnable track and then change thebackground-size
using JavaScript to achieve the required effect. As question is specific to Webkit, the snippet provided currently works only in Webkit powered browsers. This method does allow us to add aborder-radius
to the track.This snippet was adapted from Ana Tudor's CodePen Demo. That demo has ways to make it work in other browsers also.