Creating a Digital Clock with HTML, CSS, and JavaScript #html #css #javascript #shorts

Posted by

How To Build Digital Clock Using HTML, CSS & JavaScript

body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}

#clock {
font-size: 3em;
}

function updateClock() {
const now = new Date();
const hours = now.getHours();
const minutes = now.getMinutes();
const seconds = now.getSeconds();

const clock = document.getElementById(‘clock’);
clock.textContent = `${hours}:${minutes}:${seconds}`;
}

setInterval(updateClock, 1000);
updateClock();