BMI Calculator: how it works and how to build one
Body mass index in metric or imperial, with healthy range. This guide explains what happens behind the button and shows the code, so you can build your own.
What it does
Enter height and weight in cm and kg or feet, inches and pounds to get your BMI, its category and the healthy weight range for your height. Uses the WHO ranges, with the lower Asian cut-offs as an option.
When to use it
- Health checks
- Fitness apps
- Insurance forms
How to use it
- Pick metric or imperial.
- Enter height and weight.
- Read your BMI and healthy range.
Try it free in your browser, nothing is uploaded: https://eskillsfy.com/tools/bmi-calculator
How it works
BMI is weight in kilograms divided by height in metres squared. Imperial inputs are converted first (1 inch = 0.0254 m, 1 lb = 0.4536 kg).
The WHO’s Asian cut-offs (23 for overweight, 25 for obese) are lower than the general ones because health risks start at lower BMI in South Asian populations.
Build it yourself
Here is the core of the tool. It has no dependencies unless noted, so you can paste it into any TypeScript or JavaScript project.
bmi.ts (ts)
export function bmi(heightCm: number, weightKg: number, asian = true) {
const m = heightCm / 100, value = weightKg / (m * m);
const [under, over, obese] = asian ? [18.5, 23, 25] : [18.5, 25, 30];
const category = value < under ? "Underweight" : value < over ? "Healthy" : value < obese ? "Overweight" : "Obese";
return { value: +value.toFixed(1), category, healthyKg: [under * m * m, (over - 0.1) * m * m] };
}
Make it production-ready
- Explain BMI’s limits (muscle, age, pregnancy).
Questions
Is BMI accurate?
It is a quick screening number. It does not tell muscle from fat, so ask a doctor about your health.
Free, runs in your browser, nothing is uploaded.