4 min read
ā¢Question 38 of 49easyWhat 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
| Type | Format | Example |
|---|---|---|
| Date | YYYY-MM-DD | 2024-01-15 |
| Time | HH:MM | 14:00 |
| Datetime | YYYY-MM-DDTHH:MM | 2024-01-15T14:00 |
| Duration | PTXHXM | PT2H30M |
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