View raw output
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Analog Clock</title>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: #1a1d24;
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.clock {
position: relative;
width: 340px;
height: 340px;
border-radius: 50%;
background: #f8f9fa;
border: 12px solid #2c313c;
box-shadow:
0 20px 50px rgba(0, 0, 0, 0.5),
inset 0 4px 10px rgba(0, 0, 0, 0.15);
}
.tick {
position: absolute;
left: 50%;
top: 0;
width: 2px;
height: 50%;
transform-origin: bottom center;
pointer-events: none;
}
.tick::before {
content: "";
display: block;
width: 2px;
height: 8px;
background: #adb5bd;
margin: 6px auto 0;
border-radius: 1px;
}
.tick.major::before {
width: 3px;
height: 14px;
background: #343a40;
}
.number {
position: absolute;
font-size: 1.35rem;
font-weight: 700;
color: #212529;
transform: translate(-50%, -50%);
user-select: none;
}
.hand {
position: absolute;
bottom: 50%;
left: 50%;
transform-origin: bottom center;
border-radius: 4px;
pointer-events: none;
}
.hand.hour {
width: 7px;
height: 26%;
background: #212529;
z-index: 3;
}
.hand.minute {
width: 5px;
height: 36%;
background: #343a40;
z-index: 4;
}
.hand.second {
width: 2px;
height: 42%;
background: #e03131;
z-index: 5;
}
.hand.second::after {
content: "";
position: absolute;
bottom: -18px;
left: 50%;
transform: translateX(-50%);
width: 4px;
height: 18px;
background: #e03131;
border-radius: 2px;
}
.center-dot {
position: absolute;
top: 50%;
left: 50%;
width: 14px;
height: 14px;
background: #e03131;
border: 3px solid #212529;
border-radius: 50%;
transform: translate(-50%, -50%);
z-index: 6;
}
</style>
</head>
<body>
<div class="clock" id="clock" aria-label="Analog Clock">
<div class="hand hour" id="hour-hand"></div>
<div class="hand minute" id="minute-hand"></div>
<div class="hand second" id="second-hand"></div>
<div class="center-dot"></div>
</div>
<script>
(function () {
const clock = document.getElementById("clock");
const hourHand = document.getElementById("hour-hand");
const minuteHand = document.getElementById("minute-hand");
const secondHand = document.getElementById("second-hand");
// Create 60 tick marks
for (let i = 0; i < 60; i++) {
const tick = document.createElement("div");
tick.className = i % 5 === 0 ? "tick major" : "tick";
tick.style.transform = `translateX(-50%) rotate(${i * 6}deg)`;
clock.appendChild(tick);
}
// Create numbers 1 to 12
const radiusPercent = 38;
for (let n = 1; n <= 12; n++) {
const num = document.createElement("div");
num.className = "number";
num.textContent = n;
const rad = (n * 30) * (Math.PI / 180);
const x = 50 + radiusPercent * Math.sin(rad);
const y = 50 - radiusPercent * Math.cos(rad);
num.style.left = `${x}%`;
num.style.top = `${y}%`;
clock.appendChild(num);
}
function updateClock() {
const now = new Date();
const ms = now.getMilliseconds();
const seconds = now.getSeconds() + ms / 1000;
const minutes = now.getMinutes() + seconds / 60;
const hours = (now.getHours() % 12) + minutes / 60;
const secondDeg = seconds * 6;
const minuteDeg = minutes * 6;
const hourDeg = hours * 30;
secondHand.style.transform = `translateX(-50%) rotate(${secondDeg}deg)`;
minuteHand.style.transform = `translateX(-50%) rotate(${minuteDeg}deg)`;
hourHand.style.transform = `translateX(-50%) rotate(${hourDeg}deg)`;
requestAnimationFrame(updateClock);
}
requestAnimationFrame(updateClock);
})();
</script>
</body>
</html>