cookbook home ~ main site ~ other sites ~ podcast ~ twitter ~ mastodon

HTML Input Range Type With Floating Point Number

Details

HTML

<input id="alfa" type="range" min="0" max="10" step="0.1" value="0" />

EXAMPLE

0



Demonstration JavaScript

This is the code that powers the example. It's not necessary for the value to be updated. It just makes it easier to see by update a div with the id `alfaValue`

const handleInput = (event) => {
    document.getElementById('alfaValue').innerHTML = event.target.value
}

const init = () => {
    document.getElementById('alfa').addEventListener('input', handleInput)
}

document.addEventListener('DOMContentLoaded', init)

References