Count Up / Count Down Animation With Javascript

Hello Everyone, in this tutorial you'll learn how to create count animation with JavaScript. Where you can count from one number to another number. You can change start and end number along with the speed. In the previous tutorials we shared How to create Multi Tags Input Box in HTML CSS & JavaScript. Now its time to create count up and count down counter animation using javascript.
Access FREE : Compiler Design Free Tutorial

Create count animation with JavaScript with Source Code

To create count animation using javascript, you have to create three files. ie. HTML, CSS & JAVASCRIPT.


fistly, you ahve to create index.html file & copy paste below html code to your html file. Make sure you html file have .html extensions.

<!DOCTYPE html>
 <html lang="en">
        <title>Count Up/Down</title>
         <!--Google Font-->
         <link href="" rel="stylesheet">
         <link rel="stylesheet" href="style.css">
   <div id="output">

       <script src="script.js"></script>


After that, You have to copy paste below css code to your style.css file.

    padding: 0;
    margin: 0;
    box-sizing: border-box;
    height: 100vh;
    background: linear-gradient(
    height: 250px;
    width: 250px;
    background-color: #ffffff;
    position: absolute;
    transform: translate(-50%,-50%);
    top: 50%;
    left: 50%;
    border-radius: 8px;
    box-shadow: 0 20px 25px rgba(0,0,0,0.25);
    display: grid;
    place-items: center;
    font-family: "Roboto Mono", monospace;
    font-size: 50px;
    color: #20202f;


Finally, you have to create script.js file and copy paste below javascript code to your js file.

function countTo(){
    let from = -50;
    let to = 20;
    let step = to > from ? 1 : -1;
    let interval = 100;

    if(from == to){
        document.querySelector("#output").textContent = from;

    let counter = setInterval(function(){
        from += step;
        document.querySelector("#output").textContent = from;

        if(from == to){
    }, interval);

input.addEventListener("keyup", addTag);

const removeBtn = document.querySelector(".details button");
removeBtn.addEventListener("click", () =>{
    tags.length = 0;
    ul.querySelectorAll("li").forEach(li => li.remove());
Also Read : What is Backlink? How to Get High Quality Backlinks in 2022
If you wann to check the demo of this code, then you can check using below demo button.
Click on the following download button to download all source code files of count animation directly  on your computer.

Final Word

In this way, we can create count up - down animation in HTML CSS & JavaScript.  I hope you all like this tutorial. Keep with us for next tutorial. if you wann the source code of this code you can get this on our github account. If you have any query please free to contact us Or comment below.