👀 Live Preview
A blog post published on a specific date, marked up semantically:
Published on

The <time> tag marks up dates, times, and durations with semantic meaning. This guide covers syntax, the datetime attribute, common use cases, styling, accessibility, and best practices for beginners.
Write valid <time> elements with human-readable text.
Provide machine-readable ISO 8601 values.
Mark event dates, schedules, and timestamps.
Express intervals like P3W or PT2H.
Know when to use specialized date markup.
Accessibility, SEO, and clean semantics.
<time> Tag?The time element (<time>) represents a specific date, time, or duration in HTML. It pairs human-readable text (what visitors see) with a machine-readable value in the datetime attribute (what browsers, scripts, and search engines parse).
Use <time> for blog publish dates, event schedules, opening hours, countdowns, and any content where the exact moment or duration matters.
Without semantic markup, dates are just plain text. With <time datetime>, assistive technology and search engines understand the precise value behind the visible label.
Wrap a human-readable date or time in <time> and set the standardized value in datetime:
<time datetime="YYYY-MM-DDTHH:mm:ss">Your Time Content Here</time>datetime is optional but strongly recommended for clarity and parsing.<time> is an inline phrasing element—it fits inside paragraphs, lists, and headings.datetime (see the formats table below).pubdate attribute; place publication <time> inside <article> instead.<time datetime="2024-01-30T12:30:00">January 30, 2024 at 12:30 PM</time>| Use Case | datetime Value | Visible Text Example |
|---|---|---|
| Date only | 2024-01-30 | January 30, 2024 |
| Date & time | 2024-02-15T18:00:00 | February 15, 2024, at 6:00 PM |
| Time only | 18:00 | 6:00 PM |
| Duration (weeks) | P3W | 3 weeks |
| Duration (hours) | PT2H30M | 2 hours 30 minutes |
| Month & year | 2024-06 | June 2024 |
datetime FormatsHTML expects ISO 8601 strings in the datetime attribute. These are the formats beginners use most often:
| Format | Pattern | Example |
|---|---|---|
| Valid date | YYYY-MM-DD | 2024-01-30 |
| Valid local date-time | YYYY-MM-DDTHH:mm:ss | 2024-01-30T12:30:00 |
| Valid time | HH:mm or HH:mm:ss | 18:00 |
| Valid duration | PnYnMnDTnHnMnS | P3W, PT2H30M |
| Valid month | YYYY-MM | 2024-06 |
| Valid year | YYYY | 2024 |
<time> vs <data>| Feature | <time> | <data> |
|---|---|---|
| Purpose | Dates, times, durations | Any machine-readable value |
| Key attribute | datetime | value |
| Example | <time datetime="2024-06-10">Jun 10</time> | <data value="42">forty-two</data> |
| When to choose | Calendar dates, clocks, intervals | Prices, ratings, SKUs, generic values |
The datetime attribute is the heart of the <time> tag. Global attributes also apply:
datetime RecommendedMachine-readable date, time, or duration in ISO 8601 format. Browsers expose it via the dateTime DOM property.
datetime="2024-01-30T12:30:00"class GlobalCSS hook for styling publication dates, event badges, or timestamps.
class="publish-date"title GlobalTooltip with extra context, such as timezone or full formatted date.
title="UTC+5:30"id GlobalUnique identifier for JavaScript or fragment links.
id="event-start"Note: The pubdate boolean attribute appeared in early HTML5 drafts but is obsolete. Use a <time> inside an <article> for publication dates instead.
Publication dates, event schedules, and durations with copy-ready code, live previews, and hands-on practice.
A blog post published on a specific date, marked up semantically:
Published on
Use <time> whenever you display a date, clock time, or duration that has a precise meaning for users, scripts, or search engines.
Mark when an article or blog post was published. Place the <time> inside an <article> so the date is clearly associated with that content:
<article>
<h2>Getting Started with HTML</h2>
<p>
Published on
<time datetime="2024-01-30T12:30:00">January 30, 2024</time>
</p>
</article>The primary purpose of <time> is to display a specific date and time within your content, such as an event or webinar start:
<p>
Join us on
<time datetime="2024-02-15T18:00:00">February 15, 2024, at 6:00 PM</time>
for our live webinar.
</p>Use the <time> tag to represent durations—time intervals such as project length, video runtime, or delivery estimates. Set datetime to an ISO 8601 duration:
<p>
The project took
<time datetime="P3W">3 weeks</time>
to complete.
</p><time>. Write natural language dates users can understand.datetime.Style publication badges, event highlights, and muted timestamps with classes on the element:
font-size Smaller meta textcolor Accent highlightbackground Badge/chip stylefont-variant-numeric Tabular digits/* Publication date meta */
time {
font-variant-numeric: tabular-nums;
}
.publish-date {
color: #64748b;
font-size: 0.875rem;
}
.event-time {
color: #2563eb;
font-weight: 600;
background: #eff6ff;
padding: 0.1rem 0.35rem;
border-radius: 4px;
}Live styled time elements
Published
Starts
Human-friendly date or duration text goes inside <time>.
ISO 8601 in datetime gives browsers and scripts an unambiguous parse.
JavaScript reads element.dateTime while readers see the inner text.
Readers get natural language; machines get ISO 8601—the best of both worlds in one inline element.
The <time> tag is supported in all modern browsers. Very old browsers treat it as a generic inline element but still show the text content.
Chrome, Firefox, Safari, Edge, and Opera fully support the <time> element and the datetime attribute.
Bottom line: Use <time datetime> confidently for dates, times, and durations in production today.
Mastering the <time> tag empowers you to provide accurate, accessible information about dates and times. Whether you mark publication dates on blog posts, schedule event start times, or express project durations, semantic time markup improves both user experience and machine understanding.
datetime attribute for machine-readable datesdatetime<time> inside <article>pubdate attributedatetimedatetime<time> for values that are not dates or durations<time>Bookmark these before you mark up your next event, blog post, or schedule.
<time> marks dates, times, and durations with meaning beyond plain text.
ISO 8601 in datetime is the authoritative machine-readable value.
Visible text for readers; datetime for parsers and scripts.
Use values like P3W or PT2H30M for intervals.
Safe to use in all browsers your users run today.
Compatibility<time> element represents a specific date, time, or duration. It shows human-readable text and stores a machine-readable ISO 8601 value in datetime.datetime is the authoritative value scripts and parsers use.YYYY-MM-DD for dates, YYYY-MM-DDTHH:mm:ss for date-times, and P3W or PT2H30M for durations.datetime to an ISO 8601 duration such as P3W (three weeks) and put readable text like “3 weeks” inside the element.pubdate was removed from the HTML spec. Mark publication dates with a <time datetime> inside the relevant <article> instead.<time> is specialized for dates, times, and durations via datetime. <data> is general-purpose and uses a value attribute for any machine-readable string.Practice <time datetime> for events, publications, and durations in the Try It editor.
5 people found this page helpful