Definition and Usage
The datetime attribute specifies a standardized, machine-readable date or time for the element.
Basic Example
<p>
The concert was held <time datetime="2001-05-15 19:00">yesterday</time>.
</p>
The concert was held .
Applicable Elements and Uses of the datetime Attribute
The datetime attribute is not required; it is optional and can be used as needed.
When users view a web page, the value of the datetime attribute is not displayed. However, by using the datetime attribute to specify a standardized, machine-readable date or time related to the content, content authors, screen readers, and search engines can better understand and process the information.
Valid datetime Values
This standardized, machine-readable date or time refers to a valid value of the datetime attribute and must conform to one of the appropriate formats listed in the table below.
Valid datetime Value Format | Example |
|---|---|
| Valid year string | 2011
(Represents the year only) |
| Valid year-month string | 2011-11
(Represents the year and month) |
| Valid year-month-day string | 2011-11-18
(Represents the year, month, and day) |
| Valid month-day string | 11-18
(Represents the month and day) |
| Valid week string | 2011-W47
(Indicates the 47th week of 2011) |
| Valid time string | 14:54(Represents the hour and minute) 14:54:39(Represents hour, minute, and second) 14:54:39.929(Represents hour, minute, second, and millisecond) |
| Valid time-zone offset string | Z(UTC (Coordinated Universal Time, zero offset) – equivalent to +00:00) +0000(UTC with no offset) +00:00(UTC with no offset, colon added for readability) -0800(8 hours behind UTC – e.g., Pacific Standard Time (PST)) -08:00(Same as above, but colon included for readability) |
| Valid local date and time string | 2011-11-18T14:54:39.929(Date and time separated by a 'T') 2011-11-18 14:54:39.929(Date and time separated by a space) |
| Valid international date and time string (Indicates UTC timezone) |
2011-11-18T14:54:39.929Z2011-11-18T14:54:39.929-04002011-11-18T14:54:39.929-04:002011-11-18 14:54:39.929Z2011-11-18 14:54:39.929-04002011-11-18 14:54:39.929-04:00 |
| Valid duration string | PT4H18M3S(Represents a duration of hours, minutes, and seconds) |
Examples
Check out how the datetime attribute is used with the <del>, <ins>, and <time> tags through the following examples.
Using the cite attribute with <del>
<p>
The following feature has been removed.
<del cite="https://example.com/changelog" datetime="2022-11-14">
Details about the removed feature...
</del>
</p>
In this example, the datetime attribute specifies the date or time when the content was deleted within the <del> tag.
Using the cite attribute with <ins>
<p>
This is a description of the latest update.
<ins cite="https://example.com/changelog" datetime="2022-11-14">
Details about the latest update...
</ins>
</p>
In this example, the datetime attribute specifies the date or time when the content was inserted within the <ins> tag.
Using the cite attribute with <time>
<p>
The next meeting is scheduled for <time datetime="2023-09-11T14:30:00">2:30 PM tomorrow</time>.
</p>
In this example, the datetime attribute specifies an explicit date and time within the <time> tag.
Specifications
| Specification | |
|---|---|
<ins>,<del> datetime
|
HTML Standard #attributes-common-to-ins-and-del-elements |
<time> datetime
|
HTML Standard #attr-time-datetime |
Browser compatibility
The datetime attribute has the following browser compatibility across supported tags.
| Attribute |
Desktop Chrome
|
DesktopDesktop Edge
|
Desktop Firefox
|
Safari
|
|---|---|---|---|---|
<del> datetime
|
1 | 12 | 1 | 4 |
<ins> datetime
|
1 | 12 | 1 | 4 |
<time> datetime
|
62 | 18 | 22 | 7 |