Open In App

Age Calculator Design using HTML CSS and JavaScript

Last Updated : 23 Jul, 2025
Comments
Improve
Suggest changes
20 Likes
Like
Report

In the Age Calculator, the user enters their date of birth using a date input field. The tool calculates and displays the exact age in years, months, and days from the current date (or a specified date). We'll design the layout using HTML and CSS, and add functionality using JavaScript. It will also show what percentage of the current year has passed since the user's last birthday — for example, 40% of the year completed.

Project Preview:

agecalculator
Age Calculator

Note: If you want to create more Web Development Project, you can check out - Top 30+ Web Development Project.

Step-By-Step Guide to Create a Age Calculator

  • Create a calculator using HTML with a date input and a submit button.
  • Use CSS to style the calculator using classes and element selectors.
  • Use JavaScript to get the entered birth date and today’s date.
  • Calculate the age in years, months, and days.
  • Show the calculated age or an "Invalid Date" message on the screen.
  • Set the input field’s default value to today’s date.
  • Format the date to YYYY-MM-DD and add leading zeros if needed.

Example: This example describes the basic implementation of the Age Calculator using HTML, CSS, and JavaScript.

index.html
<!DOCTYPE html>
<html>
<head>
    <title>Age Calculator</title>
    <link rel="stylesheet" 
          href="style.css" />
</head>
<body>
    <div class="card">
        <header>
            <h1>AGE CALCULATOR</h1>
        </header>
        <div>
            <label>Enter your Date of Birth</label><br>
            <input id="inputDob" 
                   type="date" 
                   value="2000-01-01" />
        </div>
        <br />
        <!-- Take the date from which age is to be calculated -->
        <div>
            <label>Current Date</label><br>
            <input id="cdate"
                   type="date" 
                   value="" />
        </div>
        <br />
        <button type="button" 
                onclick="getDOB()">
            Calculate
        </button>
        <br />
        <div id="currentAge"></div>
        <script src="script.js"></script>
    </div>
</body>
</html>
style.css script.js

Output:

agecalculator
Age Calculator

Age Calculator Design using HTML CSS and JavaScript

Similar Reads