input (type=time) element

If you don't know what an element is or how you must use it, I recommend you read the "HTML tags and attributes" tutorial that you can find in the HTML tutorials section.

Description

The input element, having the "time" value in its type attribute, represents a field for a time input. In modern browsers time fields are usually represented by controls that enable users to change its value in a graphical way, instead of having to input it directly as a string.

Upon submission, supporting browsers convert the input data into a string representing a time. The rules to compose a valid time are described below.

Times

A time syntax is composed by:

  1. Two digits representing an hour between 0 and 23.
  2. A colon character (":").
  3. A two digits minute between 0 and 59.
  4. The following information, which is optional if the number of seconds is zero:
    1. A colon character (":").
    2. Two digits representing the integer part of the seconds, between 0 and 59.
    3. The following information, which is optional if the number of seconds is an integer:
      1. A period or full stop character (".").
      2. The fractional part of the seconds composed by one, two or three digits.

Example

<time>23:59:59.999</time>
<time>10:20:00.000</time>
<time>10:20</time>
<time>10:20:00</time>

Browser support for time fields is incomplete. To improve compatibility, authors may have to rely on scripts to provide advanced controls and to check values conformance before submission.

The min and max attributes may be used in this element to set a range of valid times the user will be able to submit.

Examples

In the first example we'll only create a form with a time control. Here you'll be able to note the functionality provided by your browser (if any) for the control.

<form action="../../form-result.php" method="post" target="_blank">
  <p>ETA: <input type="time" name="eta"> <input type="submit" value="Send data"></p>
</form>

ETA:

In our second example we'll provide a list of suggested values using the datalist element, so the user can quickliy pick up one of the predefined values when the browser suggests them. The control will be linked to the datalist because of the matching between the id attribute in the list and the list attribute in the control.

To make this example work properly, we'll set the step attribute to 0.01 seconds. The step attribute will be treated in the following example.

Browser support for datalist is incomplete. Authors may have to rely on scripts to provide this functionality cross-browser.

The values provided by the datalist element must conform with the requirements of time strings.

<form action="../../form-result.php" method="post" target="_blank">
  <p>
    Choose the limit time: <input type="time" name="limittime" list="limittimeslist" step="0.001">
    <input type="submit" value="Send data">
  </p>
</form>
<datalist id="limittimeslist">
  <option value="06:40">
  <option value="08:24">
  <option value="12:31:30">
  <option value="23:59:59.999">
</datalist>

Choose the limit time:

In our last example we'll be working with the attributes min, max and step to put restrictions to the values the user can input. With this configuration we're setting a minimum time, a maximum time, and the distance between a selectable time and the following (in number of seconds), respectively. More specifically, we'll only allow the user to pick an hour between 12:00 and 16:00 and a number of minutes multiple of ten (no seconds).

When the step attribute is present, authors should specify a time to be taken as initial step. This can be done through the attributes min and value. When both are present, the min attribute takes precedence.

The values provided in the attributes min, max and step must conform with the requirements of time strings.

Note that the default value for step is 60 seconds. Being this attribute absent, the user won't be able to change the number of seconds, nor select values with seconds from a datalist.

<form action="../../form-result.php" method="post" target="_blank">
  <p>
    Guess the arrival time: <input type="time" name="arrivaltime" min="12:00" max="18:00" step="600">
    <input type="submit" value="Send data">
  </p>
</form>

Guess the arrival time:

Attributes

Specific attributes

autocomplete

The autocomplete attribute provides information about if and how browsers should automatically suggest options for this control, as an attempt to guess what the user is typing. There are three possible values for this attribute:

  • The value on value, indicating the browser that it should suggest options automatically but not providing any further information about what kind of data is expected in the control.
  • The value off, indicating the browser that it shouldn't suggest options automatically, either because the control's input data is particularly sensitive (like the user to login in a very secure area) or because it's a value that will never be reused (like a one-time-key in a registration process).
  • An autofill detail tokens list, indicating the browser that it should suggest options automatically and specifying what kind of value is expected.

An autofill detail tokens list can be composed by the following tokens in the specified order.

  1. Optionally, a token beginning with the string "section-" (case-insentsitive), indicating the named group to which the field belongs.
  2. Optionally, one of the two following tokens (case-insentsitive):
    • shipping: the field is part of the shipping address.
    • billing: the field is part of the billing address.
  3. Optionally, a token that is a case-insensitive match for one of the following strings:
    • home: meaning the field is for contacting someone at their residence.
    • work: meaning the field is for contacting someone at their workplace.
    • mobile: meaning the field is for contacting someone at their mobile device.
    • fax: meaning the field describes a fax machine's contact details.
    • pager: meaning the field describes a pager's or beeper's contact details

Browsers usually perform autofilling operations by retrieving data from a database containing previous inputs or other sources of user information.

Example

<form action="../../form-result.php" method="post" target="_blank">
  <p>
    Estimate next rocket launch: <input type="time" name="nextlaunch" autocomplete="off">
    <input type="submit" value="Set">
  </p>
</form>

Estimate next rocket launch:

autofocus

A boolean value instructing the browser to set the focus to this control when the document has finished loading or when the dialog where the control finds itself is shown. If the attribute has the value "autofocus" or the empty string (""), or if it's just present, the control should get the focus as soon as possible, after the page or dialog has been loaded.

Example

<p>Make an appointment for today: <input type="time" name="appointmenttime" autofocus></p>

disabled

A boolean value indicating wether the control is disabled or not. If the attribute takes the value "disabled" or the empty string (""), or if it's just present, the control will be disabled.

Disabled controls are rendered greyed out (if visible), are blocked from user interaction and, more importantly, their values (if any) aren't sent when the form is submitted.

Example

<form action="../../form-result.php" method="post" target="_blank">
  <p>
    Contactable from: <input type="time" name="contactablefrom" disabled>
    <input type="submit" value="Send data">
  </p>
</form>

Contactable from:

form

The value of the id attribute of the form with which this control is associated to.

This attribute is new in HTML5 and helps defining the pertenence of controls in nested or distant forms.

Example

<p>Departure time: <input type="time" name="departuretime" form="form1"></p>
<form id="form1" action="../../form-result.php" method="post" target="_blank">
  <p><input type="submit" value="Send data"></p>
</form>

Departure time:

list

A token matching the value of the id attribute of the datalist this control is assopciated with. The datalist referenced by this attribute will provide a number of suggestions that users can pick to autocomplete the control.

Browser support for datalist is incomplete. Authors may have to rely on scripts to provide this functionality cross-browser.

The values provided by the datalist element must conform with the requirements of time strings.

Example

<form action="../../form-result.php" method="post" target="_blank">
  <p>
    Desired time to receive the call: <input type="time" name="desiredcalltime" list="calltimeslist">
    <input type="submit" value="Send data">
  </p>
</form>
<datalist id="calltimeslist">
  <option value="16:00">
  <option value="16:30">
  <option value="17:00">
  <option value="17:30">
</datalist>

Desired time to receive the call:

max

The maximum time the user should be able to pick. Supporting browsers are supposed to disallow the selection of any time greater than the one specified in this attribute.

The value provided in this attribute must conform with the requirements of time strings.

Example

<form action="../../form-result.php" method="post" target="_blank">
  <p>
    Wait until: <input type="time" name="waituntil" max="23:00">
    <input type="submit" value="Send data">
  </p>
</form>

Wait until:

min

The minimum time the user should be able to pick. Supporting browsers are supposed to disallow the selection of any time less than the one specified in this attribute.

The value provided in this attribute must conform with the requirements of time strings.

Example

<form action="../../form-result.php" method="post" target="_blank">
  <p>
    Start time: <input type="time" name="starttime" min="09:00">
    <input type="submit" value="Send data">
  </p>
</form>

Start time:

name

A name for the control. This name will be sent by the browser to the processing agent, paired with the content of the value attribute. Both attributes together will conform a name-value pair that will be used to process the form data.

Currently, the value isindex, formerly used in a special way by some browsers and included in the HTML standard, isn't permitted in this attribute.

Example

<form action="../../form-result.php" method="post" target="_blank">
  <p>
    Beginning: <input type="time" name="beginning">
    <input type="submit" value="Send data">
  </p>
</form>

Beginning:

readonly

A boolean value instructing the browser to prevent the user from changing the control's value. If this attribute has the value "readonly" or the empty string (""), or if it's just present, the user won't be allowed to change the value in the control.

Although this attribute prevents the control's value from being edited, not all interaction is blocked: users will still be able to select and copy the text in the control.

Example

<form action="../../form-result.php" method="post" target="_blank">
  <p>
    Appointment time: <input type="time" name="appointmenttime" value="16:05" readonly>
    <input type="submit" value="Send data">
  </p>
</form>

Appointment time:

required

A boolean value indicating wether this control can be left empty or not. If this attribute has the value "required" or the empty string (""), or if it's just present, the user will have to fill the control in order to be able to submit the form.

If a control with the required attribute present is left blank, supporting browsers will throw an error upon submission and cancel the process immediately.

Browser support for the attribute required is incomplete. Authors may have to rely on scripts to provide this functionality cross-browser.

Example

<form action="../../form-result.php" method="post" target="_blank">
  <p>
    Class begins at: <input type="time" name="classbeginningtime" required>
    <input type="submit" value="Send data">
  </p>
</form>

Class begins at:

step

A number of seconds to be used as the amount of space between an allowed value and the next one. The presence of this attribute reduces the number of choices the user will have by restricting the selection of intermediate values.

The special value any removes the default restriction over the granularity of the control and allows users to input values as specific as they want.

To avoid unexpected behaviors, authors should specify a time to be taken as initial step. This can be done through the attributes min and value. When both are present, the min attribute takes precedence.

Example

<form action="../../form-result.php" method="post" target="_blank">
  <p>
    Select an hour (no minutes): <input type="time" name="hour" step="3600" min="00:00">
    <input type="submit" value="Send data">
  </p>
</form>

Select an hour (no minutes):

type

A value indicating the type of the field that this element represents. There are twenty two possible values (case-insensitive):

  • hidden: a hidden control used to send information to the server, typically managed by scripts.
  • text: a control used to input a single-line piece of text.
  • search: same as text but for search purposes.
  • tel: a control used to provide a telephone number.
  • url: a text box used to input a single and absolute URL.
  • email: a control designed to edit one or more e-mail addresses.
  • password: a text box for editing passwords, where the characters are represented by dots.
  • date: a control to input a specific date.
  • month: a control to input a specific month.
  • week: a control to input a specific week.
  • time: a control to input a specific time.
  • datetime-local: a control to input a specific local date and time.
  • number: a control to input a number.
  • range: a control to input one or two numbers inside a range.
  • color: a control to input a color.
  • checkbox: a control to input a boolean value (true/false).
  • radio: a control used to choose one single option among many.
  • file: a control used to upload files to the server.
  • submit: a button used to submit the form.
  • image: same as submit but with the ability to be shown as an image instead of using the default button appearance.
  • reset: a button used to reset the form's controls to their default values.
  • button: a button with no default action associated.

When this attribute isn't present, the element behaves as it would have the value "text".

Example

<input type="time" name="starttime">

value

An initial value for the control, that will be set when the page loads and when the reset button is pressed.

The value provided in this attribute must conform with the requirements of time strings.

Example

<form action="../../form-result.php" method="post" target="_blank">
  <p>Send me an alert at: <input type="time" name="alerttime" value="07:45"></p>
  <p>
    <input type="submit" value="Send data">
    <input type="reset" value="Reset form">
  <p>
</form>

Send me an alert at:

Global attributes

For information about global attributes refer to this list of global attributes in HTML5.

Events

Global events

For information about global events refer to this list of global events in HTML5.