#1 Data Analytics Program in India
₹2,499₹1,499Enroll Now
4 min read
•Question 38 of 49easy

What is the Time Element?

Machine-readable dates and times.

What You'll Learn

  • Using the time element
  • ISO 8601 format
  • Dates, times, and durations

The Time Element

The <time> element represents dates, times, or durations in a machine-readable format. The datetime attribute contains the ISO 8601 formatted value, while the element content shows human-readable text.

Formats

TypeFormatExample
DateYYYY-MM-DD2024-01-15
TimeHH:MM14:00
DatetimeYYYY-MM-DDTHH:MM2024-01-15T14:00
DurationPTXHXMPT2H30M

Examples

index.htmlHTML
<!-- Date -->
<p>Published on <time datetime="2024-01-15">January 15, 2024</time></p>

<!-- Date and time -->
<p>Event starts at <time datetime="2024-03-20T19:00">March 20 at 7 PM</time></p>

<!-- Duration -->
<p>Video length: <time datetime="PT2H30M">2 hours 30 minutes</time></p>

<!-- Relative dates -->
<p>Updated <time datetime="2024-01-15">3 days ago</time></p>

Benefits

  • Search engines understand temporal info
  • Assistive technologies can parse dates
  • Browsers can add calendar events