Today, I created a small but useful application Counter App using basic HTML, CSS, and JavaScript. It’s a great little project for beginners and a handy way to reinforce fundamental web development skills.
Let me walk you through how I built it and what it does.
What the App Does
This counter app displays a number (starting from 0) and provides three buttons:
➕ Increase: Adds 1 to the counter
➖ Decrease: Subtracts 1 from the counter
🔁 Reset: Resets the counter back to 0
It’s interactive, responsive, and runs right in the browser—no frameworks required!
The Code
Here’s the complete HTML code that includes the structure and the JavaScript logic:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Counter App</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1 id="result">0</h1>
<div class="btn">
<button onclick="increase()">+</button>
<button onclick="decrease()">-</button>
<button onclick="reset()">Reset</button>
</div>
</div>
<script>
let count = 0;
let elem = document.getElementById("result");
function increase() {
count = count + 1;
elem.innerText = count;
}
function decrease() {
count = count - 1;
elem.innerText = count;
}
function reset() {
count = 0;
elem.innerText = count;
}
</script>
</body>
</html>
CSS code
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.container {
text-align: center;
background-color: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
font-size: 4em;
margin-bottom: 20px;
}
.btn button {
font-size: 1.5em;
padding: 10px 20px;
margin: 5px;
border: none;
border-radius: 5px;
background-color: #007bff;
color: white;
cursor: pointer;
}
.btn button:hover {
background-color: #0056b3;
}
Outpu
What I Learned
While making this app, I practiced:
Using onclick to trigger JavaScript functions
Updating the DOM with innerText
Writing clean, reusable functions
Keeping logic and presentation separate
Top comments (0)