Double Range Slider with Min-Max value using HTML, CSS, & JavaScript
Double Range Slider with Min-Max value using HTML, CSS, & JavaScript
Introduction
Hello coders! We are talking about Double Range Slider | Double Range Slider with Min-Max value and today In this tutorial, you will learn to make Double Range Slider with Min-Max value using HTML, CSS, & JavaScript.
We will make an interactive design of this Double Range Slider with Min-Max value in floating bubbles at the top of its thumbs design, using HTML, CSS, and JavaScript.
Preview of the project
Project author | Ashok(Website owner) |
Built with | HTML, CSS, JavaScript |
Responsive | No |
Dependencies | - |
Compatible browsers | Chrome, Edge, Firefox, Opera, Safari |
Demo | Codepen preview here |
Steps to create Double Range Slider with Min-Max value using HTML, CSS, & JavaScript
Mainly we will go through 3 steps to create this Double Range Slider with Min-Max value.
Step 1: Create the basic structure HTML
Here I have structured this HTML of Double Range Slider with Min-Max value.
DIV with class double_range_slider_box
is our main box, inside this the div with class double_range_slider
is our range slider container in which I have added a span with class range_track
, and it will be our range track.
Also, I have created 2 div
with classes minvalue & maxvalue these will be our min-value bubble and max-value bubble, which will float at near the double range slider thumbs.
If you have noticed that I have added 2 <input type="range" >
tags inside the div whose class name is double_range_slider
.
<input type="range" class="min" min="0" max="100" value="0" step="0">
<input type="range" class="max" min="0" max="100" value="20" step="0">
Look at these input
tags type ranges, here which class name is min
that is for double range slider min-value and second which class name is max
that is for max-value.
By default I have set the first input value value="0"
and that second input value value="20"
these are the initial/default value before the user interacts. See the example below.
Read also: CSS Gradient Border Glowing Animation Hover Effect
Step 2: Create design using CSS
In the CSS part I have created some styles, like background-color
, transition
, width
, height
, margin
, padding
, etc.
Remove the default style of <input type="range">
by using the below CSS code. Here you have noticed that, I have used here ::-webkit-slider-thumb
CSS pseudo-element & ::-moz-range-thumb
CSS pseudo-element to change the Input “thumb” style across all the browser.
::-webkit-slider-thumb | Chrome, Safari, Opera, Microsoft Edge, etc |
::-moz-range-thumb | Firefox |
Read also: Awesome Slider Animation using HTML, CSS, and JavaScript
Step 3: Add functionality to this Double Range Slider using JavaScript
NOTE! You must have little knowledge about JavaScript to understand and use this JavaScript code of Double Range Slider project.
In the JavaScript part I have created some variables to use these in functions.
minRangeFill()
function is for fill the range track, when the user drag on “left-thumb” of double range slidermaxRangeFill()
function is for fill the range track, when user drag on “right-thumb”.MinVlaueBubbleStyle()
function is for Left bubble moving animation when user drag on “left-thumb”.MaxVlaueBubbleStyle()
function is for Right bubble moving animation when user drag on “right-thumb”.setMinValueOutput()
function for display range minimum value in the left bubble.setMaxValueOutput()
function for display range maximum value in the right bubble.
Here I have return all the functions here.
Then I created a forEach()
function to rangeInput
variable and created a second addEventListener()
function to its child input elements the event is called “input”, this function is for when the user inputs the range or drags the range thumbs then run all the functions which we have previously made.
If you noticed that, I have created a condition in the if-else
statement is maxRange - minRange < minRangeValueGap
this is for when the user interacts with the double range slider and if the 2 thumbs get too close, the range will stop.
As example in this image:
Copy all the JavaScript code into you main.js
file.
Conclusion
This is the blog about Double Range Slider with Min-Max value using HTML, CSS, & JavaScript. Hope you like this blog and learned something new. If you have any doubt and questions about this project let me know in comments and ping me on Instagram.