DEV Community

Carlos V.
Carlos V.

Posted on

Always use semantic HTML inputs

I know sometimes is tedious to use a correct component for requesting a user input in HTML. But using the proper component will significatively enhance the user experience and it's easier to see it in action while in mobile devices.

Today I Learned that you can step x decimal in an input type="number". Let's say you want to ask for a price:

<input type="number" required name="price" min="0" value="0" step="any">
Enter fullscreen mode Exit fullscreen mode

If you omit the step="any" part, the input will validate only for integer values.

But if you use instead:

step=".01"
Enter fullscreen mode Exit fullscreen mode

Then, every time you click on the arrows, the value will be updated to ±0.01. Pretty handy isn't it?

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay