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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
<!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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
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