The time element represents a specific period in time, providing a machine-readable datetime value while displaying a human-readable format to users.
Description
The <time> element represents a specific moment or range of time. It encodes dates and times in a machine-readable format via the datetime attribute while displaying human-friendly text. Search engines, browser features and scripts (including VB's formatters below) read datetime; people, including screen reader users, get the visible text.
When to Use
- Publication dates — Blog posts, articles, news
- Event times — Meetings, appointments, concerts
- Deadlines — Due dates, expiration dates
- Historical dates — Birthdays, anniversaries, milestones
- Durations — Length of videos, podcasts, events
When Not to Use
- For vague time references ("Last week", "Soon") with no specific datetime
- For non-Gregorian dates that can't be represented in ISO 8601
- For machine-readable non-temporal values — use
<data>
Basic Usage
Standard time element with tabular numeric font for consistent digit widths.
<p>Published on <time datetime="2026-01-15">January 15, 2026</time></p><p>Updated on <time datetime="2026-02-20">February 20, 2026</time></p>
Relative Time
The relative class is styling only: muted, smaller text. It does not change the text. To keep "3 days ago" text current, pair it with one of VB's two relative-time scripts. Write an absolute date as the element's text, so readers without JavaScript still get a correct date.
<p>Posted <time class="relative" datetime="2026-02-23T09:00:00Z" data-relative>February 23, 2026</time></p><p>Due <time class="relative" datetime="2027-01-15T12:00:00Z" data-format-date="relative">January 15, 2027</time></p>
data-relative
time[data-relative] is the lightweight past-only formatter used by <activity-feed>, <comment-thread> and <time-index>. It is part of the main bundle and needs no setup. It rewrites the text to "just now", "5 minutes ago", "3 days ago" and so on, and refreshes every 60 seconds. Future dates are left as written. Text is English unless the nearest [lang] is another language, in which case it uses Intl.RelativeTimeFormat.
Choosing a relative-time mechanism
| Mechanism |
What it does |
Future dates |
Refresh |
Locale |
time.relative |
Styling only (muted, small). Text is whatever you write. |
n/a |
None |
n/a |
time[data-relative] |
Rewrites text to "3 days ago" |
Ignored (text kept) |
Every 60s |
English; Intl for a non-English nearest [lang] |
time[data-format-date="relative"] |
Rewrites text with Intl.RelativeTimeFormat; original text moves to title |
"in 3 days" |
Adaptive: 60s, 5 min, then hourly |
data-locale, nearest [lang], <html lang>, browser |
Use data-format-date="relative" for new content: it handles future dates and every locale. data-relative exists for the components that render it.
Datetime Variant
Monospace font for technical datetime displays, such as log entries or API timestamps.
<p>Timestamp: <time class="datetime" datetime="2026-02-25T14:30:00">2026-02-25 14:30:00</time></p><p>With timezone: <time class="datetime" datetime="2026-02-25T14:30:00-05:00">2026-02-25 14:30:00-05:00</time></p>
Badge Variant
A bordered, rounded-corner chip in the monospace face for dates that need to stand out, such as event dates, release versions, or deadlines. Add the boolean data-badge attribute to any <time> element. It uses the raised surface, the default text colour and --color-border, so it keeps the page's text contrast in light and dark mode, and its border stays visible in forced-colours mode.
data-badge only styles <time>. For status labels, counts or decorative ribbon, flag and stamp shapes use <layout-badge>; wrap it around the <time> if a date needs a coloured or shaped badge.
<p>Release date: <time data-badge datetime="2026-03-01">March 1, 2026</time></p><p>Event: <time data-badge datetime="2026-06-15T09:00">June 15, 2026 at 9:00 AM</time></p><p>Deadline: <time data-badge datetime="2026-04-30">April 30, 2026</time></p>
Dates, times, combined formats, and ISO 8601 durations.
VB provides locale-aware date formatting via the data-format-date attribute. Like <data>'s data-format-number, the visible text serves as a no-JS fallback and is replaced with formatted output on init. The original text moves to the element's title, so it stays available on hover.
| Attribute Value | Output (en-US) |
data-format-date (empty) | Feb 9, 2026 (medium) |
data-format-date="short" | 2/9/26 |
data-format-date="long" | February 9, 2026 |
data-format-date="full" | Monday, February 9, 2026 |
data-format-date="relative" | "2 days ago", "in 3 hours" |
Date-only values (2026, 2026-02, 2026-02-09) are formatted in UTC, so the day never shifts with the reader's time zone, and keep their precision: a year shows only the year, a month shows month and year. Add data-format-time for time display (short, medium, long, full) on values that have a time. The locale comes from data-locale, then the nearest [lang] ancestor, then <html lang>. See the i18n guide for locale resolution.
Contextual Usage
Time elements work naturally in article metadata, event listings, and other contextual patterns.
The datetime attribute uses ISO 8601 format:
| Format |
Example |
Represents |
YYYY |
2026 |
Year |
YYYY-MM |
2026-01 |
Month |
YYYY-MM-DD |
2026-01-15 |
Date |
HH:MM |
14:30 |
Time |
YYYY-MM-DDTHH:MM |
2026-01-15T14:30 |
Date and time |
YYYY-MM-DDTHH:MM:SS |
2026-01-15T14:30:00 |
With seconds |
...Z |
2026-01-15T14:30:00Z |
UTC timezone |
...+HH:MM |
2026-01-15T14:30:00+05:30 |
With timezone offset |
PTXHXMXS |
PT2H30M |
Duration |
Variant Summary
| Variant |
Selector |
Use Case |
| Default |
time |
Standard dates with tabular numerals |
| Relative |
time.relative |
Muted styling for relative displays (pair with data-relative or data-format-date="relative") |
| Datetime |
time.datetime |
Technical timestamps in monospace |
| Badge |
time[data-badge] |
Bordered chip emphasis for key dates |
CSS Properties
time { font-variant-numeric: tabular-nums;} time.relative { color: var(--color-text-muted); font-size: var(--font-size-s);} time.datetime { font-family: var(--font-mono); font-size: 0.9em;} time[data-badge] { display: inline-block; background: var(--color-surface-raised); padding: var(--size-2xs) var(--size-xs); border-radius: var(--radius-s); border: var(--border-width-thin) solid var(--color-border); font-family: var(--font-mono); font-size: 0.9em;}
Accessibility
- Screen readers read the visible text content. Mainstream screen readers do not expose the
datetime value, so the visible text must be unambiguous on its own: prefer "9 February 2026" over "2/9/26".
- Timezone clarity — include timezone information when relevant to avoid ambiguity
- Relative times — keep them current with
data-relative or data-format-date="relative", and write the actual date as the fallback text