top of page
  • Writer's pictureRahul Kumar

Calculator using HTML, CSS and JavaScript

So Today! We will learn coding project. That is Calculator.

We are not making this lecture difficult. So, This is simple and clear concept of making Calculator Web Application.



  1. 1 PC/Laptop.

  2. Some Basic knowledge of HTML, CSS and JavaScript.

So, 1st We need to install code editor (Visual Studio Code) Download Here.

After installing code Editor.

We start building Calculator.

First create file folder with the name of "calculator".

After this, we need to import our folder to code editor. I am using Visual code editor.

You can simply drag and drop your folder to code editor.

After that we will create all index files inside this calculator folder.

So, Create all these file inside calculator folder.

Location of files:


After that we can start writing our codes.

index.html : Start write HTML code in index.html.

<!DOCTYPE html>
    <link rel="stylesheet" href="styles.css">
    <div id="container">
<div id="result">
    <!-- <span class="result-text">Result......</span> -->
<input class="result-text" type="text" placeholder="Result.....">
<div id="rows">
    <button class="button">C</button>
    <button class="button">AC</button>
    <button class="button">%</button>
    <button class="button">/</button>
    <div id="rows">
    <button class="button">7</button>
    <button class="button">8</button>
    <button class="button">9</button>
    <button class="button">*</button>
<div id="rows">
    <button class="button">4</button>
    <button class="button">5</button>
    <button class="button">6</button>
    <button class="button">+</button>
<div id="rows">
    <button class="button">1</button>
    <button class="button">2</button>
    <button class="button">3</button>
    <button class="button">-</button>
<div id="rows">
    <button class="button">.</button>
    <button class="button">0</button>
    <button class="button">.</button>
    <button class="button">=</button>

    <script src="/index.js"></script>

styles.css : Start write CSS code in styles.css.

    background-color: aquamarine;
    display: flex;
    justify-content: center;
    margin: 10%;
    height: 410px;
    width: 300px;
    background-color: white;
    border-style: solid;
    border-color: black;
    /* display: flex;
    justify-content: center;
    padding-top:1%; */
/* #result{
    width: 280px;
} */
    width: 280px;
    height: 50px;
    margin-top: 5px;
    margin-left: 6px;

    width: 95%;
    height: 16%;
    margin-left: 8px;
background-color: red;
    width: 55px;
    height: 50px;
    margin-left: 10px;
    margin-bottom: 5px;
    margin-top: 5px;

index.js : Start write JavaScript code in index.js.

let string = "";
let buttons = document.querySelectorAll('.button');
button.addEventListener('click', (e)=>{
   if( == "="){
     string = eval(string);
     document.querySelector('.result-text').value = string;
     else if( == "C"){
        string = " ";
        document.querySelector('.result-text').value = string;
         else if( == "AC"){
            string = " ";
            document.querySelector('.result-text').value = string;
    string = string +;
    document.querySelector('.result-text').value = string;

Result :

Do you like this JavaScript Project?

  • Yes

  • No



bottom of page