I want to create a slider showing decimal values like 0.0 to 0.1 using html or html5.
The HTML slider input can be created on any web page by a combination of specific HTML and CSS syntaxes. You can choose any value from a specific range designed by the web developer. Users can see the value on a slider bar, also known as the HTML slider control.
What is a range slider in HTML? A range slider is an input where you select a value from a control or sliding bar. We can slide the handlebar to the right or left to produce a range. You can usually find a slider bar when manipulating your volume or brightness controls on the computer.
The HTML for ticks range slider consists of four main elements, the main container, input range, and SVG elements for ticks and values. The main container is a fieldset element of HTML that contain all other elements of the range slider.
Another example of price range slider with: The <input> type range elements let the user specify a numeric value being no less than a specified value, no more than another specified one. By default, the range is from 0 to 100. But you can restrict the numbers using max, min, step and value attributes. How can we improve it?
Add step="0.1"
in your input range tag like this: <input type="range" min="0.1" max="1.0" step="0.1" value="1">
Example:
document.getElementById("scale").oninput = function() {
document.getElementById("spanscale").innerHTML = this.value;
}
<input type="range" min="0.1" max="3.0" step="0.1" value="1" id="scale">Scale:<text id="spanscale" style="inline">1</text>
If you want to show a decimal place in integer numbers you can add this piece of code in the value output: Number(this.value).toFixed(1)
document.getElementById("scale").oninput = function() {
document.getElementById("spanscale").innerHTML = Number(this.value).toFixed(1);
}
<input type="range" min="0.1" max="3.0" step="0.1" value="1.0" id="scale">Scale:<text id="spanscale" style="inline">1.0</text>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With