Understanding how much house you can afford is a crucial first step in the home-buying process. This mortgage affordability calculator helps you estimate the maximum mortgage loan you can qualify for based on your income, debts, and desired down payment. It takes into account common lending criteria to give you a realistic idea of your borrowing power.
.calculator-container {
font-family: sans-serif;
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.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;
}
.calculator-container button {
display: block;
width: 100%;
padding: 12px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
font-size: 1.1rem;
cursor: pointer;
transition: background-color 0.3s ease;
}
.calculator-container button:hover {
background-color: #0056b3;
}
.calculator-result {
margin-top: 25px;
padding: 15px;
background-color: #e9ecef;
border: 1px solid #dee2e6;
border-radius: 4px;
text-align: center;
font-size: 1.1rem;
color: #333;
}
.calculator-result strong {
color: #007bff;
}
function calculateMortgageAffordability() {
var grossMonthlyIncome = parseFloat(document.getElementById("grossMonthlyIncome").value);
var monthlyDebtPayments = parseFloat(document.getElementById("monthlyDebtPayments").value);
var downPayment = parseFloat(document.getElementById("downPayment").value);
var interestRate = parseFloat(document.getElementById("interestRate").value);
var loanTermYears = parseInt(document.getElementById("loanTermYears").value);
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = ""; // Clear previous results
// Basic validation
if (isNaN(grossMonthlyIncome) || grossMonthlyIncome <= 0) {
resultDiv.innerHTML = "Please enter a valid Gross Monthly Income.";
return;
}
if (isNaN(monthlyDebtPayments) || monthlyDebtPayments < 0) {
resultDiv.innerHTML = "Please enter a valid total for Monthly Debt Payments.";
return;
}
if (isNaN(downPayment) || downPayment < 0) {
resultDiv.innerHTML = "Please enter a valid Down Payment amount.";
return;
}
if (isNaN(interestRate) || interestRate <= 0) {
resultDiv.innerHTML = "Please enter a valid Interest Rate.";
return;
}
if (isNaN(loanTermYears) || loanTermYears <= 0) {
resultDiv.innerHTML = "Please enter a valid Loan Term.";
return;
}
// Lender debt-to-income ratio (DTI) limits (common benchmarks)
// Front-end DTI (housing) – typically 28% of gross income
var maxHousingPayment = grossMonthlyIncome * 0.28;
// Back-end DTI (housing + other debts) – typically 36% of gross income
var maxTotalDebtPayment = grossMonthlyIncome * 0.36;
// Calculate maximum allowed monthly mortgage payment
var maxMortgagePayment = maxTotalDebtPayment – monthlyDebtPayments;
// Ensure the calculated max mortgage payment is not negative
if (maxMortgagePayment < 0) {
maxMortgagePayment = 0;
}
// Use the lower of the two DTI-based maximums for a more conservative estimate
var affordableMonthlyPayment = Math.min(maxHousingPayment, maxMortgagePayment);
// If affordableMonthlyPayment is zero or negative, it means debt obligations exceed income capacity
if (affordableMonthlyPayment 0) {
principalLoanAmount = affordableMonthlyPayment * (Math.pow(1 + monthlyInterestRate, numberOfPayments) – 1) / (monthlyInterestRate * Math.pow(1 + monthlyInterestRate, numberOfPayments));
} else {
// Handle 0% interest rate scenario (unlikely for mortgages but for completeness)
principalLoanAmount = affordableMonthlyPayment * numberOfPayments;
}
// The total affordable home price is the loan amount plus the down payment
var affordableHomePrice = principalLoanAmount + downPayment;
// Format results for display
var formattedHomePrice = affordableHomePrice.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 });
var formattedLoanAmount = principalLoanAmount.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 });
var formattedMonthlyPayment = affordableMonthlyPayment.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 });
resultDiv.innerHTML = "Based on your inputs, your estimated maximum affordable home price is: $" + formattedHomePrice + "" +
"This assumes a maximum monthly mortgage payment of approximately: $" + formattedMonthlyPayment + "" +
"This would support a loan amount of approximately: $" + formattedLoanAmount + "" +
"Note: This is an estimate and does not include property taxes, homeowner's insurance, or private mortgage insurance (PMI). Actual loan approval depends on lender underwriting and creditworthiness.";
}