copy this code
<!DOCTYPE html>
<html>
<head>
<title>Colorful Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
}
.calculator {
width: 240px;
background-color: #fff;
padding: 20px;
border-radius: 5px;
margin: 0 auto;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}
.screen {
width: 100%;
height: 50px;
margin-bottom: 20px;
padding: 5px;
font-size: 24px;
text-align: right;
background-color: #ebebeb;
border-radius: 5px;
border: none;
outline: none;
}
.buttons {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-gap: 10px;
}
.button {
padding: 10px;
font-size: 18px;
background-color: #f2f2f2;
border: none;
border-radius: 5px;
cursor: pointer;
}
.button:hover {
background-color: #e0e0e0;
}
.button.operator {
background-color: #ff9f43;
color: #fff;
}
.button.operator:hover {
background-color: #ff7f00;
}
</style>
</head>
<body>
<div class="calculator">
<input type="text" id="screen" class="screen" readonly>
<div class="buttons">
<button class="button operator" onclick="addToScreen('/')">÷</button>
<button class="button" onclick="addToScreen('7')">7</button>
<button class="button" onclick="addToScreen('8')">8</button>
<button class="button" onclick="addToScreen('9')">9</button>
<button class="button operator" onclick="addToScreen('*')">x</button>
<button class="button" onclick="addToScreen('4')">4</button>
<button class="button" onclick="addToScreen('5')">5</button>
<button class="button" onclick="addToScreen('6')">6</button>
<button class="button operator" onclick="addToScreen('-')">-</button>
<button class="button" onclick="addToScreen('1')">1</button>
<button class="button" onclick="addToScreen('2')">2</button>
<button class="button" onclick="addToScreen('3')">3</button>
<button class="button operator" onclick="addToScreen('+')">+</button>
<button class="button" onclick="addToScreen('0')">0</button>
<button class="button" onclick="addToScreen('.')">.</button>
<button class="button operator" onclick="calculate()">=</button>
<button class="button operator" onclick="clearScreen()">C</button>
</div>
</div>
<script>
function addToScreen(value) {
document.getElementById('screen').value += value;
}
function calculate() {
var result = eval(document.getElementById('screen').value);
document.getElementById('screen').value = result;
}
function clearScreen() {
document.getElementById('screen').value = '';
}
</script>
</body>
</html>