#bmi-calculator-wrapper {
font-family: sans-serif;
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
background-color: #f9f9f9;
}
#bmi-calculator-wrapper h2 {
text-align: center;
color: #333;
margin-bottom: 20px;
}
.bmi-input-group {
margin-bottom: 15px;
display: flex;
align-items: center;
}
.bmi-input-group label {
flex: 1;
margin-right: 10px;
font-weight: bold;
color: #555;
}
.bmi-input-group input[type="number"] {
flex: 2;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box; /* Include padding and border in the element's total width and height */
}
.bmi-input-group span {
margin-left: 10px;
font-weight: normal;
color: #777;
}
#bmi-result {
margin-top: 20px;
padding: 15px;
border: 1px dashed #ccc;
border-radius: 4px;
background-color: #fff;
text-align: center;
font-size: 1.2em;
color: #333;
}
#bmi-calculator-wrapper button {
display: block;
width: 100%;
padding: 12px 20px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 1.1em;
transition: background-color 0.3s ease;
}
#bmi-calculator-wrapper button:hover {
background-color: #45a049;
}
.bmi-explanation {
margin-top: 30px;
border-top: 1px solid #eee;
padding-top: 20px;
color: #444;
line-height: 1.6;
}
.bmi-explanation h3 {
margin-bottom: 10px;
color: #333;
}
.bmi-explanation p {
margin-bottom: 15px;
}
.bmi-explanation ul {
padding-left: 20px;
}
.bmi-explanation li {
margin-bottom: 8px;
}
function calculateBMI() {
var weightInput = document.getElementById("weight");
var heightInput = document.getElementById("height");
var resultDiv = document.getElementById("bmi-result");
var weight = parseFloat(weightInput.value);
var height = parseFloat(heightInput.value);
if (isNaN(weight) || isNaN(height) || height <= 0) {
resultDiv.innerHTML = "Please enter valid numbers for weight and height (height must be greater than 0).";
return;
}
var bmi = weight / (height * height);
bmi = bmi.toFixed(2); // Round to two decimal places
var bmiCategory = "";
if (bmi = 18.5 && bmi = 25 && bmi <= 29.9) {
bmiCategory = "Overweight";
} else {
bmiCategory = "Obese";
}
resultDiv.innerHTML = "Your BMI is: " + bmi + " (" + bmiCategory + ")";
}
Body Mass Index (BMI) Calculator
kg
meters
Your BMI will appear here.
What is Body Mass Index (BMI)?
Body Mass Index (BMI) is a simple calculation used to estimate whether a person has a healthy weight for their height. It's a useful screening tool, but it doesn't diagnose the body fatness or health of an individual.
The formula for BMI is: weight (kg) / [height (m)]².
BMI Categories:
- Underweight: BMI less than 18.5
- Normal weight: BMI between 18.5 and 24.9
- Overweight: BMI between 25 and 29.9
- Obesity: BMI of 30 or greater
It's important to remember that BMI is just one factor in assessing health. Muscle mass, bone density, and body fat percentage can also play significant roles. If you have concerns about your weight or health, please consult a healthcare professional.