Number and Range Inputs
You'll learn how to collect numeric data with <input type="number"> and create visual sliders with <input type="range">.
What Are Number and Range Inputs?
When you need users to enter a number (like their age or a quantity), you want the browser to enforce numeric-only entry. That's what <input type="number"> does—it provides up/down arrows and restricts input to numbers.
When you need users to select from a range visually (like a volume control or price filter), <input type="range"> creates a draggable slider that feels intuitive and touch-friendly.
Number Input Attributes
<label for="age">Age:</label>
<input type="number" id="age" name="age" min="0" max="120" step="1">
min: Minimum allowed valuemax: Maximum allowed valuestep: How much the value changes when using arrows (default is1)
Think of step like the notches on a measuring cup—you can only pour in increments that match the markings.
Range Input (Slider)
<label for="volume">Volume:</label>
<input type="range" id="volume" name="volume" min="0" max="100" step="5" value="50">
This creates a horizontal slider. The same min, max, and step attributes control its behavior. You set a starting position with value.
Practical Example
<label for="quantity">Quantity (1-10):</label>
<input type="number" id="quantity" name="quantity" min="1" max="10" step="1" value="1">
<label for="rating">Rate us (1-5):</label>
<input type="range" id="rating" name="rating" min="1" max="5" value="3">
Key Takeaway: Use type="number" with min, max, and step attributes for precise numeric entry, and type="range" for visual slider controls where exact precision matters less than ease of selection.