Skip to content

Input = time, How to allow input of only the hour. No minutes or seconds

I want to allow the user to input a time but only allow the input of hours, no minutes or seconds. I understand a text or number field would be better but need to post the input as a time.

I have tried setting the step attribute to 600, however that removes the milliseconds only.


The step attribute is the step amount you can do in milliseconds, so in this case you should use 60 * 60 * 1000 (60 minutes * 60 seconds * 1000 milliseconds = 1 hour) as the value:

<input type="time" step="3600000" />

Note that this does not work in Safari, but I did test it in Chrome. Safari simply doesnt support this type at all, so no validation happens as far as I can see. Which makes this not universally compatible.