Source Code Of Calculator Using HTML And CSS

Folder Structure

Folder Structure

Codes

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <title>Calculator</title>
</head>
<body>
   <div class="container">
      <form action="" class="calc_form" name="calc">
         <input type="text" class="input_value" readonly name="text">
         <span class="num_value clear" onclick="calc.text.value=''"><i>C</i></span>
         <span class="num_value" onclick="calc.text.value+='/'"><i>/</i></span>
         <span class="num_value" onclick="calc.text.value+='*'"><i>*</i></span>
         <span class="num_value" onclick="calc.text.value+='7'"><i>7</i></span>
         <span class="num_value" onclick="calc.text.value+='8'"><i>8</i></span>
         <span class="num_value" onclick="calc.text.value+='9'"><i>9</i></span>
         <span class="num_value" onclick="calc.text.value+='-'"><i>-</i></span>
         <span class="num_value" onclick="calc.text.value+='4'"><i>4</i></span>
         <span class="num_value" onclick="calc.text.value+='5'"><i>5</i></span>
         <span class="num_value" onclick="calc.text.value+='6'"><i>6</i></span>
         <span class="num_value plus" onclick="calc.text.value+='+'"><i>+</i></span>
         <span class="num_value" onclick="calc.text.value+='1'"><i>1</i></span>
         <span class="num_value" onclick="calc.text.value+='2'"><i>2</i></span>
         <span class="num_value" onclick="calc.text.value+='3'"><i>3</i></span>
         <span class="num_value" onclick="calc.text.value+='0'"><i>0</i></span>
         <span class="num_value" onclick="calc.text.value+='00'"><i>00</i></span>
         <span class="num_value" onclick="calc.text.value+='.'"><i>.</i></span>
         <span class="num_value equal" onclick="document.calc.text.value=eval(calc.text.value)"><i>=</i></span>
      </form>
   </div>
</body>
</html>

CSS

*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'sans-serif', poppins;
}
body{
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #1b1f29;
}
.container{
    position: relative;
    min-width: 300px;
    min-height: 400px;
    background: #1b1f29;
    padding: 40px 30px 30px;
    border-radius: 25px;
    box-shadow: 25px 25px 75px rgba(0,0,0,0.25),
    10px 10px 70px rgba(0,0,0,0.25),inset -5px -5px 15px rgba(0,0,0,0.5),inset 5px 5px 15px rgba(0,0,0,0.5);
}
.calc_form span{
    position: relative;
    display: grid;
    width: 80px;
    height: 80px;
    margin: 8px;
    cursor: pointer;
    user-select: none;
    background: linear-gradient(180deg, #2f2f2f,#3f3f3f);
    box-shadow: inset -8px 0 8px rgba(0,0,0,0.15), 
    inset 0 -8px 8px rgba(0,0,0,0.25), 0 0 0 2px rgba(0,0,0,0.75),
    10px 20px 25px rgba(0,0,0,0.4);
    color: whitesmoke;
    font-size: 20px;
    place-items: center;
    font-weight: 400;
    border-radius: 10px;
}
.calc_form span::before{
    content:'';
    position: absolute;
    top: 3px;
    left: 4px;
    bottom: 12px;
    right: 10px;
    border-radius: 10px;
    background: linear-gradient(90deg, #2d2d2d,#4f4f4f);
    box-shadow: -5px -5px 15px rgba(0,0,0,0.1),10px 5px 10px rgba(0,0,0,0.15);
    border-left: 1px solid #0004;
    border-bottom: 1px solid #0004;
    border-top: 1px solid #0009;
}
.calc_form span i{
    position: relative;
    font-style: normal;
    font-size: 1.5em;
    text-transform: uppercase;
}
.calc_form{
    position: relative;
    display: grid;
}
.calc_form .input_value{
    position: relative;
    grid-column: span 4;
    height: 100px;
    left: 10px;
    width: calc(100% - 25px);
    border: none;
    outline: none;
    background: #11d44b;
    margin-bottom: 10px;
    border-radius: 10px;
    box-shadow: 0 0 2px rgba(0,0,0,0.75);
    text-align: right;
    padding: 10px;
    font-size: 2em;
}
.calc_form span:active{
    filter:brightness(1.5);
}
.calc_form .clear{
   grid-column: span 2;
   width: 90%;
   background: #f66335;
}
.calc_form .clear::before{
    background: linear-gradient(90deg, #f66335,#ffffff5c);
    border-left: 1px solid #fff4;
    border-bottom: 1px solid #fff4;
    border-top: 1px solid #fff4;
}
.calc_form .plus{
    grid-row: span 2;
    height: 90%;
}
.calc_form .equal{
   background: #2196f3;
}
.calc_form .equal::before{
    background: linear-gradient(90deg, #2196f3,#ffffff5c);
    border-left: 1px solid #fff4;
    border-bottom: 1px solid #fff4;
    border-top: 1px solid #fff4;
}

YouTube Video

Download Source Code

Don’t forget to share this post!