Published on

Most Effective Ways To Create A Digital Clock With Tailwind CSS

Tags
Digital Clock

What is Tailwind CSS?

Tailwind CSS is a utility-first CSS framework that focuses on creating personalized user interfaces quickly. It can gives you all the building blocks you are able to create personalized designs without having to fight to override irritating opinionated styles. Also, Tailwind CSS is a highly configurable, low-level CSS framework.

The description of Digital Clock ui component

Digital clock created by me!

Why use Tailwind CSS to build a Digital Clock ui component?

  • It can make the building process of Digital Clock ui component faster and more easily.
  • Enables building complex responsive layouts and components freely.
  • Minimum lines of CSS code in Digital Clock component file.

The preview of Digital Clock ui component

Free download of the Digital Clock's source code

The source code of Digital Clock ui component

<!DOCTYPE html>
<html lang="en">
<head>
    
    <link href="https://unpkg.com/[email protected]^2/dist/tailwind.min.css" rel="stylesheet"> 
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link
    rel="stylesheet"
    href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"
  />
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Digital Clock</title>
</head>
<body>
    <style>
         @import url('https://fonts.googleapis.com/css?family=Orbitron');
        *{
            color: black;
            user-select: none;
           background-color: rgb(241, 225, 6);
            font-family: 'Orbitron';
        }
       


h1{
    text-align: center;
    padding-top: 0px;
   
    font-size: 30px;
}
#clock {

  font-size: 100px;
  text-align: center;
  padding-top: 250px;
  padding-bottom: 40px;
}

    </style>
   
    <div id="clock" onclick="currentTime()">
    
    </div>
    <h1 class="animate__backInLeft">Welcome, AliRaza</h1>
    <script type="text/javascript">
    function currentTime() {
    var date = new Date(); /* creating object of Date class */
    var hour = date.getHours();
    var min = date.getMinutes();
    var sec = date.getSeconds();
    hour = updateTime(hour);
    min = updateTime(min);
    sec = updateTime(sec);
    var y = date.getFullYear();
    var d = new Date();
    var weekday = new Array(7);
    weekday[0] = "Sunday";
    weekday[1] = "Monday";
    weekday[2] = "Tuesday";
    weekday[3] = "Wednesday";
    weekday[4] = "Thursday";
    weekday[5] = "Friday";
    weekday[6] = "Saturday";
  var n = weekday[d.getDay()];
    document.getElementById("clock").innerText = hour + " : " + min + " , " + n + " , " + y; /* adding time to the div */
      var t = setTimeout(function(){ currentTime() }, 1000); /* setting timer */
}
  function updateTime(k) {
    if (k < 10) {
      return "0" + k;
    }
    else {
      return k;
    }
  }
  currentTime(); /* calling currentTime() function to initiate the process */
    </script>
</body>
</html>

How to build a Digital Clock with Tailwind CSS?

Install tailwind css of verion 2.0.3

Use the script html tag to import the script of Tailwind CSS of the version 2.0.3

<script src="https://cdn.tailwindcss.com"></script>

All the unility class needed to build a Digital Clock component

    0 steps to build a Digital Clock component with Tailwind CSS

      Conclusion

      The above is a step-by-step tutorial on how to use Tailwind CSS to build a Digital Clock components, learn and follow along to implement your own components.