How to make animated counter using JavaScript ? Last Updated : 03 Oct, 2024 Comments Improve Suggest changes Like Article Like Report Creating an animated counter with JavaScript is an easy way to make your website more interactive. It smoothly increases or decreases numbers, which is great for displaying stats or other dynamic content. You can easily customize the speed and timing using HTML, CSS, and JavaScript.Approach :Making an Animated Counter Using JavaScript:HTML Structure: Use an HTML element, such as a <div> or <span>, to display the counter value.CSS for Styling: Add basic CSS to style the counter, making it match your website’s design seamlessly.JavaScript Logic:Use the setInterval() function in JavaScript to update the counter value at regular intervals.Adjust the interval time to control the speed of the animation.Use clearInterval() to stop the counter once it reaches the desired value.Example 1: Animated Counter from 0 to 1000In this example, we use JavaScript to create an animated counter that increments from 0 to 1000. The setInterval() method repeatedly calls the updated() function, which updates the counter's value. Once the value of the upto variable reaches 1000, the clearInterval() method stops the counter. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Animated Counter</title> <style> body { text-align: center; font-family: Arial, sans-serif; } #counter { font-size: 3rem; font-weight: bold; color: #4CAF50; margin-top: 20px; } </style> </head> <body> <h1>GeeksforGeeks</h1> <p>COUNTS</p> <div id="counter">0</div> <script> let upto = 0; let counts = setInterval(updated, 10); function updated() { let count = document.getElementById("counter"); count.innerHTML = ++upto; if (upto === 1000) { clearInterval(counts); } } </script> </body> </html> Output: Example 2: Decrement Counter from 1000 to 0In this example, the counter starts at 1000 and decrements down to 0. JavaScript's setInterval() function is used to decrement the counter, and once the counter reaches 0, the clearInterval() function stops the countdown. We have added some basic CSS styles to make the webpage visually appealing. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Decrementing Counter</title> <style> body { background-color: green; text-align: center; font-family: Arial, sans-serif; } #counter { color: white; font-size: 3rem; font-weight: bold; margin-top: 20px; } </style> </head> <body> <h1>GeeksforGeeks</h1> <p>COUNTS DECREMENT</p> <div id="counter">1000</div> <script> let upto = 1000; let counts = setInterval(updated, 10); function updated() { let count = document.getElementById("counter"); count.innerHTML = --upto; if (upto === 0) { clearInterval(counts); } } </script> </body> </html> Output: These examples show how to create a simple animated counter that can either increment or decrement, with control over the speed and stopping point. You can easily customize the starting value, ending value, and speed to fit your needs! Comment More infoAdvertise with us Next Article How to make animated counter using JavaScript ? A anuragsingh1022 Follow Improve Article Tags : HTML HTML-Tags JavaScript-Questions Similar Reads HTML Tutorial HTML stands for HyperText Markup Language. It is the standard language used to create and structure content on the web. It tells the web browser how to display text, links, images, and other forms of multimedia on a webpage. HTML sets up the basic structure of a website, and then CSS and JavaScript 11 min read JavaScript Interview Questions and Answers JavaScript (JS) is the most popular lightweight, scripting, and interpreted programming language. JavaScript is well-known as a scripting language for web pages, mobile apps, web servers, and many other platforms. Both front-end and back-end developers need to have a strong command of JavaScript, as 15+ min read HTML Interview Questions and Answers HTML (HyperText Markup Language) is the foundational language for creating web pages and web applications. Whether you're a fresher or an experienced professional, preparing for an HTML interview requires a solid understanding of both basic and advanced concepts. Below is a curated list of 50+ HTML 14 min read Top 10 Projects For Beginners To Practice HTML and CSS Skills Learning to code is an exciting journey, especially when stepping into the world of programming with HTML and CSSâthe foundation of every website you see today. For most beginners, these two building blocks are the perfect starting point to explore the creative side of web development, designing vis 8 min read HTML Introduction HTML stands for Hyper Text Markup Language, which is the core language used to structure content on the web. It organizes text, images, links, and media using tags and elements that browsers can interpret. As of 2025, over 95% of websites rely on HTML alongside CSS and JavaScript, making it a fundam 6 min read HTML Tags - A to Z List HTML Tags are fundamental elements used to structure and format content on web pages. They provide instructions to web browsers on how to render text, images, links, and other media.HTML tags are enclosed in angle brackets < > and usually come in pairs: an opening tag and a closing tag. The cl 15+ min read 30+ Web Development Projects with Source Code [2025] Web development is one of the most in-demand career paths in the IT industry, experiencing consistent growth of around 20â25% annually. Whether you're a student starting out or an experienced professional looking to switch or advance your career, it's essential to go beyond theory and demonstrate yo 4 min read HTML DOCTYPE Declaration HTML DOCTYPE (Document Type Declaration) is an instruction that appears at the beginning of an HTML document, before the <html> tag.Its primary role is to tell the web browser which version of HTML the page is written in, ensuring that the browser renders the content correctly. It is not an HT 4 min read Frontend Developer Interview Questions and Answers Frontend development is an important part of web applications, and it is used to build dynamic and user-friendly web applications with an interactive user interface (UI). Many companies are hiring skilled Frontend developers with expertise in HTML, CSS, JavaScript, and modern frameworks and librarie 15+ min read HTML Forms HTML forms, defined using the <form> Tags are essential for collecting user input on web pages. They incorporate a variety of interactive controls such as text fields, numeric inputs, email fields, password fields, checkboxes, radio buttons, and submit buttons. Over 85% of websites rely on for 5 min read Like