Sometimes, we want to let users enter currency values with HTML number inputs.
In this article, we’ll look at how to let users enter currency values with HTML number inputs.
Let Users Enter Currency Values with HTML Number Inputs
To let users enter currency values with HTML number inputs, we can set the step attribute to 0.01 so that users can enter 2 decimal places into the number input.
For instance, we can write:
<input type="number" min="0.01" step="0.01" max="1000" value="25.67" />
to add the number input with the min and max attributes set to the min and max values allowed in the input.
The step attribute is set to 0.01 to let us enter 2 decimal places into the input box.
Conclusion
To let users enter currency values with HTML number inputs, we can set the step attribute to 0.01 so that users can enter 2 decimal places into the number input.