<time>

Term side of the Card.
Topic: Semantics
Unit title: <time>
Categories: Tag
Explanation side of the Card

Explanation: The element that represents a specific time or date or both. It can be used to mark up times in a machine-readable format, improving accessibility and enabling features like event reminders.

Browser compatibility:
  • The chrome browser supports this feature starting from version 62.
  • The edge browser supports this feature starting from version 14.
  • The firefox browser supports this feature starting from version 22.
  • The safari browser supports this feature starting from version 7.
Availability: 

Example

Wronghtml
<time datetime="May 1st">
  May 1
</time>
Righthtml
<time datetime="2024-05-01">
  May 1
</time>

datetime must be a machine-readable date or time so search engines and scripts can parse it.

Common mistakes

  • Putting a localized date string like 'May 1st' or '05/01' in datetime.
  • Wrapping relative text like 'yesterday' in <time> without a datetime attribute.

Key points

  • The datetime attribute uses a valid machine format, like YYYY-MM-DD or a full ISO date and time.
  • Human-readable text inside <time> matches the datetime value.

Interview questions

Is the datetime attribute required?

Only when the element text is not itself in a valid date or time format.

Can <time> represent a duration?

Yes. datetime accepts durations such as 'PT2H30M' for two and a half hours.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy