Back to templates
Interactive BMI calculator
A responsive Body Mass Index calculator with instant range feedback and clear units.
Source code
1 lines · 1.4 KB<style>*{box-sizing:border-box}body{margin:0;font-family:Inter,system-ui,sans-serif;background:#f6f7fb;color:#172033}button,a{font:inherit}.wrap{width:min(960px,calc(100% - 32px));margin:auto}</style><style>main{min-height:100vh;display:grid;place-items:center;padding:24px}.calc{width:min(440px,100%);background:#fff;border:1px solid #e2e8f0;border-radius:18px;padding:28px}label{display:block;font-weight:600;margin:14px 0 6px}input{width:100%;padding:11px;border:1px solid #cbd5e1;border-radius:9px;font:inherit}.res{margin-top:20px;padding:16px;border-radius:12px;background:#f8fafc;text-align:center}.res strong{font-size:32px;display:block}</style><main><form class="calc" oninput="calc()"><h1 style="margin:0 0 6px">BMI Calculator</h1><p style="margin:0;color:#64748b">Metric units (cm / kg)</p><label for="h">Height (cm)</label><input id="h" type="number" value="175" min="80" max="250"><label for="w">Weight (kg)</label><input id="w" type="number" value="68" min="20" max="300"><div class="res"><strong id="bmi">22.2</strong><span id="cat">Normal weight</span></div></form></main><script>function calc(){const h=+document.getElementById("h").value/100,w=+document.getElementById("w").value;if(!h||!w)return;const v=w/(h*h);document.getElementById("bmi").textContent=v.toFixed(1);document.getElementById("cat").textContent=v<18.5?"Underweight":v<25?"Normal weight":v<30?"Overweight":"Obesity"}</script>When this template fits
A straightforward interactive calculator template demonstrating live form input events, validation bounds, and instant output updates.
How the layout works
Labeled numeric inputs trigger oninput recalculation with zero page reload, updating both the rounded index and category label.
What to customize
Add metric/imperial unit toggles, enforce sensible min/max input validation, and include clear context that BMI is only a rough screening number.
Review before publishing
Test empty or zero inputs to verify the calculator never displays NaN or Infinity, and check label associations for screen readers.
Keep building with context
Compare a related pattern or read a practical guide before adapting this example in the Playground.