Hey friends and welcome to another project blogpost. Today we are going to see how to make this simple and useful countdown page using HTML, CSS & JavaScript.


First, let's see the general usage of this project. It's a page to add a countdown to the date of a specific event. For example, in this project, I made a countdown for the 1 year anniversary of my YouTube channel. You can use it for a birthday countdown also,


Now let's see the source codes.


Paste the codes below in your HTML file:

<!-- Created by CodingPorium,2021. Visit https://youtube.com/c/CodingPorium for more tutorials with free source code -->
<!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">
    <title>Date Countdown Page using JavaScript | CodingPorium</title>
</head>
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@200;300;400;500;600;700&display=swap');

body{
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: tomato;
  font-family: poppins;
  color:white;
  height:100vh;
}

.container{
  background-color: white;
  color:tomato;
  border-radius:5px;
  text-align: center;
  width:350px;
  padding:20px;
  font-size:35px;
}
</style>
<body>
<div class="container">
  <p id="demo"></p>
</div>
<script>
var countDownDate = new Date("June 24, 2022 12:00:00").getTime();

var x = setInterval(function(){
  var now = new Date().getTime();

  var distance = countDownDate - now;

  var days = Math.floor(distance / (1000 * 60 * 60 * 24));
  var hours = Math.floor((distance % (1000 * 60 * 60* 24)) / (1000 * 60 * 60));
  var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
  var seconds = Math.floor((distance % (1000 * 60)) / 1000);

  document.getElementById("demo").innerHTML = days + "d " + hours + "h " + minutes + "m " + seconds + "s " ;

  if(distance<0){
    clearInterval(x);
    document.getElementById("demo").innerHTML="FINISHED"
  }

},1000);





</script>
</body>
</html>


And that's all for this project. Thanks for reading and do subscribe to our YouTube channel to support us.


Till the next one, goodbye!

Post a Comment

Previous Post Next Post