DOM Package
The DOM package provides vanilla JavaScript classes for rendering clocks in any web application.
Installation
# npm
npm install @clock-ui/dom
# yarn
yarn add @clock-ui/dom
# pnpm
pnpm add @clock-ui/dom
# bun
bun add @clock-ui/domCDN Usage
You can also use Clock UI directly from a CDN without installation. This is perfect for quick prototyping, CodePen examples, or when you don't want to set up a build system.
Via UNPKG
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Clock UI CDN Example</title>
<!-- Include Clock UI CSS -->
<link
rel="stylesheet"
href="https://unpkg.com/@clock-ui/dom/dist/index.css"
/>
</head>
<body>
<!-- Clock containers -->
<div id="static-clock" style="width: 200px; height: 200px;"></div>
<div id="live-clock" style="width: 200px; height: 200px;"></div>
<!-- Include Clock UI JavaScript -->
<script src="https://unpkg.com/@clock-ui/dom/dist/index.umd.js"></script>
<script>
// Static clock
const staticClock = new clockui.LiveClockUI("#static-clock", {
hours: 10,
minutes: 30,
seconds: 45,
useRoman: true,
});
// Live clock
const liveClock = new clockui.LiveClockUI("#live-clock", {
smoothSweep: true,
timezone: "America/New_York",
});
// Cleanup when page unloads
window.addEventListener("beforeunload", () => {
staticClock.destroy();
liveClock.destroy();
});
</script>
</body>
</html>Via jsDelivr
<!-- CSS -->
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@clock-ui/dom/dist/index.css"
/>
<!-- JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/@clock-ui/dom/dist/index.umd.js"></script>Specific Version
<!-- Use a specific version for production -->
<link
rel="stylesheet"
href="https://unpkg.com/@clock-ui/dom@0.1.1/dist/index.css"
/>
<script src="https://unpkg.com/@clock-ui/dom@0.1.1/dist/index.umd.js"></script>CDN with ES Modules
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Clock UI ES Modules</title>
<link
rel="stylesheet"
href="https://unpkg.com/@clock-ui/dom/dist/index.css"
/>
</head>
<body>
<div id="clock" style="width: 200px; height: 200px;"></div>
<script type="module">
import { LiveClockUI } from "https://unpkg.com/@clock-ui/dom/dist/index.umd.js";
const clock = new LiveClockUI("#clock", {
timezone: "Europe/London",
smoothSweep: true,
});
// Optional: Add custom styling
document
.getElementById("clock")
.style.setProperty("--cui-primary-color", "#ff6b6b");
</script>
</body>
</html>CodePen Example
<div id="clock" style="width: 200px; height: 200px;"></div>
<script src="https://unpkg.com/@clock-ui/dom/dist/index.umd.js"></script>
<link rel="stylesheet" href="https://unpkg.com/@clock-ui/dom/dist/index.css" />
<script>
const clock = new clockui.LiveClockUI("#clock", {
smoothSweep: true,
useRoman: true,
});
</script>Usage
Base Clock
Display a static clock at a specific time.
<div id="clock"></div>import { BaseClockUI } from "@clock-ui/dom";
const clock = new BaseClockUI("#clock", {
hours: 10,
minutes: 30,
seconds: 45,
});Live Clock
Display a live clock that updates in real-time.
<div id="live-clock"></div>import { LiveClockUI } from "@clock-ui/dom";
const liveClock = new LiveClockUI("#live-clock", {
smoothSweep: true,
timezone: "America/New_York",
});Options
Common Options
hideSeconds: Hide the second handhideNumbers: Hide hour numbersuseRoman: Use Roman numeralscardinalOnly: Show only 3, 6, 9, 12noBorder: Remove clock borderhideTicks: Hide all tickshideMajorTicks: Hide hour tickshideMinorTicks: Hide minute ticksdualTone: Enable dual-tone styling
BaseClockOptions
Extends CommonClockOptions with:
hours: Hour (0-23)minutes: Minutes (0-59)seconds: Seconds (0-59)milliseconds: Milliseconds
LiveClockOptions
Extends CommonClockOptions with:
smoothSweep: Smooth second handtimezone: Timezone stringhideDate: Hide date display
API
BaseClockUI
update(options): Update clock time/optionsdestroy(): Clean up
LiveClockUI
start(): Start animationstop(): Stop animationsetTimezone(tz): Change timezonedestroy(): Clean up
Tick duration
LiveClockUI eases the second hand to each new mark over 600ms by default, with a slight overshoot. Pass tickDuration to change how long that swing takes — a real quartz movement lands in roughly 50-150ms.
new LiveClockUI("#clock", { tickDuration: 150 }); // crisper
new LiveClockUI("#clock", { tickDuration: 0 }); // no swing at allThe hand settles on the exact second either way; this only changes how long it takes to get there. Sweep mode ignores it, since it moves continuously.