Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Text

Pro

Clock Text for React

A live digital clock whose digits rise into place as they change, its separators pulsing with the seconds. For React with Base UI, when a page should show the time, here or anywhere.

Framework

Clock Text is a live digital clock. When a digit changes, the new one rises into its window as the old one leaves through the top, so only what changed moves: the seconds every second, the minutes once a minute. The separators pulse gently in time with the tick.

Use it for a status page, an event lobby, a kiosk, or a team page with the time where each office is. For a countdown to a date, use Countdown Text; for a running video timecode, Timecode Text; for "5 minutes ago", Relative Time Text. A small timer wakes on every second boundary and the digits move with CSS keyframe animations the install adds to your stylesheet, with no animation library; with reduced motion the digits change in place.

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Usage

import { ClockText } from "@/components/ui/clock-text";
<ClockText />

Demos

Time zones

timeZone tells the time in any IANA zone, such as Europe/London, with its daylight saving; unset, it's the visitor's own. seconds={false} shows hours and minutes only.

Preview width

12-hour

hour12 counts the hours from 1 to 12 with AM and PM, rather than from 00 to 23. The time is written in locale, en-US by default; blink={false} holds the separators still.

Preview width

Accessibility

It renders a <time> element whose dateTime is the current moment. Screen readers read the time once, as written (14:05:09), from a visually hidden copy; the moving digits are hidden from them. It doesn't announce the time as it changes, which every second would be noise; to mark it as a running clock, put it in an element with role="timer", which assistive technology doesn't read out unless asked. With reduced motion the digits change in place and the separators hold still.

FAQ

Why is it blank for a moment when the page loads?

The server can't know the visitor's time, so it renders an invisible placeholder as wide as the clock, and the browser fills in the time as soon as the page runs. The page never jumps, and the server and the browser render the same markup.

Does it drift?

No. Every tick waits for the next whole second on the visitor's clock, so the seconds change when the second does, and a tab that was in the background catches up on its next tick.

Which digits move?

Only those that changed: each digit has its own window, and a new value rises in while the old one leaves. A new hour moves the hour's digits, and the others stay still.

Do the digits jump in width?

No. The clock uses tabular figures, so every digit is as wide as a zero. A 12-hour clock gains a digit at ten o'clock, as any clock written that way does.

How do I write it the way my visitors do?

Pass locale, such as de-DE or fi-FI, for their separators and digits, and hour12 for a 12-hour clock. It's fixed to en-US by default so every visitor sees the same format.

What happens with reduced motion?

The digits change in place, without moving, and the separators hold still.

API Reference

ClockText

<time> data-slot="clock-text"

PropType
blink?boolean

Whether the separators pulse once a second, in time with the tick. @default true.

Default
true
hour12?boolean

A 12-hour clock with AM and PM, rather than 24 hours. @default false.

Default
false
locale?string

The locale the time is written in (its digits and separators). Fixed by default, so every visitor sees the same format.

Default
"en-US"
seconds?boolean

Whether it shows the seconds. @default true.

Default
true
timeZone?string

The IANA time zone it tells the time in, such as "Europe/London"; the visitor's own when unset.

render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Merged with the part's classes.

CSS variableType
--clock-text-durationstring

A digit's rise into its window (400ms).

All 97 text effects