Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

data-format-date

Locale-aware date and relative time formatting via data attributes.

Overview

The data-format-date attribute enhances native <time> elements by replacing their text content with a locale-aware formatted date. Supports both absolute date formats and auto-refreshing relative time strings.

How It Works

  1. Reads the datetime attribute from the <time> element
  2. For absolute styles: formats using Intl.DateTimeFormat with the specified dateStyle, and keeps the authored text as the title tooltip
  3. For "relative": formats using Intl.RelativeTimeFormat, puts the exact date and time in title, and starts an adaptive auto-refresh
  4. Formats again whenever datetime, data-format-date, data-format-time, data-time-zone, data-locale or a lang attribute changes

The locale is resolved in this order: data-locale on the element, the nearest ancestor with a lang attribute (so a <section lang="de"> formats its dates in German), <html lang>, then the browser language.

Attributes

Attribute Type Description
data-format-date string Date style: "" / "medium" (default), "short", "long", "full", "relative".
datetime string Standard HTML datetime attribute. Must be a valid date string (ISO 8601 recommended). An invalid or missing value leaves the text as written.
data-format-time string Optional time style: "short", "medium", "long", "full". Ignored for "relative" and for date-only values.
data-time-zone string Optional IANA time zone (e.g. "Europe/Paris") for date-time values. Default: the viewer's zone. Unknown zones are ignored. Date-only values always format as calendar dates.
data-locale string Optional locale override (e.g., "de-DE"). Defaults to the nearest [lang], then <html lang>, then the browser locale.
title string Set automatically unless you author one: the original text for absolute styles, the exact date and time for "relative".
data-format-date-init boolean State hook, set once the element is enhanced. Read it for styling or tests; do not set it. Enhancement is tracked internally, so a cloned element is still formatted when it is inserted.

Absolute Date Styles

Date styles map directly to Intl.DateTimeFormat's dateStyle option:

Date-Only Values

A datetime with no time part names a calendar date, not an instant. VB formats YYYY, YYYY-MM and YYYY-MM-DD values in UTC, so 2026-02-09 shows 9 February in every time zone (a plain new Date('2026-02-09') would show 8 February west of UTC). The precision is kept: a year shows only the year, a month shows month and year, and data-format-time is ignored.

With Time

Add data-format-time to include the time component:

Time Zones

Values with a time (2026-02-09T14:30Z) are instants. By default they format in the viewer's time zone, so a reader in Tokyo and one in New York see different clock times for the same moment. When the time belongs to a place — a meetup in Paris, a store's opening hours — set data-time-zone, and add data-format-time="full" if readers need to see the zone name.

Relative Time

Use data-format-date="relative" for auto-refreshing relative time strings like "3 hours ago" or "in 2 days". The exact date and time go into the title tooltip. Write the real date as the fallback text, so readers without JavaScript still see when it happened.

The demo stamps its datetime values relative to the moment you open it, so the phrases stay current. A real page renders datetime on the server.

Auto-Refresh Intervals

Relative times update automatically on an adaptive schedule:

Age of timestamp Refresh interval
< 1 hour Every 60 seconds
< 24 hours Every 5 minutes
> 24 hours Every hour

Timers stop when an element is removed from the DOM. Units round up to the next larger one when they reach it, so 350 days reads "last year", not "12 months ago".

Locale Override

Use data-locale to force a specific locale for formatting:

Plain ja-JP formats with the Gregorian calendar. Add the BCP 47 calendar extension -u-ca-japanese for era dates; data-format-date="short" then gives the form-field abbreviation R8/2/9. See Internationalization for setting it page-wide.

Common Use Cases

Activity Feeds

Show when events happened in a list (live in the relative-time demo above):

Content Metadata

Display article or post timestamps:

Dynamic Elements

Elements added to the DOM after page load are automatically enhanced via a MutationObserver. No manual initialization is needed. Changing datetime later re-formats the element (and restarts a relative refresh). A relative element that is removed and reinserted (for example when a list is re-sorted) picks up a fresh refresh timer, and a cloned element is formatted like a new one.

Progressive Enhancement

The <time> element's original text serves as a fallback when JavaScript is unavailable. Users always see a readable date, with formatting layered on top.

Accessibility

  • The visible text is what screen readers announce; title is not reliably exposed. Keep the visible text unambiguous, and use an absolute style where the exact date matters.
  • For relative times the exact date and time are in the title tooltip, and the cursor: help style hints that it is there.
  • Relative refreshes rewrite the text silently: there is no live region, so a page full of timestamps does not interrupt a screen-reader user every minute.
  • Mainstream screen readers announce the visible text, not the datetime value. datetime serves search engines, browser features and scripts.
  • Falls back to the original text content when JavaScript is unavailable
  • No wrapper element — the <time> is the enhanced element, keeping the accessibility tree clean

Related

  • <time> — the element this attribute enhances.
  • Choosing a relative-time mechanism — data-format-date="relative" versus time[data-relative]. Use data-format-date="relative" for new content: it handles future dates and every locale and puts the exact date in the tooltip. data-relative is the lightweight past-only formatter that <activity-feed>, <comment-thread> and <time-index> render.
  • <time-index> — a dated index of entries.
  • data-format-number and data-format-bytes — the same locale-aware formatting for numbers and file sizes.
  • datetime — the machine-readable value this attribute formats, and the date and time strings it accepts.
  • lang — the attribute the formatter reads for its locale when data-locale is not set.
↑