How to Set a Default Value on "time" input HTML Element?

Adding a default value to HTML input element with type set to "time"

HTML <input type="time" /> element accepts a value that is in:

  • 24-hour format with leading zeros, and;
  • "hh:mm" and "hh:mm:ss" format only.

Therefore, to set a default value on the <input type="time" /> element, you simply need to set the value attribute to the correct format. For example, to set a default value of "3:45 pm", you would write it in 24-hour format, like so:

<input type="time" value="15:45" />

Similarly, the following would have a default value of "3:45 am and 25 seconds":

<input type="time" value="03:45:25" />

Please note that the visual representation of time picker may vary depending on the user's browser and/or OS.

Hope you found this post useful. It was published . Please show your love and support by sharing this post.