Relative Time
Time relative to now, such as "3 minutes ago" or "in 2 days", that keeps itself current and shows the full date on hover.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
date | Date | string | number | undefined | undefined | The moment to describe: an ISO 8601 string or a millisecond timestamp in markup, or a Date from script. |
format | RelativeTimeFormat | long | Length of the phrase: long ("3 minutes ago"), short ("3 min. ago") or narrow ("3m ago" in some locales). |
numeric | RelativeTimeNumeric | auto | auto uses words such as "yesterday", "tomorrow" and "now"; always keeps a number ("1 day ago"). |
locale | string | — | BCP 47 locale of the phrase and the full date. Empty uses the nearest lang attribute, then the browser's language. |
min-unit | RelativeTimeUnit | second | Smallest unit counted: second, minute, hour, day, week, month or year. With minute, a date less than
a minute away reads as "now" and the phrase never counts seconds, so it redraws at most once a minute. |
no-update | boolean | false | Draw the phrase once and stop updating it as time passes. |
Slots
| Name | Description |
|---|---|
(default) | Fallback content shown while date is unset or not a valid date. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
time | The <time> element holding the phrase, with the machine-readable datetime and the full date as its title. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-relative-time--color | color | inherit | Colour of the phrase; inherits the surrounding text colour. |
--c2-relative-time--font-size | font-size | inherit | Size of the phrase. |
--c2-relative-time--font-weight | font-weight | inherit | Weight of the phrase. |
--c2-relative-time--font-variant-numeric | string | tabular-nums | Digit style; tabular digits keep a ticking value from shifting the text after it. |
--c2-relative-time--white-space | string | nowrap | Whether the phrase may wrap between its words. |