Debt-to-Income (DTI) Ratio Calculator
.dti-calculator-widget {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
background: #fff;
border: 1px solid #e0e0e0;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}
.dti-calc-header {
background: #2c3e50;
color: #fff;
padding: 20px;
text-align: center;
}
.dti-calc-header h2 {
margin: 0;
font-size: 24px;
}
.dti-calc-body {
padding: 30px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 30px;
}
@media (max-width: 768px) {
.dti-calc-body {
grid-template-columns: 1fr;
}
}
.dti-input-group {
margin-bottom: 15px;
}
.dti-input-group label {
display: block;
margin-bottom: 5px;
font-weight: 600;
color: #333;
font-size: 14px;
}
.dti-input-wrapper {
position: relative;
}
.dti-input-wrapper span {
position: absolute;
left: 10px;
top: 50%;
transform: translateY(-50%);
color: #777;
}
.dti-input-wrapper input {
width: 100%;
padding: 10px 10px 10px 25px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 16px;
box-sizing: border-box;
}
.dti-input-wrapper input:focus {
border-color: #3498db;
outline: none;
}
.dti-results-section {
background: #f8f9fa;
padding: 20px;
border-radius: 6px;
border: 1px solid #e9ecef;
display: flex;
flex-direction: column;
justify-content: center;
}
.dti-result-box {
text-align: center;
margin-bottom: 20px;
}
.dti-result-label {
font-size: 14px;
color: #666;
text-transform: uppercase;
letter-spacing: 1px;
margin-bottom: 5px;
}
.dti-result-value {
font-size: 36px;
font-weight: 700;
color: #2c3e50;
}
.dti-result-value.good { color: #27ae60; }
.dti-result-value.warning { color: #f39c12; }
.dti-result-value.bad { color: #c0392b; }
.dti-btn {
background: #3498db;
color: white;
border: none;
padding: 12px 20px;
width: 100%;
border-radius: 4px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: background 0.2s;
margin-top: 10px;
}
.dti-btn:hover {
background: #2980b9;
}
.dti-explanation {
font-size: 13px;
color: #555;
text-align: center;
margin-top: 10px;
font-style: italic;
}
.dti-article-content {
padding: 30px;
border-top: 1px solid #e0e0e0;
line-height: 1.6;
color: #333;
}
.dti-article-content h3 {
color: #2c3e50;
margin-top: 25px;
}
.dti-article-content p {
margin-bottom: 15px;
}
.dti-article-content ul {
margin-bottom: 20px;
padding-left: 20px;
}
.dti-article-content li {
margin-bottom: 8px;
}
function calculateDTI() {
// Get values
var income = parseFloat(document.getElementById('dti_income').value) || 0;
var housing = parseFloat(document.getElementById('dti_mortgage').value) || 0;
var cars = parseFloat(document.getElementById('dti_cars').value) || 0;
var student = parseFloat(document.getElementById('dti_student').value) || 0;
var cards = parseFloat(document.getElementById('dti_cards').value) || 0;
var other = parseFloat(document.getElementById('dti_other').value) || 0;
// Validations
if (income <= 0) {
document.getElementById('frontend_result').innerHTML = "0.00%";
document.getElementById('backend_result').innerHTML = "0.00%";
document.getElementById('dti_verdict').innerHTML = "Enter Income";
document.getElementById('dti_verdict').style.backgroundColor = "#e9ecef";
document.getElementById('dti_verdict').style.color = "#333";
return;
}
// Calculations
var totalNonHousingDebt = cars + student + cards + other;
var totalDebt = housing + totalNonHousingDebt;
var frontEndRatio = (housing / income) * 100;
var backEndRatio = (totalDebt / income) * 100;
// Display Results
document.getElementById('frontend_result').innerHTML = frontEndRatio.toFixed(2) + "%";
document.getElementById('backend_result').innerHTML = backEndRatio.toFixed(2) + "%";
// Logic for Verdict and Colors
var verdictBox = document.getElementById('dti_verdict');
var messageBox = document.getElementById('dti_message');
var backEndEl = document.getElementById('backend_result');
// Color coding for Back-End Ratio
backEndEl.classList.remove('good', 'warning', 'bad');
if (backEndRatio = 36 && backEndRatio 43 && backEndRatio < 50) {
backEndEl.classList.add('bad');
verdictBox.innerHTML = "High Risk";
verdictBox.style.backgroundColor = "rgba(192, 57, 43, 0.2)";
verdictBox.style.color = "#c0392b";
messageBox.innerHTML = "It may be difficult to qualify for a conventional mortgage. FHA might be an option.";
} else {
backEndEl.classList.add('bad');
verdictBox.innerHTML = "Critical";
verdictBox.style.backgroundColor = "rgba(192, 57, 43, 0.2)";
verdictBox.style.color = "#c0392b";
messageBox.innerHTML = "Your debt load is too high for most lending standards. Focus on paying down debt.";
}
}