# `<time>`

> The `<time>` HTML element represents a specific period in time or a date, typically in a machine-readable format.

## How do I use the `<time>` element and its datetime attribute?

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.

- Topic: Semantics
- Type: tag
- Browser support: Chrome 62+, Chrome Android 62+, Edge 14+, Firefox 22+, Firefox Android 22+, Safari 7+, Safari iOS 4+

## Example

Wrong:

```html
<time datetime="May 1st">
  May 1
</time>
```

Right:

```html
<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.

## Related cards

- [`<data>`](https://wonderium.dev/html/data.md)
- [time](https://wonderium.dev/a11y/time.md)
- [.toISOString()](https://wonderium.dev/js/date-to-iso-string.md)
- [Intl.DateTimeFormat](https://wonderium.dev/js/intl-datetime-format.md)
- [Schema Markup](https://wonderium.dev/web/schema-markup.md)

---

- Level: [HTML](https://wonderium.dev/html.md)
- HTML version: https://wonderium.dev/html/time
- Last updated: 2026-11-25
