Countdown
Time left until a date, or through a timer, drawn as segments, a clock or a phrase, and kept current to the second.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
date | Date | string | number | undefined | undefined | The moment to count down to: an ISO 8601 string or a millisecond timestamp in markup, or a Date from script. Wins over duration. |
duration | number | undefined | undefined | Length of a timer in seconds, used when date is unset. The timer starts when the element connects, unless paused; changing it restarts the timer. |
units | string | days hours minutes seconds | The units to show, largest first, from days, hours, minutes and seconds. The largest absorbs the rest: hours minutes shows two days as 48 hours. |
display | CountdownDisplay | segments | segments draws a box per unit with its name, clock draws 14:05:31, inline writes a phrase such as "2 days 14 hours". |
format | CountdownFormat | long | Length of the unit names: long ("hours"), short ("hr") or narrow ("h"). |
trim | boolean | false | Leave out the leading units that are zero: three hours left read "3 hours 12 minutes", not "0 days 3 hours 12 minutes". |
warn-at | number | 0 | Seconds left under which the element is in its warning state (:state(warning), coloured by --c2-countdown__warning--color). 0 turns it off. |
paused | boolean | false | Stop the countdown where it is. A timer resumes from the same point; a countdown to a date catches up with the time that passed. |
locale | string | — | BCP 47 locale of the unit names and digits. Empty uses the nearest lang attribute, then the browser's language. |
Slots
| Name | Description |
|---|---|
ended | Content shown in place of the digits once the time is over, such as "We are live!". |
Events
| Name | Type | Description |
|---|---|---|
tick | CustomEvent | Fired whenever the shown value changes; detail.remaining is the time left in milliseconds. |
complete | Event | Fired once when the countdown reaches zero while the element is on the page. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
segment | The box around one unit's value and label (display="segments"). |
value | The digits of one unit (display="segments"). |
label | The unit name under its digits (display="segments"). |
separator | The colon between two segments, hidden unless --c2-countdown__separator--display shows it. |
text | The clock or phrase (display="clock" and display="inline"). |
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-countdown--color | color | inherit | Text colour of the clock and the phrase. |
--c2-countdown--font-size | font-size | inherit | Size of the clock and the phrase. |
--c2-countdown--font-weight | font-weight | inherit | Weight of the clock and the phrase. |
--c2-countdown--font-variant-numeric | string | tabular-nums | Digit style; tabular digits keep a ticking value from shifting the text around it. |
--c2-countdown--gap | length | 8px | Space between segments (and their separators). |
--c2-countdown__segment--background-color | color | #f4f4f5 | Background of a segment. |
--c2-countdown__segment--border | border | 1px solid #e4e4e7 | Border of a segment. |
--c2-countdown__segment--border-radius | length | 8px | Corner radius of a segment. |
--c2-countdown__segment--padding | length | 12px | Inner spacing of a segment. |
--c2-countdown__segment--min-width | length | 64px | Smallest width of a segment, so the boxes line up while the digits change. |
--c2-countdown__segment--gap | length | 4px | Space between a segment's digits and its label. |
--c2-countdown__value--color | color | #18181b | Colour of a segment's digits. |
--c2-countdown__value--font-size | font-size | 32px | Size of a segment's digits. |
--c2-countdown__value--font-weight | font-weight | 600 | Weight of a segment's digits. |
--c2-countdown__value--font-family | string | inherit | Typeface of a segment's digits. |
--c2-countdown__value--animation-duration | time | 0ms | Length of the roll-in played when a segment's digits change; 0ms draws them still. Reduced motion always draws them still. |
--c2-countdown__label--color | color | #52525b | Colour of a segment's unit name. |
--c2-countdown__label--font-size | font-size | 12px | Size of a segment's unit name. |
--c2-countdown__label--font-weight | font-weight | normal | Weight of a segment's unit name. |
--c2-countdown__label--text-transform | string | none | Case of a segment's unit name, such as uppercase. |
--c2-countdown__label--letter-spacing | length | normal | Letter spacing of a segment's unit name. |
--c2-countdown__separator--display | string | none | inline shows a colon between segments. |
--c2-countdown__separator--color | color | #a1a1aa | Colour of the colon between segments. |
--c2-countdown__separator--font-size | font-size | 32px | Size of the colon between segments. |
--c2-countdown__warning--color | color | #dc2626 | Colour of the digits and text while less than warn-at seconds are left. |
--c2-countdown__paused--color | color | #71717a | Colour of the digits and text while paused. |