Relative time
Shows when something happened, or will happen, as "3 minutes ago" or "in 2 hours", and keeps the text current.
Example
Comment posted
Invoice sent
Next backup
Zuletzt gespeichert
<p> Comment posted <focsd-relative-time datetime="2026-10-15T10:41:00Z"></focsd-relative-time></p><p> Invoice sent <focsd-relative-time datetime="2026-10-05T09:00:00Z" format="auto"></focsd-relative-time></p><p> Next backup <focsd-relative-time datetime="2026-10-16T02:00:00Z"></focsd-relative-time></p><p lang="de"> Zuletzt gespeichert <focsd-relative-time datetime="2026-10-15T09:30:00Z"></focsd-relative-time></p>Usage
Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.
<script type="module"> import '@focsd-dev/components/focsd-relative-time.js';</script>
<focsd-relative-time datetime="2026-10-15T10:41:00Z"></focsd-relative-time>import { RelativeTime } from '@focsd-dev/react';
export function Example() { return <RelativeTime datetime="2026-10-15T10:41:00Z"></RelativeTime>;}<script setup>import '@focsd-dev/components/focsd-relative-time.js';</script>
<template> <focsd-relative-time datetime="2026-10-15T10:41:00Z"></focsd-relative-time></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-relative-time.js';
// template<focsd-relative-time datetime="2026-10-15T10:41:00Z"></focsd-relative-time><script> import '@focsd-dev/components/focsd-relative-time.js';</script>
<focsd-relative-time datetime="2026-10-15T10:41:00Z"></focsd-relative-time>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
datetime | datetime | string | — |
format | format | 'relative' | 'auto' | relative |
frozen | frozen | boolean | false |
locale | locale | string | — |
CSS parts
Style the inside of the component with ::part(), for example focsd-relative-time::part(time).
| Part | Description |
|---|---|
time | The `<time>` element. |
Accessibility
- The text sits in a
<time>element whosedatetimeis the exact moment, so scripts and machines can read it. - The full date and time follows the relative text as visually hidden text, so a screen reader reads "3 minutes ago, October 15, 2026 at 10:41 AM". The same text is the tooltip.
- It has no live region: the text updates once a minute (once an hour for older times) without being announced, which would be noise.
- With
format="auto", times more than 7 days away show the date instead, which is easier to place than "3 weeks ago". - Without
localeit follows the nearestlangattribute. Withlocalethe text carries thatlang, so screen readers read it in that language. - Server-rendered pages show the text for the moment the server rendered it; it corrects itself when the element loads in the browser.
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.