BMI Calculator
This calculator helps you determine your Body Mass Index (BMI), a common measure used to estimate body fat and classify weight categories. A healthy BMI is generally considered to be between 18.5 and 24.9.
Understanding Your BMI
Body Mass Index (BMI) is a value derived from the mass (weight) and height of a person. The formula is as follows:
BMI = weight (kg) / [height (m)]2
BMI Categories:
- Underweight: Below 18.5
- Normal weight: 18.5 – 24.9
- Overweight: 25 – 29.9
- Obesity: 30 or greater
It's important to remember that BMI is a screening tool and does not diagnose body fatness or health. Factors like muscle mass, bone density, and body composition can influence BMI. Consult a healthcare professional for personalized health advice.
Example Calculation:
Let's say a person weighs 75 kg and is 1.80 meters tall.
BMI = 75 / (1.80 * 1.80) = 75 / 3.24 = 23.15
In this example, a BMI of 23.15 falls within the "Normal weight" category.
function calculateBMI() {
var weight = document.getElementById("weight").value;
var height = document.getElementById("height").value;
var resultDiv = document.getElementById("result");
// Clear previous results
resultDiv.innerHTML = "";
// Validate input
if (isNaN(weight) || isNaN(height) || weight <= 0 || height <= 0) {
resultDiv.innerHTML = "Please enter valid positive numbers for weight and height.";
return;
}
// Calculate BMI
var bmi = weight / (height * height);
var bmiRounded = bmi.toFixed(2);
var category = "";
if (bmi = 18.5 && bmi = 25 && bmi <= 29.9) {
category = "Overweight";
} else {
category = "Obesity";
}
resultDiv.innerHTML = "Your BMI is:
" + bmiRounded + "Category:
" + category + "";
}
#bmiCalculator {
font-family: sans-serif;
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 8px;
background-color: #f9f9f9;
}
#bmiCalculator h2 {
text-align: center;
color: #333;
margin-bottom: 20px;
}
.calculator-inputs {
display: flex;
flex-direction: column;
gap: 15px;
margin-bottom: 20px;
}
.input-group {
display: flex;
flex-direction: column;
gap: 5px;
}
.input-group label {
font-weight: bold;
color: #555;
}
.input-group input[type="number"] {
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 1em;
}
#bmiCalculator button {
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;
}
#bmiCalculator button:hover {
background-color: #45a049;
}
.calculator-result {
margin-top: 20px;
padding: 15px;
background-color: #e0ffe0;
border: 1px solid #a0e0a0;
border-radius: 4px;
text-align: center;
font-size: 1.2em;
}
.calculator-result p {
margin: 5px 0;
}
.calculator-explanation {
margin-top: 30px;
padding-top: 20px;
border-top: 1px solid #eee;
font-size: 0.95em;
color: #444;
}
.calculator-explanation h3,
.calculator-explanation h4 {
color: #333;
margin-bottom: 10px;
}
.calculator-explanation ul {
list-style-type: disc;
margin-left: 20px;
margin-bottom: 10px;
}
.calculator-explanation li {
margin-bottom: 5px;
}