What I can suggest is to use input range oninput event to follow the value of the input and use a proportional margin-left with this value.

Here's the code you need:

$('input[type="range"]').on('input', function() {
  $('span#a').css('margin-left', parseInt($(this).val() - 10) > 0 ? parseInt($(this).val() - 10) + '%' : '0px');
});

Demo:

$('input[type="range"]').on('input', function() {
  $('span#a').css('margin-left', parseInt($(this).val() - 10) > 0 ? parseInt($(this).val() - 10) + '%' : '0px');
});
input {
  width: 90%;
}

span#a {
  display: block;
  width: auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="range" min="0" max="100" step="1" value="0" />
<span id="a">I'm following.</span>

Note:

  • This will update the span left margin to be proportional to value of the range, so it will be updating between 0% to 100%, which gives it the floating effect.

  • In the following sample Demo, the margin-left value needs more
    adjusting so it will give a better result. The logic is there, but
    needs just some adjustment.

Answer from cнŝdk on Stack Overflow
🌐
W3C
w3c.github.io › html-reference › input.range.html
input type=range – imprecise number-input control (NEW) - HTML5
ⓘ step = "any" or positive floating-point number NEW # Specifies the value granularity of the element’s value. ... A string representing a number. The interactive element input must not appear as a descendant of the a element.
🌐
Reddit
reddit.com › r/learnpython › beginner question: how do i limit the range of a float input?
r/learnpython on Reddit: Beginner question: How do I limit the range of a float input?
March 7, 2022 -

I'm ultimately trying to scrape all of the top movie databases (starting with IMDB,) to generate a list of top IMDB movies that are organised by rating, genre, etc.

I'm just learning functions and I'm a little stuck. My code works, but I can't figure out how to easily limit the input range of the rating (IMDB rating is capped at 10.0, therefore it needs to call an error if past that) - this should sort itself out when I automate the values but for now it's a manual process and I just wanna learn how to do it for the sake of learning. My code thus far:

def movie_review(rating):
    if rating < 6.9:
        return "Avoid"
    elif rating < 8:
        return "Pretty decent"
    else:
        return "Outstanding movie"

def movie_name(x):
   return x, rating

x = input("Enter movie name: ")
rating = float(input("Enter rating: "))

a = movie_review(rating)
b = movie_name(x)

print(b)

print(a)

Thank you!(!!!!!)

Edit: just noting, the variables that define how good a movie is will change. I know there are some good movies with a lower than 7 rating, I'm not a ratings snob; it's all temporary for now. 😅

Edit#2: I love you guys, thanks everyone.

Discussions

html - Is there a float input type in HTML5? - Stack Overflow
Step attribute actually shows the input field how many decimal points should be accepted. E.g, step="0.01" will accept only two decimal points. ... Save this answer. ... Show activity on this post. Using React on my IPad, type="number" does not work perfectly for me. For my floating point numbers in the range ... More on stackoverflow.com
🌐 stackoverflow.com
html - Step parameter for input type of range - Stack Overflow
Is it possible to specify a decimal for a step parameter within the range element? According to a few articles I've read, including one on Nettuts, this should be possible. This does not appear to be More on stackoverflow.com
🌐 stackoverflow.com
python - range() for floats - Stack Overflow
def frange(start, stop, step, n=None): """return a WYSIWYG series of float values that mimic range behavior by excluding the end point and not printing extraneous digits beyond the precision of the input numbers (controlled by n and automatically detected based on the string representation ... More on stackoverflow.com
🌐 stackoverflow.com
Custom Number Input with limited range - Max and Min float value - Get Help - Adalo
I am going to make a number input with limited range. So what I want is to set max and min value for the number input component. The values could be integer or float value. For example, I can set a number in the input as a maximum value of 100. And the numbers in the input will be float value ... More on forum.adalo.com
🌐 forum.adalo.com
0
July 25, 2023
Top answer
1 of 2
1

What I can suggest is to use input range oninput event to follow the value of the input and use a proportional margin-left with this value.

Here's the code you need:

$('input[type="range"]').on('input', function() {
  $('span#a').css('margin-left', parseInt($(this).val() - 10) > 0 ? parseInt($(this).val() - 10) + '%' : '0px');
});

Demo:

$('input[type="range"]').on('input', function() {
  $('span#a').css('margin-left', parseInt($(this).val() - 10) > 0 ? parseInt($(this).val() - 10) + '%' : '0px');
});
input {
  width: 90%;
}

span#a {
  display: block;
  width: auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="range" min="0" max="100" step="1" value="0" />
<span id="a">I'm following.</span>

Note:

  • This will update the span left margin to be proportional to value of the range, so it will be updating between 0% to 100%, which gives it the floating effect.

  • In the following sample Demo, the margin-left value needs more
    adjusting so it will give a better result. The logic is there, but
    needs just some adjustment.

2 of 2
1

https://jsfiddle.net/2cc83shx/2/

$( document ).ready( function() {
    $( '#rangeInput' ).on( 'change', function() {
        $( '#a' ).css({
            'transform': 'translateX(' + $(this).val() + 'px)'
        })
    })
})

I can help a bit. you can positioning it a bit better later from my fiddle. (here, I'm using jquery to select the element. you can use pure js to do this too)

*UPDATE

If you want it to follow whenever you drag the range, follow the code below

https://jsfiddle.net/2cc83shx/3/

Top answer
1 of 13
2477

The number type has a step value controlling which numbers are valid (along with max and min), which defaults to 1. This value is also used by implementations for the stepper buttons (i.e. pressing up increases by step).

Simply change this value to whatever is appropriate. For money, two decimal places are probably expected:

<label for="totalAmt">Total Amount</label>
<input type="number" step="0.01" id="totalAmt">

(I'd also set min=0 if it can only be positive)

If you'd prefer to allow any number of decimal places, you can use step="any" (though for currencies, I'd recommend sticking to 0.01). In Chrome & Firefox, the stepper buttons will increment / decrement by 1 when using any. (thanks to Michal Stefanow's answer for pointing out any, and see the relevant spec here)

Here's a playground showing how various steps affect various input types:

<form>
  <input type=number step=1 /> Step 1 (default)<br />
  <input type=number step=0.01 /> Step 0.01<br />
  <input type=number step=any /> Step any<br />
  <input type=range step=20 /> Step 20<br />
  <input type=datetime-local step=60 /> Step 60 (default)<br />
  <input type=datetime-local step=1 /> Step 1<br />
  <input type=datetime-local step=any /> Step any<br />
  <input type=datetime-local step=0.001 /> Step 0.001<br />
  <input type=datetime-local step=3600 /> Step 3600 (1 hour)<br />
  <input type=datetime-local step=86400 /> Step 86400 (1 day)<br />
  <input type=datetime-local step=70 /> Step 70 (1 min, 10 sec)<br />
</form>
Run code snippetEdit code snippet Hide Results Copy to answer Expand


As usual, I'll add a quick note: remember that client-side validation is just a convenience to the user. You must also validate on the server-side!

2 of 13
219

Via: http://blog.isotoma.com/2012/03/html5-input-typenumber-and-decimalsfloats-in-chrome/

But what if you want all the numbers to be valid, integers and decimals alike? In this case, set step to “any”

<input type="number" step="any" />

Works for me in Chrome, not tested in other browsers.

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › HTML › Element › input › range
<input type="range"> HTML attribute value - HTML | MDN
For example, in the case of a home stereo volume control, users typically think "set volume at halfway to maximum" instead of "set volume to 0.5". By default, the minimum is 0 and the maximum is 100. If that's not what you want, you can easily specify different bounds by changing the values ...
🌐
ProcessWire
processwire.com › modules › inputfield-float-range
Float (Range slider) (InputfieldFloatRange) - ProcessWire Module
October 17, 2019 - Simple and fast HTML5 input range slider, with optional precision, min/max and step settings. Works as a drop-in replacement for regular float and integer fields.6
🌐
Alanwsmith
html-css-js.alanwsmith.com › recipes › html_input_range_type_with_floating_point_number--2itkxa97ogoe › index.html
HTML Input Range Type With Floating Point Number
This example uses the `step` attribute of an range type input element to make a floating point value (e.g. `4.3`) instead of an integer (e.g.
Find elsewhere
🌐
CodePen
codepen.io › islam077 › pen › oNvbOqJ
rangeslider.js floating point boundaries
<!-- rangeslider.js example https://github.com/andreruffert/rangeslider.js by André Ruffert - @andreruffert --> <h2>Floating point boundaries</h2> <br> <br> <input type="range" value="0.5" step="0.1" min="0.1" max="3.0"> <br> <output>0.5</output>
🌐
GeeksforGeeks
geeksforgeeks.org › html › how-to-set-float-input-type-in-html5
How to set float input type in HTML5 ? - GeeksforGeeks
July 23, 2025 - These input types include text, password, checkbox, radio, submit, reset, button, image, file, hidden, date, time, datetime-local, month, week, number, range, email, url, search, tel, and color. However, "float" is not a valid input type in HTML5.
🌐
Bobby Hadz
bobbyhadz.com › blog › python-input-float
How to take Float user input in Python | bobbyhadz
April 9, 2024 - The if statement checks if the float is in the range 1.1-9.9 and if the condition is met, we break out of the while loop.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › HTML › Reference › Elements › input › range
<input type="range"> HTML attribute value - MDN Web Docs
September 10, 2026 - For example, in the case of a home stereo volume control, users typically think "set volume at halfway to maximum" instead of "set volume to 0.5". By default, the minimum is 0 and the maximum is 100. If that's not what you want, you can easily specify different bounds by changing the values ...
🌐
Observable
observablehq.com › framework › inputs › range
Range input | Observable Framework
API · Source · The range input specifies a number between the given min and max (inclusive). This number can be adjusted roughly by sliding, or precisely by typing. A range input is also known as a slider. By default, a range chooses a floating point number between 0 and 1 with full precision, ...
🌐
Adalo
forum.adalo.com › get help
Custom Number Input with limited range - Max and Min float value - Get Help - Adalo
July 25, 2023 - I am going to make a number input with limited range. So what I want is to set max and min value for the number input component. The values could be integer or float value. For example, I can set a number in the input as a maximum value of 100. And the numbers in the input will be float value like 14.23 or 99.xx.
Top answer
1 of 3
4

If you're not supporting old browsers, you can take advantage of the

<input type="range"> 

and some JavaScript to follow it along. See my Codepen: http://codepen.io/abhisharma2/pen/wMOpqz

2 of 3
2

An example with custom output

It's updating while you drag the input.

var el, newPoint, newPlace, offset;
 
$('input[type=range]').on('input', function () {
    $(this).trigger('change');
});
// Select all range inputs, watch for change
$("input[type='range']").change(function() {

 // Cache this for efficiency
 el = $(this);
 
 // Measure width of range input
 width = el.width();
 
 // Figure out placement percentage between left and right of input
 newPoint = (el.val() - el.attr("min")) / (el.attr("max") - el.attr("min"));
  
  offset = -1;

 // Prevent bubble from going beyond left or right (unsupported browsers)
 if (newPoint < 0) { newPlace = 0; }
 else if (newPoint > 1) { newPlace = width; }
 else { newPlace = width * newPoint + offset; offset -= newPoint; }
 
 // Move bubble
 el
   .next("output")
   .css({
     left: newPlace,
     marginLeft: offset + "%"
   })
     .text(el.val());
 })
 // Fake a change to position bubble at page load
 .trigger('change');
output { 
  position: absolute;
  background-image: linear-gradient(#444444, #999999);
  width: 40px; 
  height: 30px; 
  text-align: center; 
  color: white; 
  border-radius: 10px; 
  display: inline-block; 
  font: bold 15px/30px Georgia;
  bottom: 175%;
  left: 0;
  margin-left: -1%;
}
output:after { 
  content: "";
  position: absolute;
  width: 0;
  height: 0;
  border-top: 10px solid #999999;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  top: 100%;
  left: 50%;
  margin-left: -5px;
  margin-top: -1px;
}
form { 
  position: relative; 
  margin: 50px;
}
body {
  padding: 20px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<form>
<input type="range" name="foo" min="0" max="100">
<output for="foo" onforminput="value = foo.valueAsNumber;"></output>
</form>

<form>
<input type="range" name="foo" min="0" max="100" style="width: 300px;">
<output for="foo" onforminput="value = foo.valueAsNumber;"></output>
</form>

<form>
<input type="range" name="foo" min="0" max="100">
<output for="foo" onforminput="value = foo.valueAsNumber;"></output>
</form>

reference https://css-tricks.com/value-bubbles-for-range-inputs/

🌐
W3C
w3.org › wiki › Html › Elements › input › range
Html/Elements/input/range - W3C Wiki
February 3, 2011 - max = valid floating point number indicate the allowed range of values for the element.
🌐
Grav Community Forum
discourse.getgrav.org › support › forms & blueprints
Float values in Range slider - Forms & Blueprints - Grav Community Forum
August 24, 2021 - Does anybody know a good way to let users select floating point values in admin forms? For non-floating point integer selection I usually used the range slider, and this works quite well. I tried by simply using floating points as min/max/default like this: header.margin: type: range label: ...