---
title: "Duration"
description: "A length of time as text: short units (1m 8s), a clock (1:08), or words (1 minute, 8 seconds). It can count up or down live."
url: https://gelatinui.com/components/duration
markdown_url: https://gelatinui.com/components/duration.md
access: free
install: "npx shadcn@latest add @gelatin-ui/duration"
registry_item: https://gelatinui.com/r/duration.json
version: "2026-11-09"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Duration

> A length of time as text: short units (1m 8s), a clock (1:08), or words (1 minute, 8 seconds). It can count up or down live.

Page: https://gelatinui.com/components/duration

## When to use it

Best for: A length of time as text, in units, as a clock, or in words.

- Use `kind="units"` for 1m 08s.
- Use `since` to count up, and `until` to count down.
- Set `animated` to roll the digits.

## When not to use it

- For a time point such as 5 minutes ago, use [Time Ago](https://gelatinui.com/components/time-ago.md).
- For a timer with buttons, use a [Button](https://gelatinui.com/components/button.md).

## Notes for agents

- All live durations share one second clock.
- It renders a `time` element with the ISO length.
- Zero, a negative value, and `NaN` show the zero of their kind.

## Anatomy

```text
Duration
├─ DurationEmpty (0..n)
└─ DurationEnded (0..n)
```

## API reference

### Duration

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `seconds` | `number` |  | The length in seconds. A negative value or `NaN` shows as 0. With `since` or `until`, it is the value once the clock stops (`live` false), or the empty text. |
| `durationMs` | `number` |  | The length in milliseconds, in place of `seconds`: `2400` is "2.4s". |
| `value` | `string` |  | The length as an ISO 8601 duration, in place of `seconds`: `"PT1H30M"`, `"P1DT2H"`. Years and months have no fixed length, so `"P1M"` is invalid and shows `empty`. |
| `since` | `DateLike` |  | A live count-up: whole seconds since this time (a `Date`, ISO text, or epoch milliseconds) on the shared second clock (`useElapsedSeconds`), so only this part renders on a tick. A muted box of about the final width shows before hydration. |
| `until` | `DateLike` |  | A live count-down: whole seconds left until this time, rounded up. |
| `live` | `boolean` | true | Run the `since` or `until` clock. Default `true`; `false` shows `seconds` (the end value). |
| `now` | `DateLike` |  | A fixed now for `since` and `until` (tests, stories, a frozen view): no clock runs, and it shows before hydration too. |
| `onEnd` | `function` |  | Called once when an `until` clock reaches 0 while it runs. |
| `kind` | `DurationKind` | "units" | The look of the text. Default `units`. |
| `length` | `DurationLength` | "long" | The words of `kind="words"`: `long` (default) "1 minute, 8 seconds", `short` "1 min, 8 sec", `narrow` "1m 8s". |
| `fractionDigits` | `DurationDigits` | "auto" | The fraction digits of `units`. Default `auto`: one digit under 10s ("2.4s"), none from 10s on ("14s"). A live clock always shows whole seconds, so it ticks "1s", "2s", "3s". |
| `animated` | `boolean` | true | Roll the digits that change on the Rolling Number (`units` and `clock`). Default `true`. `false` prints plain text: for long lists and table cells. Words never roll. |
| `locale` | `string` |  | The BCP 47 locale ("de-DE"). Default: the `DisplayLocaleProvider` locale, else "en-US". |
| `children` | `ReactNode` |  | `DurationEmpty`, the words of no value, and `DurationEnded`, what shows in place of the time when an `until` clock is at 0 ("Done", "Expired"). Only the one for the current state draws. |

### DurationEmpty

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `data-slot` | `string` |  | The `data-slot` of the root: the item's own slot (`"time-ago"`). Default `"empty-value"`. |

Also takes every prop of Base UI `UseRender`: https://base-ui.com/react/components/use-render

### DurationEnded

No props of its own: `className`, `children`, and every other prop go to the element it renders.

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| Duration | `duration` |  |  | `motion-timing` |
| DurationEmpty | `duration-empty` |  |  |  |
| DurationEnded | `duration-ended` |  | `--duration-time` |  |

## Usage

Pass the length in seconds. Put a `DurationEmpty` inside for a step that has no time yet.

```tsx title="build-steps.tsx"
import { Duration, DurationEmpty } from "@/components/ui/duration";

const STEPS: { name: string; seconds?: number }[] = [
  { name: "Install", seconds: 14.2 },
  { name: "Typecheck", seconds: 3.8 },
  { name: "Deploy" },
];

export function BuildSteps() {
  return (
    <ul className="flex w-56 flex-col gap-1 text-sm">
      {STEPS.map((step) => {
        return (
          <li key={step.name} className="flex justify-between">
            {step.name}
            <Duration seconds={step.seconds} className="text-muted-foreground">
              <DurationEmpty>Waiting</DurationEmpty>
            </Duration>
          </li>
        );
      })}
    </ul>
  );
}
```

## Compose

Rules:

- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui/duration
```

It adds 31 registry items: 30 files, 5757 lines, and the npm packages `@base-ui/react`, `@internationalized/date`, `clsx`, `motion`, `tailwind-merge`, `tailwind-variants`.

## Built on

- [Rolling Number](https://gelatinui.com/components/rolling-number.md)

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Time Ago](https://gelatinui.com/components/time-ago.md)
- [Countdown](https://gelatinui.com/components/countdown.md)
- [Clock](https://gelatinui.com/components/clock.md)

## Accessibility

The `time` element holds the exact ISO length.

## Motion

| Part | Motion |
| --- | --- |
| Digits | panel · 260ms · the digits roll when `animated` is on |
