Digital Clock with HTML, CSS & JavaScript

10 DAYS 10 PROJECT CHALLENGE

Day #01

Project Overview

This project is a Digital Clock built using HTML, CSS, and JavaScript.
It displays the current time dynamically and updates every second. The clock is styled to look modern, simple, and responsive, making it a great beginner-friendly JavaScript project to learn DOM manipulation, date/time handling, and styling with CSS.

Key Features

  • Real-time update – The clock automatically updates every second.
  • Date Display – Show today’s date below the clock.
  • Day Indicator – Highlights the current day of the week.
  • Responsive Design – Works on desktop, tablet, and mobile.
  • AM/PM Indicator – For 12-hour format clocks.

HTML Code

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Digital Clock</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <!-- Clock Container -->
  <div class="clock-container">
    <h1 id="clock"></h1>
    <p id="date"></p>
  </div>

  <script src="script.js"></script>
</body>
</html>

CSS Code

/* Clock Container Styling */
.clock-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: #002252; 
  color: #ffffff; /* White text */
  font-family: 'Courier New', monospace; /* Digital font look */
}

/* Time Styling */
#clock {
  font-size: 60px;
  font-weight: bold;
  margin: 10px 0;
  color: #eea731;
}

/* Date Styling */
#date {
  font-size: 22px;
  opacity: 0.9;
}

Javascript Code

// Function to update the clock
function updateClock() {
  let now = new Date();

  // Extract time values
  let hours = now.getHours();
  let minutes = now.getMinutes();
  let seconds = now.getSeconds();

  // AM/PM format
  let ampm = hours >= 12 ? 'PM' : 'AM';
  hours = hours % 12 || 12; // Convert 24hr → 12hr format

  // Add leading zeros
  hours = hours.toString().padStart(2, '0');
  minutes = minutes.toString().padStart(2, '0');
  seconds = seconds.toString().padStart(2, '0');

  // Format time
  let timeStr = `${hours}:${minutes}:${seconds} ${ampm}`;

  // Format date
  let options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
  let dateStr = now.toLocaleDateString(undefined, options);

  // Display in HTML
  document.getElementById("clock").innerText = timeStr;
  document.getElementById("date").innerText = dateStr;
}

// Update clock every second
setInterval(updateClock, 1000);

// Run immediately on page load
updateClock();

Your Task

Create a similar project on your own and share your CodePen link in the comments.
I’ll review your work and share my feedback as a reply!

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Related Projects

Day 3 : To-Do List App

Users can add, mark complete, and delete tasks.

Concepts: Arrays, LocalStorage.

Day 4 : Image Slider / Carousel

A slider that automatically or manually slides through images.

Concepts: CSS transitions, DOM traversal.

Day 5 : Quiz App

A multiple-choice quiz with score tracking.

Concepts: Loops, conditionals.