Use this calculator to estimate how much house you can afford based on your income, debts, and down payment. Understanding your potential mortgage amount is a crucial first step in the home-buying process.
.calculator-container {
font-family: sans-serif;
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 8px;
background-color: #f9f9f9;
}
.calculator-container h2 {
text-align: center;
margin-bottom: 20px;
color: #333;
}
.calculator-inputs {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 15px;
margin-bottom: 20px;
}
.input-group {
display: flex;
flex-direction: column;
}
.input-group label {
margin-bottom: 5px;
font-weight: bold;
color: #555;
}
.input-group input {
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 1rem;
}
button {
display: block;
width: 100%;
padding: 12px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
font-size: 1.1rem;
cursor: pointer;
transition: background-color 0.3s ease;
margin-bottom: 20px;
}
button:hover {
background-color: #0056b3;
}
.calculator-result {
margin-top: 20px;
padding: 15px;
background-color: #e9ecef;
border: 1px solid #ddd;
border-radius: 5px;
text-align: center;
font-size: 1.1rem;
color: #333;
}
.calculator-result p {
margin: 0;
}
.calculator-result strong {
color: #28a745;
}
function calculateMortgageAffordability() {
var annualIncome = parseFloat(document.getElementById("annualIncome").value);
var monthlyDebt = parseFloat(document.getElementById("monthlyDebt").value);
var downPayment = parseFloat(document.getElementById("downPayment").value);
var interestRate = parseFloat(document.getElementById("interestRate").value);
var loanTerm = parseFloat(document.getElementById("loanTerm").value);
var resultDiv = document.getElementById("result");
// Clear previous results
resultDiv.innerHTML = "";
// Validate inputs
if (isNaN(annualIncome) || isNaN(monthlyDebt) || isNaN(downPayment) || isNaN(interestRate) || isNaN(loanTerm) ||
annualIncome < 0 || monthlyDebt < 0 || downPayment < 0 || interestRate < 0 || loanTerm <= 0) {
resultDiv.innerHTML = "Please enter valid positive numbers for all fields.";
return;
}
// — Lender Guidelines (Common Benchmarks) —
// Front-end ratio (housing costs / gross income) – typically 28%
var maxHousingRatio = 0.28;
// Back-end ratio (total debt / gross income) – typically 36%
var maxDebtRatio = 0.36;
// — End Lender Guidelines —
var monthlyIncome = annualIncome / 12;
var maxMonthlyHousingPayment = monthlyIncome * maxHousingRatio;
var maxTotalMonthlyDebt = monthlyIncome * maxDebtRatio;
var maxMortgagePayment = maxTotalMonthlyDebt – monthlyDebt;
// If maxMortgagePayment is negative, it means existing debt exceeds allowed limit for income
if (maxMortgagePayment 0) {
var monthlyInterestRate = (interestRate / 100) / 12;
var numberOfPayments = loanTerm * 12;
// Formula for Loan Amount: M = P [ (1 + r)^n – 1 ] / r (1 + r)^n
// Rearranged for P (Principal Loan Amount): P = M [ (1 + r)^n – 1 ] / r (1 + r)^n
// where M = Monthly Payment, r = Monthly Interest Rate, n = Number of Payments
if (monthlyInterestRate > 0) {
affordableMaxLoan = affordableMonthlyPayment * (Math.pow(1 + monthlyInterestRate, numberOfPayments) – 1) / (monthlyInterestRate * Math.pow(1 + monthlyInterestRate, numberOfPayments));
} else {
// If interest rate is 0, loan is simply monthly payment * number of payments
affordableMaxLoan = affordableMonthlyPayment * numberOfPayments;
}
}
var maxHomePrice = affordableMaxLoan + downPayment;
// Display results
resultDiv.innerHTML = "Based on your inputs and common lending guidelines:" +
"Maximum affordable monthly housing payment (P&I): $" + affordableMonthlyPayment.toFixed(2) + "" +
"Estimated maximum loan amount: $" + affordableMaxLoan.toFixed(2) + "" +
"Estimated maximum home price (Loan + Down Payment): $" + maxHomePrice.toFixed(2) + "";
}