How To Create a Responsive Digital Clock

Share To Help Other...

Introduction

Today we will learn about How To Create a Responsive Digital-Clock.

1 Digital Clock. manglastubh by ankit akolkar

HTML STRUCTURE

<!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 href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet">

</head>
<body>
    <div class="container text-center">
        <h1 class="my-3">Digital Clock</h1>
        <div id="clock" class="alert alert-primary"></div>
    </div>

</body>
</html>

CSS STRUCTURE

<style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f5f5f5;
        }
        #clock {
            font-size: 4em;
            font-weight: bold;
        }
    </style>

JAVASCRIPT AND JQUERY

<script>
        function updateClock() {
            const now = new Date();
            const hours = String(now.getHours()).padStart(2, '0');
            const minutes = String(now.getMinutes()).padStart(2, '0');
            const seconds = String(now.getSeconds()).padStart(2, '0');
            document.getElementById('clock').textContent = `${hours}:${minutes}:${seconds}`;
        }

        setInterval(updateClock, 1000);
        updateClock(); // Initialize clock immediately
    </script>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/js/bootstrap.bundle.min.js"></script>

CODE INCLUDE

This Login Form code includes the mentioned things

  • HTML Code
  • JavaScript Code
  • CSS Code

Digital Clock FEATURES

  • Desktop View is Perfect
  • Mobile View is Perfect
  • Include Bootstrap CDN Library
  • Live Webpage Preview Button

How To Create a Responsive Digital-Clock. Manglastubh By Ankit Akolkar. Search on Google Free Online Courses.

Scroll to Top