Using Range Input to create HTML sliders

The range element that has been introduced in HTML5 and that was missing in the previous versions can be used to create a variety of sliders. The syntax of this input type is:

Various attributes can be received by this element, mot noteworthy being min, max, step and value etc. As a demonstration, a gauge is built using the range element in which first of all, we need to create the mark-up:

In the above code, other than setting the min and max values, we can also mention what the step for each transition will be.  If the step is set to 1, there will then be 10 values to choose. After that, we would use :before and :after to inform the user what our specified min and max values are. This is done using CSS:

Here, content is created before and after the range input and their values are made equal to min and max values respectively.

Finally comes the JavaScript part, in which we determine if the current browser knows what the range input is. If not, we alert the user that the demo won’t work. This part would also be used to update the output element dynamically, as the user moves the slider. The next time the user refreshes the page, the range and output will automatically be set to what they last selected:

This would pretty much sum up the entire coding of the slider. This feature can considerably enhance the ease and power of web programming and can be regarded as another exciting feature added in HTML5.

BlueHost | HostGator | Media Temple