Analog Clock
UI Coding
Medium
30 min
svg
timers
effects
accessibility
Build an analog clock showing the current local time.
Requirements
- Draw it with SVG: a face, 12 hour ticks (the 3, 6, 9 and 12 positions more prominent) and three hands: hour, minute and second.
- The hands move continuously in the correct proportions:
- the hour hand advances between hours (at 3:30 it's halfway between 3 and 4)
- the minute hand advances with the seconds
- the second hand ticks once per second.
- Update every second, aligned to the real second boundary, and clean up on unmount.
- The whole clock is one image for assistive tech:
role="img"and an accessible name such as "Current time 3:45 PM". Its parts are hidden from the accessibility tree. Don't announce every tick. - The clock scales with its container (use
viewBox). - Accept an optional
sizeprop (default 240 px).
Follow-up
- When the second hand goes from 59 to 0, a CSS transition spins it backwards the whole way round. How do you avoid that?
- Smooth sweeping hands:
requestAnimationFrame, CSS animation, or something else? - How would you show a different time zone?
Spotted a mistake or a rights concern? Report an issue