

Hey Friends! Today we are make a beautiful digital clock using html css and javascript. So i hope you like it. Here you can get my all videos source code this source code just paste in your code editor and save it filename.html
In this article, we will tell you how to make diital clock using html css and javascript. If you like this article of ours, then click on the video given below to watch the video related to this article and also subscribe to our channel.
So let’s know how to make digital clock using html css and javascript.
HTML
First of all you understanding this html language because if you know about html then you can create digital clock using html otherwise you dont know about html then first lean from w3school and make some project using html then you can make it easily. Basic understanding of HTML, CSS, and JavaScript.
Approach: We will create three files (HTML file, a CSS file, and JavaScript File), we also have an image of the clocks that will be used in the background, and on top of that, we will make an hour, minute, and second hand (using HTML and CSS). These hands will rotate as per the system time (we will use the predefined Date function of JavaScript to calculate the degree of rotations of each hand).
File Structure
It is a simple file having the basic structure of the webpage and ID for the digital clock’s body and for the second, minute, hour hands.
CSS: The CSS is used just for making the clocks actually look a bit nicer. We have basically centered our clocks in the middle of the webpage. JavaScript: The JavaScript file will provide the logic behind the rotation of the hands.
First we have selected the hour, minute, and second from HTML.
To get the current time we have used the Date() object provided by the JavaScript. This will give the current seconds, minutes, and hours respectively.
Now, we have got our hour, minute, and second, and we know that the clocks rotates 360 degrees. So, we will convert to convert the rotation of the hands of the clocks into degrees. The degree calculation is based on a simple unary method.
HTML for Digital Clock
Now open your vs code editor and go to the right top section and click on file and select new file then save filename.html after this press ctrl+1 then html syntax generate automatically on your editor. This feature inbuild only visual code editor so i suggested you download this editor and make projects easily because it is a best code editor software. And this design for digital clock project make a fast with visual studio code editor.
Now we will learn how to write html for digital clock. So let’s know that first you have to go to the body tag, after that you will take the div tag and together with the class whose name is to be named motor. Then after that we will take div tag again and we will name its class as stand. Again we will take div tag and name its class as bottom stand after that we will take div tag again and we will name its class as petal1. Again we will take div tag and name its class as Pankhdi 2, then again take div tag and name its class as Pankdi 3. Now in the last we will take the div tag and name its class as center.
CSS for Fan Design
Now we will design the digital clock using css. So let’s design, first of all you have to know how we write css. We write css in 3 ways first we can write inline and second we can write it internal and third we can write it external so that we have to create new css file but in this article we have used internal css so that We will not have to create css file separately and we can work inside the same file.
First of all we have to go inside the head section and going inside we have to take style tag then we will take * tag and by applying curly braces open and close in it we will keep margin as 0 and padding as 0. And will keep its box sizing border box. Then we will take the body tag and flex the display in it, then we will center the justify content, after that we will center the align items and also make the background color rgb.
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: rgb(22, 22, 22);
}
Popular Articles
How to make portfolio header with dark mode enable or disable using html css and javascript ?
How to create user profile like a instagram using html and css?
How to create Tea Cup with vapour effect using html and css?
<html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Digital Clock</title> <style> body{ background-color: rgb(189, 206, 200); } h1{ text-align: center; font-family: verdana; margin-top: 30px; color: rgb(167, 5, 86); text-shadow: 3px 3px 8px black; font-weight: bold; } .main{ width: 400px; height: 150px; background-color: rgb(126, 6, 90); position: absolute; top: 16%; left: 36%; border-radius: 10px; box-shadow: 3px 3px 8px black; } .time{ width: 350px; height: 110px; background-color: rgb(8, 168, 16); margin: 20px 0px 0px 25px; border: 2px dotted rgb(204, 18, 18); box-shadow: inset 2px 2px 5px black; } .hour{ font-size: 90px; color: rgb(245, 239, 239); position: absolute; top: 25px; left: 32px; font-weight: bold; text-shadow: 3px 3px 8px black; } .minute{ font-size: 90px; color: rgb(245, 239, 239); position: absolute; top: 25px; left: 157px; font-weight: bold; text-shadow: 3px 3px 8px black; } .second{ font-size: 90px; color: rgb(145, 7, 7); position: absolute; top: 25px; left: 279px; font-weight: bold; text-shadow: 3px 3px 8px black; } .date{ width: 350px; height: 370px; background-color: darkgreen; margin: 200px 0px 0px 511px; } .newDate{ color: darkgrey; position: absolute; top: 50%; left: 43%; font-size: 30px; text-shadow: 3px 3px 7px black; } </style> </head> <body> <h1>Digital Clock</h1> <div> <div></div> </div> <div></div> <script> var time = document.querySelector('.time'); var todayDate = document.querySelector('.date'); function setDate(){ const date = new Date(); const tm = date.toLocaleTimeString(); const newDate = date.toDateString(); const sec = date.getSeconds(); const min = date.getMinutes(); const hour = date.getHours() time.innerHTML = '<span>'+'<div>'+hour+":"+'</div>'+ '<div>'+min+":"+ '</div>'+'<div>' +sec+ '</div>'+'</span>'; todayDate.innerHTML = '<span>'+'<div>'+newDate+'</div>'+tm+'</span>'; } setInterval(setDate, 1000); </script> </body> </html>