The datetime attribute gives a machine-readable date, time, or duration while the element’s text stays easy for people to read. It is used on <time>, <ins>, and <del>.
On <time> it marks when something happens. On <ins> / <del> it records when content was added or removed (often with cite for a change URL).
Baseline · Widely available.
Not deprecated and not experimental. The <time> element and datetime are stable across modern browsers.
Deprecated: pubdate.
The old pubdate boolean on <time> is obsolete. Use datetime for the precise value instead.
Syntax
HTML Syntax
syntax.html
<time datetime="value">human text</time>
Same attribute name on <ins> and <del>. The value must match a valid date, time, datetime, week, year, or duration string.
Values
Attribute Values
Common valid forms (HTML living standard / ISO 8601 style):
Duration: start with P, use T before hours/minutes — PT2H30M.
Separate elements for start vs length keep each value clear.
Labels can differ from the attribute as long as they mean the same thing.
Example 3 — When Text Was Changed
On <ins> / <del>, datetime timestamps the edit.
HTML
<p>"You're late!"</p>
<del datetime="2018-05-01">
<p>"I apologize for the delay."</p>
</del>
<ins cite="/changelog" datetime="2018-05">
<p>"A wizard is never late …"</p>
</ins>
datetime says when the change happened (date or month is fine).
cite (optional) points to a document that explains the change.
Browsers typically strike through del and underline ins.
Edge Cases & Pitfalls
Most issues come from invalid formats or mixing human text with machine rules.
format
Invalid strings lose the timestamp
If the value cannot be parsed, the element has no associated machine date. Stick to documented microsyntaxes.
time
Omitting datetime has rules
Without datetime, <time> must not have element children, and its text must be a valid date/time string.
history
Avoid pre-Gregorian dates
MDN notes <time> is not for dates before the Gregorian calendar — those calculations are unreliable in HTML.
js
Property is dateTime
In JavaScript the IDL name is camelCase with a capital T: element.dateTime, not datetime.
obsolete
Do not use pubdate
That attribute is obsolete. Publication timing belongs in datetime (and your own metadata if needed).
Compatibility
Browser Support
datetime is an HTML attribute for time, ins, and del in the browser. It is not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
datetime
Widely available with the HTML5 time and modification elements. Desktop and mobile browsers parse the attribute; styling of time/ins/del is consistent enough for everyday use.
96%Global support (approx.)
Google Chrome31+
Full support
Mozilla Firefox22+
Full support
Apple Safari7+
Full support
Microsoft Edge12+
Full support
Opera18+
Full support
Samsung InternetModern
Full support
Internet Explorer9+ (partial)
Partial
datetimeWidely supported
Bottom line: Safe to use for semantic dates today. Treat datetime as metadata — browsers do not auto-format the visible text from it.
Remember
Key Takeaways
Role: machine-readable date, time, or duration alongside human text.
Elements:<time>, <ins>, and <del>.
Formats: dates, times, datetimes with offsets, weeks/months, and P… durations.
JS: use element.dateTime (capital T). Skip obsolete pubdate.
One line:datetime is the precise value; the element text is what humans read.
Frequently Asked Questions
It stores a machine-readable date, time, or duration (usually ISO 8601) while the element’s visible text stays human-friendly. Search tools and scripts can read the precise value.
time, ins, and del. It is most common on time. On ins and del it records when content was inserted or deleted.
No. It is optional. If you omit it, the time element’s text content must itself be a valid date/time string and the element must not contain other elements.
Common forms include YYYY-MM-DD, HH:MM, YYYY-MM-DDTHH:MM with optional timezone (Z or ±HH:MM), YYYY-MM, YYYY-Www, and durations such as PT2H30M.
Use the dateTime property (capital T) on the element, for example timeEl.dateTime = "2018-07-07". You can also use setAttribute("datetime", value).
No. pubdate on time is obsolete. Use datetime for the machine-readable value instead.