"I've always wondered what a height different between a 4'10 person and a 5'7 person would look like … I found this image but idk if it's up to scale or not."

That question, posted to r/heightcomparison, is the whole genre in one sentence. People want to see a height gap, they find a picture, and then they have no way to tell whether the picture is honest. If you are building the tool that makes those pictures, "is it up to scale?" is the one question your code has to answer correctly every time.

It sounds trivial: multiply height by a constant and draw. In practice, height comparison charts break in a handful of predictable ways: an axis that does not start at zero, figures that float instead of standing on a floor, decorations that add fake height, and a sneaky unit-conversion bug that shifts some heights by a quarter of an inch and not others. This post builds a small, framework-free JavaScript module for a height comparison to scale, with a node --test suite. Along the way it explains each failure mode and the test that catches it.

What people actually ask (and what they notice)

The original question is old, but the pattern keeps repeating. In September 2026 a developer posted their new height comparison site to the same subreddit and asked for brutally honest feedback, specifically: "Does the visual height difference look intuitive?" and "Do you notice anything that looks inaccurate or misleading?" The replies are a free QA report, and three of them are worth turning into requirements:

  1. A rounding bug. One user wrote that the site "changes all odd heights from 5'11" to 6'7" to a fraction 1/4 above or below the entered height. I.e. 6'5" = 6'5 1/4" and 6'1" = 6'3/4"".
  2. Decoration that changes perceived height. Another said "5'9 without the circle somehow feels taller than 5'10 with the circle," and suggested putting the portrait "as an emblem on the chest instead."
  3. Eye level expectations. A 195.5 cm user said the figure's eyes did not line up with 6 ft, "which is my eye level."

On the developer side, the parsing questions never stop. A Stack Overflow question asks how to convert 5'5" to centimetres when the data sometimes says 5' 5" with a space. An r/learnjavascript beginner tried to convert feet and inches to metres and lost the values to variable scope. And in r/FanFiction, someone wanted to line up 25 characters and found that every site capped the number of people.

So the requirements write themselves: accept the formats people type, refuse the ones that are ambiguous, never let a conversion drift, draw everyone on one floor with one scale, and be honest about what a silhouette can and cannot show.

The geometry: one ground line, one scale

Height comparison to scale: the same 4 ft 10 in and 5 ft 7 in silhouettes drawn three ways, with a truncated axis starting at 140 cm that exaggerates the gap about four times, figures centred vertically that hide half the gap, and the correct chart with one ground line and an axis from zero
Is this height comparison up to scale? The same 4'10" and 5'7" drawn three ways. Only the third panel, with an axis from zero and one shared ground line, is a height comparison to scale.

A height comparison to scale has exactly two rules:

  • One ground line. Every figure's feet sit on the same y coordinate. If you centre figures vertically (panel 2), half the difference moves below the floor and the visible gap shrinks to half. For 4'10" vs 5'7", that is 11.4 cm visible instead of 22.9 cm.
  • One scale, starting at zero. Pixels per centimetre is a single number for the whole chart, and 0 cm sits on the ground line. If your scale maps "height minus 140 cm" to pixels (panel 1), the shorter person shrinks to 7.3 units against 30.2, about four times smaller, when the real ratio is 170.18 / 147.32 ≈ 1.155.

The truncated axis is the same mistake as a bar chart that does not start at zero. It is tempting because it makes small differences "readable," but in a height chart the visual ratio is the message. If you need to emphasize a 2 cm gap, add a zoomed inset or a number, not a cropped axis.

Step 1: store heights as unrounded centimetres

Height comparison to scale in JavaScript: bar chart of displayed minus entered height from 4 ft 10 in to 6 ft 8 in when centimetres are rounded on storage, showing quarter-inch drift at exactly the odd heights from 5 ft 11 in to 6 ft 7 in, and zero drift when heights are stored unrounded
Height comparison to scale in JavaScript: storing Math.round(cm) and converting back to the nearest quarter inch shifts exactly the odd heights from 5'11" to 6'7" by 1/4 inch. Storing unrounded centimetres gives zero drift.

Let's start with the bug report, because it is the most instructive. I don't know how that site is built, but a very common pipeline reproduces the report exactly:

  1. User enters 6'5".
  2. Convert: 77 in × 2.54 = 195.58 cm.
  3. Store Math.round(cm) → 196.
  4. Display: 196 / 2.54 = 77.165 in → nearest quarter inch → 6'5¼".

Run that for every inch from 5'11" to 6'7", and the heights that drift are 5'11", 6'1", 6'3", 6'5" and 6'7". Those are the odd ones, just as reported, with 6'5" going up a quarter and 6'1" going down a quarter (185.42 → 185 → 72.835 in → 6'0¾"). Even heights in that range happen to land within an eighth of an inch after rounding, so they look fine, which is exactly why this bug survives casual testing.

The inch is defined as exactly 2.54 cm, so there is no reason to lose information. The fix is a rule: pick one canonical unit, store it unrounded, and round only at the display edge. Centimetres as a JavaScript Number is fine; a double holds 180.34 to far more precision than a chart needs. If you persist to a database, an integer number of micrometres or a decimal column also works. Whole centimetres do not.

Step 2: parse what people type, refuse what is ambiguous

Height inputs arrive as 5'11", 5' 11, 5ft 11in, 71 in, 180 cm, 1.8 m, and the one that causes real trouble: 5.11. Is that 5.11 feet (about 155.8 cm) or 5 feet 11 inches (180.34 cm)? Users mean the second far more often, but silently guessing is how a 25 cm error ends up in a chart. My parser refuses it and offers a suggestion the UI can show as "Did you mean 5'11"?":

export const CM_PER_INCH = 2.54; // exact by definition export const MIN_CM = 20; export const MAX_CM = 300; const num = String.raw`(\d+(?:\.\d+)?)`; const PATTERNS = [ // 5'11" 5' 11 5'11.5'' 5ft 11in 5' { re: new RegExp(String.raw`^(\d+)\s*(?:'|’|ft|feet)\s*(?:${num}\s*(?:"|”|''|in|inch|inches)?)?$`, "i"), toCm: (m) => feetInches(Number(m[1]), m[2] === undefined ? 0 : Number(m[2])) }, { re: new RegExp(String.raw`^${num}\s*(?:"|”|''|in|inch|inches)$`, "i"), toCm: (m) => Number(m[1]) * CM_PER_INCH }, { re: new RegExp(String.raw`^${num}\s*(?:cm|centimet(?:er|re)s?)$`, "i"), toCm: (m) => Number(m[1]) }, { re: new RegExp(String.raw`^${num}\s*(?:m|met(?:er|re)s?)$`, "i"), toCm: (m) => Number(m[1]) * 100 }, ]; export function feetInches(feet, inches = 0) { if (!Number.isInteger(feet) || feet < 0) throw new RangeError("Feet must be a whole number"); if (!Number.isFinite(inches) || inches < 0 || inches >= 12) throw new RangeError("Inches must be at least 0 and below 12"); return (feet * 12 + inches) * CM_PER_INCH; } export function parseHeight(input, { bareUnit = null } = {}) { const s = String(input ?? "").trim().replace(/\s+/g, " "); if (!s) return { ok: false, error: "Enter a height" }; // "5.11" usually means 5'11", not 5.11 ft. Ask instead of guessing. const dotted = s.match(/^([3-8])\.(\d{1,2})$/); if (dotted && bareUnit !== "cm" && bareUnit !== "m") { const inches = Number(dotted[2]); const suggestion = inches < 12 ? `${dotted[1]}'${inches}"` : undefined; return { ok: false, error: `Ambiguous: "${s}" could be decimal feet or feet.inches`, suggestion }; } for (const p of PATTERNS) { const m = s.match(p.re); if (m) { let cm; try { cm = p.toCm(m); } catch (e) { return { ok: false, error: e.message }; } return checkRange(cm); } } if (/^\d+(?:\.\d+)?$/.test(s)) { if (bareUnit === "cm") return checkRange(Number(s)); if (bareUnit === "m") return checkRange(Number(s) * 100); if (bareUnit === "in") return checkRange(Number(s) * CM_PER_INCH); return { ok: false, error: "Add a unit (cm, m, ft/in)" }; } return { ok: false, error: `Could not read "${s}"` }; } function checkRange(cm) { if (!Number.isFinite(cm)) return { ok: false, error: "Not a number" }; if (cm < MIN_CM || cm > MAX_CM) return { ok: false, error: `Height must be ${MIN_CM}-${MAX_CM} cm` }; return { ok: true, cm }; } 

A few deliberate choices:

  • Feet must be whole, inches must be below 12. 5'13" is rejected rather than "helpfully" normalized to 6'1". Someone who typed 13 probably made a typo, and you can't know which digit is wrong.
  • A bare number needs a unit. If your form has a separate cm field, pass bareUnit: "cm". A free-text box that accepts 180 and assumes centimetres will one day receive 71 from someone who meant inches.
  • The result is an object, not a throw. Form validation wants a message to display; reserve exceptions for programmer errors.
  • Typographic quotes are accepted. Phones autocorrect ' to ’ and " to ”. If you only match straight quotes, iOS users get "Could not read."

The 20–300 cm range is a product policy, not a fact about people. It matches the limits on Body Visualizer's height comparison tool, which also requires whole feet and inches below 12. Pick limits that suit your audience and test both edges.

Step 3: format for humans, with carry

Displaying feet and inches has its own classic bug: 5'12". If you compute feet with Math.floor and then round the remaining inches, 71.9 inches becomes 5 feet and 12 inches. Round the total first, then split:

export function formatFtIn(cm, { denominator = 1 } = {}) { const totalUnits = Math.round((cm / CM_PER_INCH) * denominator); const feet = Math.floor(totalUnits / (12 * denominator)); const rest = totalUnits - feet * 12 * denominator; const whole = Math.floor(rest / denominator); const frac = rest - whole * denominator; if (!frac) return `${feet}'${whole}"`; const g = gcd(frac, denominator); return `${feet}'${whole} ${frac / g}/${denominator / g}"`; } const gcd = (a, b) => (b ? gcd(b, a % b) : a); 

denominator: 4 gives quarter inches; denominator: 1 gives whole inches. Because the input is the unrounded canonical value, formatFtIn(parseHeight("6'5\"").cm, { denominator: 4 }) returns 6'5" every time.

The difference readout should follow the same rule. I compute the percentage relative to the shorter person, which is how the Body Visualizer tool explains it too: 160 cm vs 175 cm is a 15 cm gap, and 15 / 160 = 9.375%. Whichever base you choose, state it in the UI, because "9.4% taller" and "8.6% shorter" describe the same pair.

export function difference(aCm, bCm) { const taller = Math.max(aCm, bCm), shorter = Math.min(aCm, bCm); const cm = taller - shorter; return { cm, inches: cm / CM_PER_INCH, percentOfShorter: shorter > 0 ? (cm / shorter) * 100 : NaN }; } 

Step 4: lay out everyone on one floor

The layout function is where "up to scale" is actually enforced. It computes a single pxPerCm from the tallest person plus some headroom, puts 0 cm on the ground line, and measures every figure from the same floor:

export function layout(people, { width = 800, height = 500, top = 30, bottom = 40, left = 60, headroom = 0.08 } = {}) { if (!people.length) throw new RangeError("Need at least one person"); const plotH = height - top - bottom; const groundY = height - bottom; const maxCm = Math.max(...people.map((p) => p.cm)); const axisMaxCm = maxCm * (1 + headroom); const pxPerCm = plotH / axisMaxCm; // the ONE scale const slot = (width - left) / people.length; const figures = people.map((p, i) => ({ ...p, x: left + slot * i + slot / 2, heightPx: p.cm * pxPerCm, topY: groundY - p.cm * pxPerCm, // every figure measured from the same ground })); const step = niceStep(axisMaxCm); const ticks = []; for (let v = 0; v <= axisMaxCm + 1e-9; v += step) ticks.push({ cm: v, y: groundY - v * pxPerCm }); return { width, height, groundY, pxPerCm, axisMaxCm, figures, ticks }; } 

niceStep picks ruler intervals of 1, 2, 2.5 or 5 times a power of ten, so a chart of people gets 25 cm ticks and a chart that includes a building gets round hundreds:

export function niceStep(range, targetTicks = 8) { const raw = range / targetTicks; const mag = 10 ** Math.floor(Math.log10(raw)); for (const m of [1, 2, 2.5, 5, 10]) if (raw <= m * mag) return m * mag; return 10 * mag; } 

The layout function is pure: give it heights and a box, get numbers back. That makes the "to scale" property directly testable, which matters more than any amount of visual review.

If you need many people, like the 25 fan-fiction characters, keep the same pxPerCm and let the chart scroll horizontally. Shrinking each slot until figures overlap, or splitting the cast into separately scaled charts, breaks comparability. If you do split, reuse one scale across every chunk.

Step 5: render SVG with no hidden padding

Here is the subtle part behind the "circle" complaint. Most silhouette artwork has padding: transparent space above the head inside the image or SVG viewBox. Scale that asset to heightPx and the visible crown lands below the true height. Add a portrait circle above the head and the eye reads the circle's top as the person's top.

My silhouette path is authored in a unit box where y = 0 is the crown and y = 1 is the soles, with nothing above or below:

const SILHOUETTE = "M0,0.0 C0.07,0 0.075,0.11 0.0,0.125 C-0.075,0.11 -0.07,0 0,0 Z " + "M-0.11,0.14 L0.11,0.14 L0.12,0.52 L0.06,0.52 L0.05,1 L-0.05,1 L-0.06,0.52 L-0.12,0.52 Z"; // inside renderSvg, for each figure f: parts.push(`<path d="${SILHOUETTE}" transform="translate(${f.x.toFixed(2)} ${f.topY.toFixed(4)}) scale(${f.heightPx.toFixed(4)})" fill="${esc(f.color ?? "#7c3aed")}"/>`); 

translate to the crown, then scale by the pixel height, and the feet land exactly on groundY. If you use richer artwork, measure its real bounding box once (for example with getBBox() in a build step) and normalize it to this convention. Keep names, portraits and badges outside the height box: below the ground line, beside the figure, or on the chest as that commenter suggested. The full renderSvg also draws the ruler, escapes names (people will type <b> into a name field), and adds a <title> so screen readers get the heights as text.

Eye lines: draw them honestly or not at all

The 195.5 cm user who expected the figure's eyes at 6 ft has a fair point, but it reveals a limit rather than a bug. A generic silhouette puts the eyes at a fixed fraction of its drawn height. A real person's eye height depends on their head size and posture, which you have not measured. If you draw an "eye line," say it is approximate and derived from the figure, not from the user.

Body Visualizer's height comparison page takes a clear position here: the drawing "shows relative total height only" and "cannot establish where someone's head would reach on another person's body, because individual proportions have not been measured." That is a good sentence to borrow for your own UI. The same honesty applies to width. A height chart that draws a heavier person as a wider silhouette is guessing. If you want to show build, use a tool built for that, such as a side-by-side height and weight comparison in 3D, and label it as an estimate.

The tests that prove "up to scale"

The suite has nine tests. These are the ones I'd keep even if I deleted everything else:

test("reproduces the 'odd heights drift by 1/4 inch' bug when cm are rounded on storage", () => { const storeRounded = (cm) => Math.round(cm); // the bug assert.equal(formatFtIn(storeRounded(feetInches(6, 5)), { denominator: 4 }), `6'5 1/4"`); assert.equal(formatFtIn(storeRounded(feetInches(6, 1)), { denominator: 4 }), `6'0 3/4"`); // ...and across 5'11"–6'7" exactly [5'11", 6'1", 6'3", 6'5", 6'7"] drift }); test("unrounded storage round-trips every quarter inch from 3'0\" to 9'10\"", () => { for (let q = 36 * 4; q <= 118 * 4; q++) { const inches = q / 4, ft = Math.floor(inches / 12), rest = inches - ft * 12; const cm = parseHeight(`${ft}'${rest}"`).cm; const expected = formatFtIn(inches * CM_PER_INCH, { denominator: 4 }); assert.equal(formatFtIn(cm, { denominator: 4 }), expected); } }); test("layout: one scale, one ground line, axis from zero", () => { const lay = layoutSource:https://dev.to/charlotte_nelson_9aadde70/is-this-height-comparison-up-to-scale-how-to-draw-one-correctly-in-javascript-and-svg-21m

Related posts