MASIGNASUKA101
239990035665021724

Make Analog Clock Using HTML, CSS, and JS (With Code)

Make Analog Clock Using HTML, CSS, and JS (With Code)
Add Comments
Tuesday, November 3, 2020

Make Analog Clock Using HTML, CSS, and JS (With Code)

Analog Clock is an integral part of the JavaScript programming language. 

In this article, I am going to tell you how you can easily make a clock using only simple HTML, CSS, and JavaScript programming code. The JavaScript programming language is one of the most widely used analog clocks. Also, some amount of HTML is used for design and some amount of CSS code for styling. There are many types of watches such as digital watches, hand watches, analog watches, etc. Here I will show you how to make an analog watch very easily.

 Hello, friends I know Santana Jana is a web designer. I will show you step by step through my experience of the last five years how you can make an analog clock using only ordinary HTML, CSS, and Java programming languages. 

Some information about this analog watch

💚 This watch is made of plain HTML. Uses CSS and JavaScript programming languages. Most of these Java programming codes have been used.

💝 So that you can easily know and learn how this watch has been extended. The simplest way to do this is to write the programming code.

💛 The background of this watch has been completely blackened and its hands have been painted in different colors. Such as white, blue, and red which do very well on a black background and look bright.

💜 In a typical clock, such as 1 to 12, there are 1 to 12 cells. Three types of forks have been used, namely minute fork second hand, and hour fork.


How to make clock(watch) using html, css, and javascript?

All in all, it is a professional and stylish watch. Which will help you increase your programming knowledge. I have shown in this article how you can make this beautiful professional watch or add it to your own project.

 You can easily download the necessary code to make this watch by clicking on the download button there. To watch the live demo, you can watch the live demo of this watch by clicking on the demo button above.


How To Make This Clock Using HTML, CSS, JS

To make this watch you follow the three steps shown below step by step. You can easily create an HTML clock by following these three steps. Even if you don't have any programming knowledge, you can easily add it to any of your projects. Below are all the instructions on how to add it to your project.


First of all, you create an HTML file. To create an HTML file you need to open any Notepad or any text editor of your choice. Then paste the code below into that editor. Then rename to your liking and save by adding dot HTML. This way you can easily create an HTML file.
Then follow the procedure shown below

Step 1: Add HTML code

 The codes shown below are HTML codes. You add these codes to my project. For this, paste the ad HTML in the structure above (your HTML file). Also if you want to add this watch to any of your other projects, you can paste the following codes into the body tags of that project.

 <div class="clock">
   <div class="hour">
     <div class="hr" id="hr"></div>
   </div><!-- <i class="fa fa-search"></i>
    <i class="fa fa-user"></i>
    <i class="fa fa-shopping-cart"></i>-->
   <div class="min">
     <div class="mn" id="mn"></div>
   </div>
   <div class="sec">
     <div class="sc" id="sc"></div>
   </div>
 </div>


Step 2: Add CSS code

 After adding the HTML code you add the CSS code to your project. To do this, you copy the CSS codes below and paste them into the upper structure of your project where Ad CSS is written.

 If you want to add it to any of your other projects, you can copy all these CSS codes and paste the codes inside the style tags in the head tags of that project.


 body {
  displayflex;
  justify-contentcenter;
  align-itemscenter;
  height100vh;
  background-color#091921;
}

.clock {
  width300px;
  height300px;
  border-radius50%;
  background-imageurl("https://i.postimg.cc/hjVspvcJ/clock.png");
  background-sizecover;
  displayflex;
  /*content: "";
  height: 395px;
  width: 550px;
  background-color: #2a2f40;*/
  justify-contentcenter;
  align-itemscenter;
  box-shadow0 -15px 15px rgba(2552552550.05),
    inset 0 -15px 15px rgba(2552552550.05), 0 15px 15px rgba(0000.3),
    inset 0 15px 15px rgba(0000.3);
}
/*align-items: center;
  background-color: #ff6d39;
  margin-left: 93px;*/
.clock::before {
  content"";
  width15px;
  height15px;
  positionabsolute;
  background-color#fff;
  border-radius50%;
  z-index1000;
}

.hour,
.min,
.sec {
  positionabsolute;
}
/*align-items: center;
  background-color: #ff6d39;
  margin-left: 93px;*/
.hr {
  width160px;
  height160px;
}

.mn {
  width190px;
  height190px;
}

.sc {
  width230px;
  height230px;
}

.hr,
.mn,
.sc {
  displayflex;
  justify-contentcenter;
}
/*align-items: center;
  background-color: #ff6d39;
  margin-left: 93px;*/
.hr::before {
  content"";
  width8px;
  height80px;
  background-color#ff105e;
  z-index100;
  border-radius5px;
}
/*content: "";
  height: 395px;
  width: 550px;
  background-color: #2a2f40;*/
.mn::before {
  content"";
  width6px;
  height90px;
  background-colorrgb(15105207);
  z-index11;
  border-radius5px;
}
/*align-items: center;
  background-color: #ff6d39;
  margin-left: 93px;*/
.sc::before {
  content"";
  width2px;
  height140px;
  background-color#fff;
  z-index10;
  border-radius5px;
}

Step 3: Add JavaScript code

 Hopefully, you have followed the above two methods very nicely i.e. you have added HTML and CSS code to your project. This time the most important thing to make is JavaScript code.

 To add this JavaScript to your project, you need to copy the following JavaScript codes and paste the following JavaScript codes into your project in the above structure where Ad JavaScript is written.


 const deg = 6//360deg / 60(min||sec) => 6
const hr = document.querySelector("#hr");
const mn = document.querySelector("#mn");
const sc = document.querySelector("#sc");
/*var digits = {};

    var positions = ['h1', 'h2', ':', 'm1', 'm2', ':', 's1', 's2' ];

    var digitHolder = clock.find('.digits');

    $.each(positions, function(){
*/
setInterval(() => {
  let day = new Date();
  let hh = day.getHours() * 30//360deg / 12 hour => 30
  let mm = day.getMinutes() * deg;
  let ss = day.getSeconds() * deg;
/*var digits = {};

    var positions = ['h1', 'h2', ':', 'm1', 'm2', ':', 's1', 's2' ];

    var digitHolder = clock.find('.digits');

    $.each(positions, function(){
*/
  hr.style.transform = `rotateZ(${hh + mm / 12}deg)`;
  mn.style.transform = `rotateZ(${mm}deg)`;
  sc.style.transform = `rotateZ(${ss}deg)`;
});



Conclusion

You can download the three types of code shown above by clicking on the download button above. In this, you will get the most. I had some problems when I uploaded these codes. So I added some amount of comments to this code. However, there is no reason to worry, these comments do not change your programming in any way. However, for the convenience of your understanding, you can download the code by clicking on the download button there.


Hope you find it very easy to understand from this article how to make a digital and analog clock using common HTML CSS and JavaScript programming language.

You can easily make this analog watch by following the above three methods. If you have any problem you can let me know by commenting below, I will help you in any way.

❤Sharing is caring❤