time
The HTML <time> element gives a date, time, or duration semantic meaning. Its visible text can be friendly to people while datetime provides a machine-readable value.
What you will learn
- What dates, times, and durations
timecan represent - How visible text and
datetimework together - How to write machine-readable ISO 8601 values
time marks a date or time; it does not create an input
Write readable text inside time and a machine-readable value in datetime. It does not create a ticking clock or automatically convert time zones. To collect a time, use input type="time".
<time datetime="2026-11-15">November 15, 2026</time>
<time datetime="11-27">November 27 (birthday)</time>
<time datetime="--11-27">November 27 (same meaning)</time>
For a date without a year, both 11-27 and --11-27 are valid. The leading -- is optional.
| Purpose | datetime value | Visible example |
|---|---|---|
| Date | 2026-11-15 | November 15, 2026 |
| Yearless date | 11-27 | November 27 |
| Time | 14:30 | 2:30 PM |
| Date, time, and UTC offset | 2026-11-15T09:30+09:00 | November 15, 9:30 AM (Japan time) |
| Duration | PT45M | 45 minutes |
November 15, 2026 at 09:30 in Japan (+09:00) is the same moment as 00:30 UTC (Z) that day. Replacing +09:00 with Z without converting the clock time changes the moment.
A date and time may be separated by T or a space. These examples consistently use T. Without datetime, the text inside time must itself be a valid date or time value.
Try changing the visible text to “2:30 PM” while leaving datetime="14:30" unchanged. Explain which part is the display and which part is the value.
Sources: the time element and yearless date syntax.
Basic date example
<time datetime="2026-09-05">September 5, 2026</time>
The user-facing text can follow the page’s language and style. The datetime value should use a standard format that software can parse consistently.
Times and date-times
<time datetime="14:30">2:30 PM</time>
<time datetime="2026-09-05T14:30+09:00">September 5 at 2:30 PM</time>
Include a time-zone offset when the moment needs to be understood across regions. Do not imply a time zone you do not know.
Durations
<time datetime="PT45M">45 minutes</time>
<time datetime="P2D">2 days</time>
Durations use an ISO 8601 duration such as PT45M for 45 minutes. A duration is different from a point on the calendar.
time is not just a styling hook
Use time when the content has date, time, or duration meaning. CSS can style it, but styling alone does not give software the semantics or a reliable value.
Common mistakes
- Putting a localized date in
datetimeinstead of a machine-readable value. - Leaving the time zone ambiguous when the event crosses regions.
- Using
timefor an ordinary number or a period that has no temporal meaning. - Assuming browsers will automatically convert every visible date into a local format.