Live preview
Preview settings
Changes appear as you type. Use Tab to test keyboard focus.
⌘ / Ctrl + S saves locally
Digital Clock
HTML, CSS or Tailwind, and a little JavaScript. One button or a group of up to six.
Button submission checks
Checks will appear after the preview updates.
Buttons only: no full pages, forms, cards or navigation. Put scripts in the JavaScript tab. Tailwind uses utilities from HTML and JavaScript; use complete class names. Custom CSS supports plain CSS, without @apply, imports or plugins.
Accessibility quick check
Waiting for the rendered preview…
Try Tab, Enter and Space in the preview. Check the focus ring, hover and disabled states, then enable Reduce motion. These checks are guidance, not an accessibility certification.
Explore freely here. Remix to publish your version with credit to the creator.
About Digital Clock
Digital Clock is an animated CSS button by @VardaPanchal005. Preview the interaction, customize its HTML, styles and JavaScript, or download the files with creator credit.
- Effects and categories
- Hover effects, Animated
- Using this example
- Copy the HTML or download index.html, style.css and app.js. Test keyboard focus, motion and contrast in your own project.
Usage, Tailwind and licensing questions
Read the source files
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<title>Digital Clock</title>
</head>
<body>
<div class="container">
<div class="bg-elem"></div>
<div class="bg-elem"></div>
<div class="bg-elem"></div>
<div class="content">
<h3>Digital Clock with Stopwatch and Countdown Timer</h3>
<p class="type">Clock</p>
</div>
<div class="main-container">
<div class="clock">
<div class="wrapper">
<div class="main">
<div class="hour">
<p class="number" id="hour">20</p>
<p>hours</p>
</div>
<p class="colon">:</p>
<div class="min">
<p class="number" id="min">00</p>
<p>minutes</p>
</div>
<p class="colon">:</p>
<div class="sec">
<p class="number" id="sec">00</p>
<p>seconds</p>
</div>
<p class="colon">:</p>
<div class="ampm">
<p class="number" id="ampm">AM</p>
<p id="other-ampm">PM</p>
</div>
</div>
</div>
<div class="btns">
<button class="btn" id="stopwatch-btn">Stopwatch</button>
<button class="btn" id="timer-btn">Timer</button>
</div>
</div>
<div class="stopwatch hidden">
<div class="wrapper">
<div class="main">
<div class="hour">
<p class="number" id="stopwatch-hour">00</p>
<p>hours</p>
</div>
<p class="colon">:</p>
<div class="min">
<p class="number" id="stopwatch-min">00</p>
<p>minutes</p>
</div>
<p class="colon">:</p>
<div class="sec">
<p class="number" id="stopwatch-sec">00</p>
<p>seconds</p>
</div>
<p class="colon">:</p>
<div class="ms">
<p class="number" id="stopwatch-ms">00</p>
<p>miliseconds</p>
</div>
</div>
</div>
<div class="laps">
<div class="lap active">
<p>lap 1</p>
<p>00:00</p>
</div>
</div>
<div class="btns">
<button class="btn start-stopwatch">Start</button>
<button class="btn lap-stopwatch hidden">Lap</button>
<button class="btn reset-stopwatch">Reset</button>
<button class="btn back-btn">Back</button>
</div>
</div>
<div class="timer hidden">
<div class="wrapper">
<div class="main">
<div class="hour">
<p class="number" id="timer-hour">00</p>
<p>hours</p>
</div>
<p class="colon">:</p>
<div class="min">
<p class="number" id="timer-min">00</p>
<p>minutes</p>
</div>
<p class="colon">:</p>
<div class="sec">
<p class="number" id="timer-sec">00</p>
<p>seconds</p>
</div>
<p class="colon">:</p>
<div class="ms">
<p class="number" id="timer-ms">00</p>
<p>miliseconds</p>
</div>
</div>
</div>
<div class="btns">
<button class="btn start-timer">Start</button>
<button class="btn stop-timer hidden">Stop</button>
<button class="btn reset-timer">Reset</button>
<button class="btn back-btn">Back</button>
</div>
</div>
</div>
</div>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.3/jquery.min.js"
integrity="sha512-STof4xm1wgkfm7heWqFJVn58Hm3EtS31XFaagaa8VMReCXAkQnJZ+jEy8PCC/iT18dFy95WcExNHFTqLyp72eQ=="
crossorigin="anonymous"
></script>
<script src="script.js"></script>
</body>
</html>CSS
@import url(https://fonts.googleapis.com/css?family=Poppins:100,100italic,200,200italic,300,300italic,regular,italic,500,500italic,600,600italic,700,700italic,800,800italic,900,900italic);
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Poppins", sans-serif;
}
body {
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: #eef1f6;
}
.container {
position: relative;
width: 100%;
max-width: 800px;
padding: 60px;
border-radius: 10px;
color: #fff;
background: #6994c5;
box-shadow: 0 10px 10px rgba(0, 0, 0, 0.2);
}
p,
i {
font-size: 10px;
font-weight: 500;
color: #ffffff62;
text-transform: uppercase;
}
.content h3 {
font-size: 20px;
font-weight: 500;
margin-bottom: 25px;
}
.wrapper {
padding: 30px 0;
border-radius: 10px;
margin-top: 15px;
background: rgba(255, 255, 255, 0.15);
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
backdrop-filter: blur(1.5px);
-webkit-backdrop-filter: blur(1.5px);
border-radius: 10px;
border: 1px solid rgba(255, 255, 255, 0.18);
transition: all 0.3s ease;
}
.wrapper:hover {
box-shadow: none;
}
.main {
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
}
.main div {
width: 20%;
text-align: center;
}
.main .number {
position: relative;
font-size: 60px;
font-weight: 400;
line-height: 1;
color: #fff;
}
.main .colon {
font-size: 20px;
}
.btns {
margin-top: 20px;
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
gap: 10px;
}
.btn {
padding: 10px 20px;
border-radius: 5px;
color: #fff;
border: none;
font-size: 12px;
font-weight: 500;
text-transform: uppercase;
cursor: pointer;
transition: all 0.3s ease;
background: rgba(255, 255, 255, 0.15);
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
backdrop-filter: blur(1.5px);
-webkit-backdrop-filter: blur(1.5px);
border: 1px solid rgba(255, 255, 255, 0.18);
}
.btn:active {
box-shadow: none;
}
.hidden {
display: none;
}
.laps {
position: relative;
max-height: 100px;
overflow-y: auto;
display: flex;
align-items: center;
flex-direction: column;
gap: 10px;
margin: 0 auto;
margin-top: 20px;
}
.laps::-webkit-scrollbar {
width: 5px;
}
.laps::-webkit-scrollbar-track {
background: rgba(255, 255, 255, 0.15);
border-radius: 10px;
}
.laps::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.15);
border-radius: 10px;
}
.lap {
width: 50%;
display: flex;
justify-content: space-between;
padding: 10px;
background: rgba(255, 255, 255, 0.15);
border-radius: 10px;
border: 1px solid rgba(255, 255, 255, 0.18);
}
.lap:last-child {
border-bottom: none;
}
.lap.active p {
color: #fff;
}
.bg-elem {
position: absolute;
top: 60%;
left: 10%;
width: 80px;
height: 80px;
transform: rotate(45deg);
background: rgba(255, 255, 255, 0.15);
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
backdrop-filter: blur(1.5px);
-webkit-backdrop-filter: blur(1.5px);
border-radius: 10px;
border: 1px solid rgba(255, 255, 255, 0.18);
animation: bg-elem 10s linear infinite;
transition: all 0.3s ease;
}
.bg-elem:hover {
animation-play-state: paused;
box-shadow: none;
}
.bg-elem:nth-child(2) {
top: 20%;
left: 80%;
width: 100px;
height: 100px;
animation-duration: 30s;
}
.bg-elem:nth-child(3) {
top: 15%;
left: 10%;
width: 40px;
height: 40px;
border-radius: 50%;
animation-duration: 20s;
}
@keyframes bg-elem {
0% {
transform: rotate(45deg) translate(0, 0);
}
50% {
transform: rotate(45deg) translate(20px, 20px);
}
100% {
transform: rotate(45deg) translate(0, 0);
}
}
@media (max-width: 600px) {
.container {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
border-radius: 0;
padding: 0 20px;
}
.content h3 {
font-size: 16px;
}
.main-wrapper {
padding: 20px 0;
}
.main div {
width: 15%;
}
.main .number {
font-size: 50px;
}
.main .colon {
font-size: 16px;
}
.bg-elem {
display: none;
}
}
@media (max-width: 400px) {
.container {
padding: 0 10px;
}
.content h3 {
font-size: 14px;
}
.main-wrapper {
padding: 10px 0;
}
.main-wrapper .head {
padding: 0 20px;
}
.main .number {
font-size: 40px;
}
.main .colon {
font-size: 12px;
}
}
/* Credits */
.credits a {
position: absolute;
bottom: 10px;
right: 10px;
font-size: 14px;
color: #333;
}
.credits span {
color: #109dff;
}JavaScript
const updateTime = () => {
const time = new Date();
let hours = time.getHours();
let minutes = time.getMinutes();
let seconds = time.getSeconds();
let ampm = hours >= 12 ? "PM" : "AM";
let otherampm = hours >= 12 ? "AM" : "PM";
hours = hours % 12 || 12;
hours = addTrailingZero(hours);
minutes = addTrailingZero(minutes);
seconds = addTrailingZero(seconds);
$("#hour").html(hours);
$("#min").html(minutes);
$("#sec").html(seconds);
$("#ampm").html(ampm);
$("#other-ampm").html(otherampm);
};
updateTime();
setInterval(updateTime, 1000);
$("#stopwatch-btn").click(function () {
$(".main-container > div").slideUp();
$(".stopwatch").slideDown();
$(".type").html("Stopwatch");
});
$("#timer-btn").click(function () {
$(".main-container > div").slideUp();
$(".timer").slideDown();
$(".type").html("Timer");
});
$(".back-btn").click(function () {
$(".main-container > div").slideUp();
$(".clock").slideDown();
$(".type").html("Clock");
});
let stopwatchHours = 0,
stopwatchMinutes = 0,
stopwatchSeconds = 0,
stopwatchMiliSeconds = 0,
stopwatchRunning = false,
laps = 0,
stopwatchInterval;
function stopwatch() {
stopwatchMiliSeconds++;
if (stopwatchMiliSeconds === 100) {
stopwatchMiliSeconds = 0;
stopwatchSeconds++;
}
if (stopwatchSeconds === 60) {
stopwatchSeconds = 0;
stopwatchMinutes++;
}
if (stopwatchMinutes === 60) {
stopwatchMinutes = 0;
stopwatchHours++;
}
$("#stopwatch-hour").html(addTrailingZero(stopwatchHours));
$("#stopwatch-min").html(addTrailingZero(stopwatchMinutes));
$("#stopwatch-sec").html(addTrailingZero(stopwatchSeconds));
$("#stopwatch-ms").html(addTrailingZero(stopwatchMiliSeconds));
}
function startStopwatch() {
if (!stopwatchRunning) {
stopwatchInterval = setInterval(stopwatch, 10);
stopwatchRunning = true;
}
}
function stopStopwatch() {
clearInterval(stopwatchInterval);
stopwatchRunning = false;
}
function resetStopwatch() {
clearInterval(stopwatchInterval);
stopwatchRunning = false;
stopwatchHours = 0;
stopwatchMinutes = 0;
stopwatchSeconds = 0;
stopwatchMiliSeconds = 0;
laps = 0;
$("#stopwatch-hour").html("00");
$("#stopwatch-min").html("00");
$("#stopwatch-sec").html("00");
$("#stopwatch-ms").html("00");
}
$(".start-stopwatch").click(function () {
startStopwatch();
$(".start-stopwatch").hide();
$(".lap-stopwatch").show();
});
$(".lap-stopwatch").click(function () {
laps++;
$(".lap").removeClass("active");
$(".laps").prepend(
` <div class="lap active">
<p>Lap ${laps}</p>
<p>
${addTrailingZero(stopwatchHours)} : ${addTrailingZero(
stopwatchMinutes
)} : ${addTrailingZero(stopwatchSeconds)} : ${addTrailingZero(
stopwatchMiliSeconds
)}
</p>
</div>
`
);
});
$(".reset-stopwatch").click(function () {
resetStopwatch();
$(".start-stopwatch").show();
$(".lap-stopwatch").hide();
$(".laps").html("");
});
function addTrailingZero(number) {
return number < 10 ? "0" + number : number;
}
let time = 0,
timerHours = 0,
timerMinutes = 0,
timerSeconds = 0,
timerMiliseconds = 0,
timerRunning = false,
timerInterval;
function getTime() {
time = prompt("Enter time in minutes");
time = time * 60;
setTime();
}
function setTime() {
timerHours = Math.floor(time / 3600);
timerMinutes = Math.floor((time % 3600) / 60);
timerSeconds = Math.floor(time % 60);
timerMiliseconds = 0;
$("#timer-hour").html(addTrailingZero(timerHours));
$("#timer-min").html(addTrailingZero(timerMinutes));
$("#timer-sec").html(addTrailingZero(timerSeconds));
$("#timer-ms").html(addTrailingZero(timerMiliseconds));
}
function timer() {
timerMiliseconds--;
if (timerMiliseconds === -1) {
timerMiliseconds = 99;
timerSeconds--;
}
if (timerSeconds === -1) {
timerSeconds = 59;
timerMinutes--;
}
if (timerMinutes === -1) {
timerMinutes = 59;
timerHours--;
}
$("#timer-hour").html(addTrailingZero(timerHours));
$("#timer-min").html(addTrailingZero(timerMinutes));
$("#timer-sec").html(addTrailingZero(timerSeconds));
$("#timer-ms").html(addTrailingZero(timerMiliseconds));
timeUp();
}
function startTimer() {
if (timerHours === 0 && timerMinutes === 0 && timerSeconds === 0) {
getTime();
} else {
timerInterval = setInterval(timer, 10);
timerRunning = true;
$(".start-timer").hide();
$(".stop-timer").show();
}
}
function stopTimer() {
clearInterval(timerInterval);
timerRunning = false;
$(".start-timer").show();
$(".stop-timer").hide();
}
function resetTimer() {
stopTimer();
time = 0;
setTime();
}
function timeUp() {
if (
timerHours === 0 &&
timerMinutes === 0 &&
timerSeconds === 0 &&
timerMiliseconds === 0
) {
stopTimer();
alert("Time's up!");
setTime();
}
}
$(".start-timer").click(startTimer);
$(".stop-timer").click(stopTimer);
$(".reset-timer").click(function () {
resetTimer();
if (!timerRunning) {
$(".start-timer").show();
$(".stop-timer").hide();
}
});