Skip to content

Simple Calculator Online – Free Basic Math Calculator

Use this free online simple calculator to add, subtract, multiply, and divide numbers. Get quick and accurate results on any device.

Sohail Ilyas
Nov 13, 20262 min read

Start calculating today with our free Simple Calculator and make your everyday math calculations faster, easier, and more accurate!

Copy the free Simple Calculator HTML code and add it to your own website to offer visitors a fast, simple, and user-friendly calculation tool.


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Calculator</title>

<style>
* {
    box-sizing: border-box;
}

.calculator {
    width: 100%;
    max-width: 300px;
    margin: 15px auto;
    padding: 15px;
    font-family: Arial, sans-serif;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 3px 12px rgba(0,0,0,0.08);
}

.calculator h2 {
    text-align: center;
    font-size: 21px;
    color: #1e293b;
    margin: 0 0 14px;
}

#display {
    width: 100%;
    height: 50px;
    padding: 10px;
    margin-bottom: 12px;
    border: 1px solid #cbd5e1;
    border-radius: 7px;
    background: #f8fafc;
    font-size: 23px;
    text-align: right;
    color: #0f172a;
}

.buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 7px;
}

.buttons button {
    height: 44px;
    border: none;
    border-radius: 7px;
    background: #e2e8f0;
    color: #1e293b;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
}

.buttons button:hover {
    filter: brightness(0.95);
}

.buttons .operator {
    background: #dbeafe;
    color: #2563eb;
}

.buttons .clear {
    background: #fee2e2;
    color: #dc2626;
}

.buttons .equal {
    grid-column: span 2;
    background: #2563eb;
    color: white;
}

.more-calculators {
    display: block;
    margin-top: 12px;
    padding: 12px;
    border-radius: 7px;
    background: #2563eb;
    color: #ffffff;
    text-align: center;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
}

.more-calculators:hover {
    background: #1d4ed8;
    color: white;
}

@media (max-width: 350px) {
    .calculator {
        padding: 10px;
    }

    .buttons button {
        height: 40px;
        font-size: 16px;
    }
}
</style>
</head>

<body>

<div class="calculator">

    <h2>Simple Calculator</h2>

    <input type="text" id="display"
           placeholder="0" readonly
           aria-label="Calculator display">

    <div class="buttons">

        <button class="clear" onclick="clearDisplay()">AC</button>
        <button onclick="deleteLast()">DEL</button>
        <button class="operator" onclick="appendValue('%')">%</button>
        <button class="operator" onclick="appendValue('/')">÷</button>

        <button onclick="appendValue('7')">7</button>
        <button onclick="appendValue('8')">8</button>
        <button onclick="appendValue('9')">9</button>
        <button class="operator" onclick="appendValue('*')">×</button>

        <button onclick="appendValue('4')">4</button>
        <button onclick="appendValue('5')">5</button>
        <button onclick="appendValue('6')">6</button>
        <button class="operator" onclick="appendValue('-')">−</button>

        <button onclick="appendValue('1')">1</button>
        <button onclick="appendValue('2')">2</button>
        <button onclick="appendValue('3')">3</button>
        <button class="operator" onclick="appendValue('+')">+</button>

        <button onclick="appendValue('0')">0</button>
        <button onclick="appendValue('.')">.</button>
        <button class="equal" onclick="calculate()">=</button>

    </div>

    <a href="https://calczila.com/" class="more-calculators">
        Check More Calculators →
    </a>

</div>

<script>
const display = document.getElementById("display");

function appendValue(value) {
    if (display.value === "Error") {
        display.value = "";
    }
    display.value += value;
}

function clearDisplay() {
    display.value = "";
}

function deleteLast() {
    display.value = display.value.slice(0, -1);
}

function calculate() {
    try {
        const expression = display.value;

        if (!expression || !/^[0-9+\-*/%.() ]+$/.test(expression)) {
            throw new Error("Invalid input");
        }

        const result = Function(
            '"use strict"; return (' + expression + ')'
        )();

        display.value = Number.isFinite(result)
            ? String(Number(result.toPrecision(12)))
            : "Error";

    } catch {
        display.value = "Error";
    }
}
</script>

</body>
</html>

Did you enjoy this article?

Recommend it — Standard Reader surfaces well-loved writing to more readers across the network.

Across the AtmosphereDiscussions