Build a Mini Arithmetic Calculator in HTML5 CSS3 and Javascript Full Project For Beginners

You are currently viewing Build a Mini Arithmetic Calculator in HTML5 CSS3 and Javascript Full Project For Beginners

 

Welcome folks today in this blog post we will be building a mini arithmetic calculator in html5 css3 and javascript. All the full source code of the application is given below.

 

 

Get Started

 

 

In order to get started just make a index.html file inside the root directory and copy paste the following code

 

index.html

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Calculator</title>
    <link rel="stylesheet" href="./main.css">
</head>
<body>
    <h1>My Calculator</h1><br/>
    <form id="myform" name="calc">
        <input name="display" style = "width: 675px;height: 1--px;text-align: center;background-color: darkgray;"><br>
        <input type="button" value="0" onclick="calc.display.value+='0'">
        <input type="button" value="1" onclick="calc.display.value+='1'" >
        <input type="button" value="2" onclick="calc.display.value+='2'">
        <input type="button" value="+" onclick="calc.display.value+='+'" style="background-color: lightgreen;"><br/>
        <input type="button" value="3" onclick="calc.display.value+='3'">
        <input type="button" value="4" onclick="calc.display.value+='4'">
        <input type="button" value="5" onclick="calc.display.value+='5'">
        <input type="button" value="-" onclick="calc.display.value+='-'" style="background-color: palevioletred;"><br/>
        <input type="button" value="6" onclick="calc.display.value+='6'">
        <input type="button" value="7" onclick="calc.display.value+='7'">
        <input type="button" value="8" onclick="calc.display.value+='8'">
        <input type="button" value="x" onclick="calc.display.value+='*'" style="background-color: mediumpurple;"><br/>
        <input type="button" value="9" onclick="calc.display.value+='9'">
        <input type="button" value="C" onclick="calc.display.value=''" style="background-color: rgb(110, 58, 110);">
        <input type="button" value="=" onclick="calc.display.value=eval(calc.display.value)">
        <input type="button" value="÷" onclick="calc.display.value+='/'" style="background-color: lightslategrey;">
    </form>
    <br>
   

</body>
</html>

 

 

Now just make another main.css file inside the root directory and copy paste the following code

 

main.css

 

input {
  width: 150px;
  height: 100px;
  font-size: 75px;
  border-radius: 10px;
  margin: 10px;
  background-color: #000;
  color: #fff;
  border-style: none;
}
#myform {
  text-align: center;

  margin-top: 20px;
}
h1 {
  text-align: center;
  font-size: 80px;

  margin-top: 20px;
}

 

 

Now if you open index.html file inside the browser you will see the following output as shown below

 

 

Leave a Reply