How to make Incremental and Decremental counter using HTML, CSS and JavaScript ? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report While visiting different shopping websites like Flipkart and Amazon you have seen a counter on each product, that counter is used to specify the quantity of that product. Hence, the counter is a very useful part of many websites. In this article, we will design a counter using HTML, CSS, and JavaScript.Output Preview:Approach:First, we will design a simple button using HTML. Refer to the comments in the code.Next, we will use some CSS properties to design the button and use the hover class to get the animation effect when we hover the mouse over the button.Now, we will add some JavaScript code to add functionality to the buttons which we created earlier. Refer to the comments in the code for help.Example: In this example, we are following above explained approach. HTML <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> <!-- give a suitable heading using h1 tag--> <h1>Increment and Decrement counter</h1> <div class="container"> <!-- adding button and heading to show the digits --> <!--increment() and decrement() functions on button click--> <button onclick="increment()">+</button> <h2 id="counting"></h2> <button onclick="decrement()">-</button> </div> </body> </html> CSS /*apply css properties to body tag*/ body { position: absolute; left: 0%; text-align: center; } /*apply css properties to container class*/ .container { justify-content: center; align-items: center; display: flex; height: 100%; text-align: center; } /*apply css properties to button tag*/ button { width: 90px; height: 60px; font-size: 30px; background-color: green; color: honeydew; } /*apply hover effect to button tag*/ button:hover { background-color: greenyellow; color: grey; } /*apply css properties to h2 tag*/ h2 { color: black; margin: 0 50px; font-size: 45px; } /*apply css properties to h1 tag*/ h1 { font-size: 35px; color: green; text-align: center; padding-left: 10%; } JavaScript //initialising a variable name data let data = 0; //printing default value of data that is 0 in h2 tag document.getElementById("counting").innerText = data; //creation of increment function function increment() { data = data + 1; document.getElementById("counting").innerText = data; } //creation of decrement function function decrement() { data = data - 1; document.getElementById("counting").innerText = data; } Output Comment More info R riyamathur Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings6 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in Javascript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)9 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readJavascript Scope3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like