This project is a simple digital clock created using HTML, CSS, and JavaScript. It displays the current time in hours, minutes, and seconds, updating every second.
index.html: The HTML file that defines the structure of the digital clock.style.css: The CSS file that styles the digital clock.script.js: The JavaScript file that updates the clock every second.
The HTML file sets up the structure of the digital clock. It includes:
- A
divwith the classheroto act as the main container. - Inside
hero, adivwith the classcontainercenters the clock on the page. - The
clockdivcontains threespanelements with IDshrs,min, andsecto display hours, minutes, and seconds, respectively. - A link to the
style.cssfile for styling. - A script tag to include the
script.jsfile for functionality.
The CSS file styles the digital clock with a modern look:
- It uses the Poppins font from Google Fonts.
- The
heroclass sets a gradient background and centers its content. - The
containerclass centers the clock on the page and includes decorative before and after pseudo-elements. - The
clockclass styles the clock with a semi-transparent background and a blur effect. - Each
spaninside the clock is styled to have a large font size for the time display, with smaller labels below each part of the time (hours, minutes, seconds).
The JavaScript file handles the clock functionality:
- It selects the
spanelements by their IDs (hrs,min,sec). - It uses
setIntervalto update the time every second. - The current time is fetched using the
Dateobject. - Hours, minutes, and seconds are updated with leading zeros if necessary to always display two digits.