HTML / HTML Attributes

HTML Datetime Attribute

Oct 12, 2022
3 min read
HTML datetime Attribute

Definition

The datetime attribute specifies a date, time, or both in a machine-readable format.

Applicable Elements

The datetime attribute can be used with the following elements:

HTML <del> datetime Attribute

The <del> tag indicates the content has been removed from the document. Browsers will display the <del> element with a line running through it.

The datetime attribute, when used with the <del> element, specifies the date and optionally the time that the text was deleted.

Syntax

<del datetime="2009-10-10T23:38-07:00">deleted</del>

Usage

  • The datetime’s attribute’s value must be a valid date string, with optional time.

Values

Values can include:

Examples

The example shows the date and time the text was marked as deleted:

<p>There are some <del datetime="2009-10-10T23:38-07:00" 
cite="Demonstrating del element">deleted words</del> in this paragraph</p>

HTML <ins> datetime Attribute

The <ins> tag indicates the content has been inserted into the document. Browsers will display the ins element as underlined.

The datetime attribute, when used with the <ins> element, specifies the date and optionally the time that the text was inserted.

Syntax

<ins datetime="2009-10-10T23:38-07:00">inserted words</ins>

Usage

  • The datetime’s attribute’s value must be a valid date string, with optional time.

Values

Values can include:

Examples

The example shows the date and time the text was marked as inserted.

<p>There are some <ins datetime="2009-10-10T23:38-07:00" 
cite="Demonstrating ins element">inserted words</ins> in this paragraph</p>

HTML <time> datetime Attribute

A <time> element represents a specific date, time, or duration. It must adhere to a valid syntax. You can specify a more readable (non-valid syntax) date or time by placing a valid version in an optional datetime attribute.

The datetime attribute, when used with the <time> element, specifies a machine-readable format of the <time> element.

Syntax

<time datetime="2021-03-05 20:00">Friday</time>

Usage

  • The datetime’s attribute’s value must be a valid date string, with optional time.

Values

Values should be both:

Examples

The example shows an example using the <time> element with the datetime attribute.

<p>I am going to the movies on <time datetime="2021-03-05 20:00">Friday</time>.</p>

Specification

The datetime HTML specification for each of the following elements is below:

Browser Support

The datetime has the following browser support:

Desktop

ChromeEdgeFirefoxIEOperaSafari
<del>YesYesYesYesYesYes
<ins>YesYesYesYesYesYes
<time>YesYesYesNoYesYes

Mobile

Android WebviewChrome AndroidFirefox AndroidOpera AndroidiOS SafariSamsung Internet
<del>YesYesYesYesYesYes
<ins>YesYesYesYesYesYes
<time>YesYesYesYesYesYes