HTML datetime Attribute

The HTML datetime attribute provides a machine-readable date or time value for the <time> element and identifies the date and optionally the time associated with a deletion when used on the <del> element.

Syntax

The datetime attribute is added to a <time> or <del> element and contains a machine-readable date or time value.

<time datetime="2026-09-19">September 19, 2026</time>

The text displayed to users can be written in a readable format while the datetime attribute provides a standardized value that software can process.

Attribute Value

The value of the datetime attribute depends on the element and can represent a date, time, date and time, duration, or other supported date-related value.

Value Description
Date or time value Provides a machine-readable representation of a date, time, date and time, duration, or another supported date-related value.

Elements That Use the datetime Attribute

The datetime attribute is used with the <time> and <del> elements.

Element Description
<time> Provides the machine-readable value represented by the element.
<del> Indicates the date and optionally the time when content was deleted.

Using datetime with the <time> Element

On a <time> element, the datetime attribute provides a machine-readable version of the date or time represented by the element.

<p>The tutorial was updated on
  <time datetime="2026-09-19">September 19, 2026</time>.
</p>

This allows the visible text to use a reader-friendly format without losing a standardized value that software can interpret.

Using datetime with the <del> Element

On a <del> element, the datetime attribute indicates when the content was removed from the document.

<p>The price is
  <del datetime="2026-09-19T14:30:00-07:00">$29.95</del>
  $24.95.
</p>

The date and time are metadata and are not displayed automatically by the browser.

Date and Time Formats

The datetime attribute uses standardized machine-readable formats. The formats available to <time> include dates, times, combined dates and times, months, weeks, years, and durations.

Example Represents
2026 Year
2026-09 Year and month
2026-09-19 Date
14:30 Time
2026-09-19T14:30:00-07:00 Date and time with a time-zone offset
2026-W38 Week
PT2H30M Duration of 2 hours and 30 minutes

Using a valid machine-readable format allows software to interpret the value reliably even when the visible text uses a different presentation.

Common Mistakes

Do not assume the datetime value is automatically displayed. The attribute contains metadata; the content between the element's tags is what users normally see.

Do not place a reader-friendly date such as September 19, 2026 in the attribute value. Use the appropriate machine-readable format, such as 2026-09-19.

When a time-zone offset is needed, include it as part of the date and time value rather than relying on the reader to infer the time zone.

Browser Support

Baseline: Widely available indicates a feature has been supported by core browsers for at least 30 months. At this stage, the feature is considered stable and safe for most websites to use without needing to worry about compatibility issues or fallbacks, as it is supported by the vast majority of users' devices and browser versions.

The datetime attribute and its established uses are widely supported in current core browsers. It is used with <time>, <del>, and <ins>.

Checking Browser Support

For current browser compatibility information, visit Can I Use? . Search for the HTML element or attribute you want to check. You can also narrow your search by entering an element name and attribute name separated by a colon. Search results can include related HTML features, element attributes, input types, APIs, and other technologies, so select the result that most closely matches the feature you are checking.

Try the datetime Attribute

The example uses datetime with the <time> and <del> elements to associate machine-readable dates with visible content.

Play in Editor

Summary

The HTML datetime attribute provides machine-readable date and time information. It is used with <time> to represent dates, times, and related values, and with <del> to indicate when content was deleted. The attribute provides metadata and does not change how the visible content is displayed.