how to create a simple calculator in 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>
  </head>

  <!--CSS File-->

  	* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: #fffbd5; /* fallback for old browsers */
  background: -webkit-linear-gradient(
    to right,
    #b20a2c,
    #fffbd5
  ); /* Chrome 10-25, Safari 5.1-6 */
  background: linear-gradient(
    to right,
    #b20a2c,
    #fffbd5
  ); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
}
.container-first {
  position: relative;
  background: #0b8000;
  border-radius: 6px;
  overflow: hidden;
  z-index: 10;
}
.container-first .calculator {
  position: relative;
  display: grid;
}
.container-first .calculator .value {
  grid-column: span 4;
  height: 140px;
  width: 300px;

  border: none;
  padding-left: 1em;

  font-size: 2.5em;

  color: gold;
}
.container-first .calculator span {
  display: grid;
  height: 4.5em;
  font-weight: 900;
  color: rgb(255, 255, 255);
  text-align: center;
  align-items: center;

  font-size: 20px;
  user-select: none;
  border-bottom: 4px solid rgba(255, 255, 255, 0.07);
  border-right: 4px solid rgba(255, 255, 255, 0.07);
}
input[type="text"] {
  color: rgb(255, 136, 0);
  background-color: rgb(156, 40, 40);
}
  <body>
    <div class="container-first">
      <form name="val" class="calculator">
        <input type="text" class="value" name="ans" />
        <span onclick="document.val.ans.value+='4'">4</span>
        <span onclick="document.val.ans.value+='5'">5</span>
        <span onclick="document.val.ans.value+='6'">6</span>


        <span onclick="document.val.ans.value =eval(document.val.ans.value)">
          =
        </span>


        <span onclick="document.val.ans.value+='7'">7</span>
        <span onclick="document.val.ans.value+='8'">8</span>
        <span onclick="document.val.ans.value+='9'">9</span>
        <span onclick="document.val.ans.value+='-'">-</span>

        <span onclick="document.val.ans.value+='1'">1</span>
        <span onclick="document.val.ans.value+='2'">2</span>
        <span onclick="document.val.ans.value+='3'">3</span>

        <span onclick="document.val.ans.value+='/'">/</span>

        <span onclick="document.val.ans.value+='0'">0</span>
        <span onclick="document.val.ans.value=''">C</span>
        <span onclick="document.val.ans.value+='*'">*</span>

        <span onclick="document.val.ans.value+='00'">00</span>

        <span onclick="document.val.ans.value+='+'">+</span>
      </form>
    </div>
  </body>
</html>

0
9
Natasha 80 points

                                    &lt;body&gt;
  
   &lt;center&gt;
    &lt;h1 class=&quot;text-danger&quot;&gt;Calculator&lt;/h1&gt; 
    &lt;p class=&quot;q&quot;&gt;Type in the numbers to be added, separate them with commas (,). If 'Invalid' shows, you have not used a number, please clear the box and type numbers&lt;/p&gt;
   &lt;/center&gt;

    &lt;center&gt;
    &lt;h3 style=&quot;font-family: Lucida Sans; color: lightseagreen&quot;&gt;Add&lt;/h3&gt;
    &lt;input class=&quot;addinput&quot; type=&quot;text&quot;&gt;
   &lt;button class=&quot;add&quot; style=&quot;font-family: Lucida Sans; background-color: lightsalmon&quot;&gt;ADD&lt;/button&gt;
   &lt;p class=&quot;p&quot; style=&quot;background-color:lightpink&quot;&gt;Sum is &lt;span class=&quot;result&quot;&gt;&lt;/span&gt;&lt;/p&gt;
   &lt;/center&gt;
 
&lt;center&gt;
    &lt;h3 style=&quot;font-family: Lucida Sans; color: lightseagreen&quot;&gt;Multiply&lt;/h3&gt;
  &lt;input class=&quot;multiplyinput&quot; type=&quot;text&quot;&gt;
  &lt;button class=&quot;multiply&quot; style=&quot;font-family: Lucida Sans; background-color: lightsalmon&quot;&gt;MULTIPLY&lt;/button&gt;
   &lt;p class=&quot;p&quot; style=&quot;background-color:lightpink&quot;&gt;&lt;/p&gt;&gt;Product is &lt;span class=&quot;product&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/center&gt;

&lt;center&gt;
        &lt;h3 style=&quot;font-family: Lucida Sans; color: lightseagreen&quot;&gt;Subtract&lt;/h3&gt;
    &lt;input class=&quot;subtractinput&quot; type=&quot;text&quot;&gt;
    &lt;button class=&quot;subtract&quot; style=&quot;font-family: Lucida Sans; background-color: lightsalmon&quot;&gt;SUBTRACT&lt;/button&gt;
     &lt;p class=&quot;p&quot; style=&quot;background-color:lightpink&quot;&gt;&lt;/p&gt;&gt;Difference is &lt;span class=&quot;difference&quot;&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;/center&gt;

  &lt;center&gt;
        &lt;h3 style=&quot;font-family: Lucida Sans; color: lightseagreen&quot;&gt;Divide&lt;/h3&gt;
    &lt;input class=&quot;divideinput&quot; type=&quot;text&quot;&gt;
    &lt;button class=&quot;divide&quot; style=&quot;font-family: Lucida Sans; background-color: lightsalmon&quot;&gt;DIVIDE&lt;/button&gt;
     &lt;p class=&quot;p&quot; style=&quot;background-color:lightpink&quot;&gt;&lt;/p&gt;&gt;Quotient is &lt;span class=&quot;quotient&quot;&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;/center&gt;
  
   &lt;script src=&quot;calculator.js&quot;&gt;&lt;/script&gt;

&lt;/body&gt;

0
0
4.2
5
Desty 110 points

                                    
&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
&lt;style&gt;
.contain{
display: flex;
}
#display{
  width: 98%;
  
}
.mathButtons{
  width: 100px;
  height: 40px;
  background-color: rgb(0,0,0,0.3);
  color: white;
}
.mathButtons:hover{
  background-color: DodgerBlue;
  
  }
  #clearButton:hover{
    background-color: orangered;
  }
  #container{
  
    width: 430px;
    height: 300px;

    }
    
    
    .buttondigits{
      background-color:  black;
      color: white;
      height: 40px;
      width: 100px;
    }
    #clearButton{
      width: 100px;
      height: 40px;
      background-color: rgb(0,0,0,0.3);
      font-weight: bold;
    }
	.buttondigits:hover {
background-color: gray;
}

&lt;/style&gt;
&lt;title&gt; standard calculator &lt;/title&gt;
&lt;meta charset=&quot;utf-8&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;cal.css&quot;/&gt;
&lt;/head&gt;
&lt;body&gt;
  
     &lt;div class=&quot;container&quot;&gt;
	&lt;fieldset id=&quot;container&quot;&gt;
	  &lt;form name=&quot;calculator&quot;&gt;
&lt;input type=&quot;text&quot; id=&quot;display&quot; name=&quot;display&quot; readonly&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;div class=&quot;contain&quot;&gt;
&lt;input class=&quot;buttondigits&quot; type=&quot;button&quot; value=&quot;7&quot; onclick=&quot;calculator.display.value += '7'&quot;&gt;
&lt;input class=&quot;buttondigits&quot; type=&quot;button&quot; value=&quot;8&quot; onclick=&quot;calculator.display.value += '8'&quot;&gt;
&lt;input class=&quot;buttondigits&quot; type=&quot;button&quot; value=&quot;9&quot; onclick=&quot;calculator.display.value += '9'&quot;&gt;
&lt;input class=&quot;mathButtons&quot; type=&quot;button&quot; value=&quot;+&quot; onclick=&quot;calculator.display.value += '+'&quot;&gt;
&lt;/div&gt;

&lt;div class=&quot;contain&quot;&gt;
&lt;input class=&quot;buttondigits&quot; type=&quot;button&quot; value=&quot;4&quot; onclick=&quot;calculator.display.value += '4'&quot;&gt;
&lt;input class=&quot;buttondigits&quot; type=&quot;button&quot; value=&quot;5&quot; onclick=&quot;calculator.display.value += '5'&quot;&gt;
&lt;input class=&quot;buttondigits&quot; type=&quot;button&quot; value=&quot;6&quot; onclick=&quot;calculator.display.value += '6'&quot;&gt;
&lt;input class=&quot;mathButtons&quot; type=&quot;button&quot; value=&quot;-&quot; onclick=&quot;calculator.display.value += '-'&quot;&gt;
&lt;/div&gt;

&lt;div class=&quot;contain&quot;&gt;
&lt;input class=&quot;buttondigits&quot; type=&quot;button&quot; value=&quot;1&quot; onclick=&quot;calculator.display.value += '1'&quot;&gt;
&lt;input class=&quot;buttondigits&quot; type=&quot;button&quot; value=&quot;2&quot; onclick=&quot;calculator.display.value += '2'&quot;&gt;
&lt;input class=&quot;buttondigits&quot; type=&quot;button&quot; value=&quot;3&quot; onclick=&quot;calculator.display.value += '3'&quot;&gt;
&lt;input class=&quot;mathButtons&quot; type=&quot;button&quot; value=&quot;*&quot; onclick=&quot;calculator.display.value += '*'&quot;&gt;
&lt;/div&gt;

&lt;div class=&quot;contain&quot;&gt;
&lt;input id=&quot;clearButton&quot; class=&quot;button&quot; type=&quot;button&quot; value=&quot;C&quot; onclick=&quot;calculator.display.value = ''&quot;&gt;
&lt;input class=&quot;buttondigits&quot; type=&quot;button&quot; value=&quot;0&quot; onclick=&quot;calculator.display.value += '0'&quot;&gt;
&lt;input class= &quot;mathButtons&quot; type=&quot;button&quot; value=&quot;=&quot; onclick=&quot;calculator.display.value = eval(calculator.display.value)&quot;&gt;
&lt;input class=&quot;mathButtons&quot; type=&quot;button&quot; value=&quot;/&quot; onclick=&quot;calculator.display.value += '/'&quot;&gt;
&lt;/div&gt;
&lt;/form&gt; 
&lt;/fieldset&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

4.2 (5 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
create a calculator html html calculator program how to build calculator in html html calculator demo create a simple calculator using html w3schools calculator html making calculator in html html code a simple calculator html code to make a simple calculator for beginners html code to make a simple calculator Simple calculator HTML code simple calculator in html code simple calculator in htl simple calculator using html, css make calculator html make calculator with html simple calculator html css designing of calculator using html and css simple calculator in html build a simple calculator using html5 basic calculator w3schools Simple CALCULATOR html 5 simple calculator program in html html program for simple calculator make a calculator in html HTML code to make a calculator html simple calculator simple CALCULTOR in html make a basic html we using calculator make a simple calculator in html how to code a calculator in html html code for basic calculator things to put on calcualtor html basic calculator html W3Schools HTML Calculator html code for simple calculator build a simple calculator using html5 w3schools simple calculator in html5 simple calculator in javascript calculator with steps how to make calculator in javascript easy how to make a simple calculator using html and javascript how to make a calculator using html and javascript CONVERT WHAT TO WHAT CALCULATOR how to make a simple calculator with html cass and js create calculator in html simple attractive basic calculator php css using html code calculation of screen calculation in html get calculator to display input in javascript rechner html code basic html calculator no style code for making calculator in html reate a simple calculator JavaScript program. The user enters an arithmetic expression and clicks a button to perform the required computations. The answer is displayed in the regular running text of the page. simple calculator javascript.the user enters an arithmetic expression and click button to perform the required computations calculate html how to create a display on calculator using html html calculator example calculator ui html javascript calculator code basic calculator using javascript calculator in js and html simple calculator wid 2 fields using html and javascript how to make a calculator in html with javascript with writing in box how to make calculator in html calculator using javascript and html javascript calculator simple code simple calculator html calculator using javascript code html and css makeing calculation in html how to design a simple calculator web application how to make html button do calculation how to create a calculator in html calculator html html javascript calculation page html code for calculator making a calculator in css html calculator interface building a calculator with input field javascript html how to make basic calculator how to build calculator html css how to make a calculator in webbroswer displaying what we typed while making calculator in html how to make calculator in javascript with html how to make a calcualtor in html creating calculator with just html css calculator button javascript calculator coding html css javascript calculator code how to create a calculator html make calculator screen with html make html calculator that does not enter alhabet html input small text for calculator building a calculator in html javascript calculator using html form simple html calculator how to create without calculator html and css website how to add make a calculator in html how to make a calculator in html how to create a simple calculator in html
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source