How To Create A Calculator Using HTML, CSS & JavaScript | Full Source Code





index.html
--------------
<!DOCTYPE html>
<html>
<head>
    <title>Calculator</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <h1>MY CALCULATAR</h1>
 
    <form id="cal_form" name="cal">
 
    <input name="display" style="width: 830px;; height: 150px; text-align: center; background-color: #0FB8AF; "><br>
     
        <input type="button" value="7" onClick="cal.display.value +='7'">
        <input type="button" value="8" onClick="cal.display.value +='8'">
        <input type="button" value="9" onClick="cal.display.value +='9'">
        <input type="button" value="+" onClick="cal.display.value +='+'" style="background-color: coral"><br>
     
        <input type="button" value="4" onClick="cal.display.value +='4'">
        <input type="button" value="5" onClick="cal.display.value +='5'">
        <input type="button" value="6" onClick="cal.display.value +='6'">
        <input type="button" value="-" onClick="cal.display.value +='-'" style="background-color: #ba55d3"><br>
     
        <input type="button" value="1" onClick="cal.display.value +='1'">
        <input type="button" value="2" onClick="cal.display.value +='2'">
        <input type="button" value="3" onClick="cal.display.value +='3'">
        <input type="button" value="x" onClick="cal.display.value +='*'" style="background-color: #7db1b2 "><br>
     
        <input type = "button" value="C" onClick="cal.display.value = ''">
     
        <input type="button" value="0" onClick="cal.display.value +='0'">
     
         <input type = button value="=" onClick="cal.display.value = eval(cal.display.value)" style = "background-color:#27ACD9">
     
        <input type="button" value="&#247" onClick="cal.display.value +='/'" style="background-color: green">

    </form>

</body>
</html>


---------------------------------------------------------------------------------------------------------------------

style.css

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

#calform{
    margin-left: 225px;
    margin-top: 20px;
}

h1{
 
    font-size: 80px;
    margin-right: 150px;
    margin-top: 20px;
    color: blueviolet;
    padding-left: 300px;

}


                                                                  Tutorial





Comments