<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>EMI Calculator 💰</title>
<style>
* {
box-sizing: border-box;
font-family: 'Arial', sans-serif;
}
body {
background: #f0f2f5;
margin: 0;
padding: 20px;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.container {
background: white;
padding: 30px;
border-radius: 15px;
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
width: 100%;
max-width: 600px;
}
.input-group {
margin-bottom: 25px;
}
label {
display: block;
margin-bottom: 10px;
color: #333;
font-weight: bold;
}
input[type="number"], input[type="range"] {
width: 100%;
padding: 12px;
border: 2px solid #ddd;
border-radius: 8px;
font-size: 16px;
}
input[type="range"] {
padding: 0;
}
.rate-value {
display: inline-block;
margin-left: 10px;
font-weight: bold;
color: #2ecc71;
}
.results-table {
width: 100%;
margin-top: 30px;
background: #f8f9fa;
border-radius: 10px;
padding: 20px;
display: none;
}
.results-table.active {
display: table;
}
.result-row {
display: flex;
justify-content: space-between;
padding: 15px 0;
border-bottom: 1px solid #eee;
}
.result-row:last-child {
border-bottom: none;
}
.result-label {
color: #666;
}
.result-value {
font-weight: bold;
color: #2c3e50;
}
@media (max-width: 480px) {
.container {
padding: 20px;
}
.result-row {
flex-direction: column;
}
}
.emoji {
font-size: 1.2em;
margin-right: 8px;
}
</style>
</head>
<body>
<div class="container">
<div class="input-group">
<label>💰 Principal Amount ($)</label>
<input type="number" id="principal" min="100" step="100" value="10000" oninput="calculateEMI()">
</div>
<div class="input-group">
<label>📈 Annual Interest Rate
<span id="rateDisplay" class="rate-value">10%</span>
</label>
<input type="range" id="interestRate" min="1" max="20" value="10" oninput="updateRateDisplay(this.value)">
</div>
<div class="input-group">
<label>⏳ Loan Tenure (Months)</label>
<input type="number" id="tenure" min="1" value="12" oninput="calculateEMI()">
</div>
<div class="results-table" id="resultsTable">
<div class="result-row">
<div class="result-label"><span class="emoji">📉</span>Monthly EMI</div>
<div class="result-value" id="emiResult">$0.00</div>
</div>
<div class="result-row">
<div class="result-label"><span class="emoji">💸</span>Total Interest</div>
<div class="result-value" id="totalInterest">$0.00</div>
</div>
<div class="result-row">
<div class="result-label"><span class="emoji">💵</span>Total Amount</div>
<div class="result-value" id="totalAmount">$0.00</div>
</div>
</div>
</div>
<script>
function updateRateDisplay(value) {
document.getElementById('rateDisplay').textContent = value + '%';
calculateEMI();
}
function calculateEMI() {
const principal = parseFloat(document.getElementById('principal').value);
const annualRate = parseFloat(document.getElementById('interestRate').value);
const months = parseFloat(document.getElementById('tenure').value);
const monthlyRate = annualRate / 1200; // Convert annual to monthly and percentage to decimal
const emi = principal * monthlyRate *
Math.pow(1 + monthlyRate, months) /
(Math.pow(1 + monthlyRate, months) - 1);
const totalAmount = emi * months;
const totalInterest = totalAmount - principal;
document