EN
HTML - range input
6
points
In this article, we would like to show you how to create and use range input element in HTML.
Quick solution:
// ONLINE-RUNNER:browser;
<label>
<span>Range: </span>
<input type="range" name="example-range" min="0" max="10" />
</label>
Screenshot:
Practical example
In this example, we use the input element's type="range"
attribute to create range input element.
Additionally, we specify the following range input attributes:
min
- minimum value,max
- maximum value,step
- specifies the size of each movement (increment or decrement) of the slider control.
// ONLINE-RUNNER:browser;
<!doctype html>
<html>
<body>
<script>
function handleInput(input) {
console.log('Value: ' + input.value);
}
</script>
<form>
<label>
<span>Range: </span>
<input type="range" name="example-range" min="0" max="10" step="2" oninput="handleInput(this)" />
</label>
</form>
</body>
</html>