I Created an Analog Clock Using Pure HTML, CSS and JavaScript
I have always been fascinated by clocks. I remember as a child being mesmerized by the clock in my grandparents’ home. I would watch the hands move around the dial, and the pendulum swing back and forth.
So, when I decided to learn HTML, CSS and JavaScript, I knew I wanted to create a clock. And I wanted to create it using only HTML, CSS and JavaScript – no frameworks or libraries.
It took me a while to figure out how to do it, but I finally succeeded. And it was a lot easier than I thought it would be.
The clock is a simple analog clock, and it uses only HTML, CSS and JavaScript. Here’s how it works:
The clock is made up of two elements: a
The
The clock face is a simple
The hands are a with a background color, a border, and some text. The text is formatted using CSS, and the border is added using the border-radius property.
The clock is powered by JavaScript. The JavaScript code calculates the time based on the current time and the time zone, and then rotates the to the correct position.
Here’s the code for the clock:
var clock = document.getElementById("clock-face");
var hand = document.getElementById("clock-hand");
var timeZone = "America/Los_Angeles";
function updateClock() {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
hand.innerHTML = hours +