DEV Community

A Ramesh
A Ramesh

Posted on

Day-14 : Counter Page Using HTML, CSS & JavaScript...

Counter Page Using HTML, CSS & JavaScript

I created a simple Counter Page to practice front-end development. The page allows users to increase, decrease, or reset a number using buttons. It’s a great beginner project to understand HTML, CSS, and JavaScript interaction.


Features:

  • Interactive buttons to change the count
  • Smooth hover effects
  • Clean layout with basic styling
  • Responsive design using Flexbox and Grid

Code:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Counter Page</title>
  <style>
    body {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 96vh;
      background: #e0f7fa;
    }

    .counter {
      width: 400px;
      height: 300px;
      display: grid;
      grid-template-rows: 1fr 1fr;
      border-radius: 10px;
      background-color: rgba(255, 255, 255, 0.9);
      box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
      text-align: center;
    }

    #count {
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 4rem;
    }

    .counting_button {
      display: flex;
      justify-content: center;
      gap: 20px;
    }

    button {
      padding: 10px 20px;
      font-size: 18px;
      border-radius: 10px;
      border: none;
      cursor: pointer;
      transition: 0.3s;
    }

    button:hover {
      background-color: #1877f2;
      color: white;
    }
  </style>
</head>
<body>
  <div class="counter">
    <h1 id="count">0</h1>
    <div class="counting_button">
      <button onclick="increase()">+</button>
      <button onclick="reset()">Reset</button>
      <button onclick="decrease()">-</button>
    </div>
  </div>

  <script>
    let count = 0;
    const countElement = document.getElementById('count');

    function increase() {
      count++;
      countElement.innerText = count;
    }

    function decrease() {
      count--;
      countElement.innerText = count;
    }

    function reset() {
      count = 0;
      countElement.innerText = count;
    }
  </script>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

OutPut (ScreenShot):

Image description

What I Learned:

  • Basic DOM manipulation
  • How to handle button clicks with JavaScript
  • Styling using Flexbox and Grid
  • Adding smooth transitions with CSS

Top comments (0)