Line Height Calculator
Calculate unitless CSS line-height from font size and line height in px. Add multiple rows, copy results in your browser. No signup.
How to Use a Free Line Height Calculator to Convert px to Unitless CSS
What Is Unitless Line-Height?
In CSS, the line-height property controls the vertical space between lines of text. You can express it in several units — pixels, percentages, ems, or as a plain number. That plain number is what developers call unitless line-height. Instead of writing line-height: 24px, you write line-height: 1.5. The browser multiplies that ratio by the element's current font size to compute the spacing at render time.
This distinction matters more than it first appears. A fixed pixel value is rigid: if a visitor bumps up their default font size for accessibility, your 24px line stays 24px and the text can feel cramped. A unitless value scales with the font, so the rhythm of your paragraphs stays comfortable at any size. That is why most modern style guides recommend unitless line-height as the default.
Why Use This Calculator
Converting by hand is error-prone, especially once you are juggling several components with different font sizes. Our free Line Height Calculator does the math for you: enter a font size and a line height in pixels, and it returns the unitless ratio instantly. Everything runs in your browser, so nothing is uploaded and no account is required.
Use it when you are:
- Migrating a legacy stylesheet that used
pxline-heights to a more flexible unitless system. - Matching a design mockup that specifies spacing in pixels but needs to scale responsively.
- Auditing a site for accessibility and want consistent, font-relative vertical rhythm.
- Teaching or documenting a typographic scale for a team.
How to Use the Tool
The calculator above works row by row, and you can add as many rows as you need.
Step 1 — Enter your font size. Type the font size in pixels into the Font Size field. The field only accepts numbers and a single decimal point, so letters are blocked automatically.
Step 2 — Enter your line height. Type the desired line height in pixels into the Line Height field. This is the total vertical space you want each line to occupy.
Step 3 — Read the unitless result. The Unitless field is disabled and shows the computed ratio, rounded to two decimal places. Click it (or blur the input) to copy the value to your clipboard.
Step 4 — Add or remove rows. Use the + button on any row to insert another calculation beneath it, and the − button to delete that row. At least one row always remains so the tool never becomes empty.
Step 5 — Paste into CSS. Drop the copied number straight into your stylesheet as line-height: 1.5; or use it inside a CSS custom property.
Pressing Enter inside any field moves focus to the next control, so you can fly through a list of values without touching the mouse.
Worked Examples
The formula is simply unitless = lineHeightPx / fontSizePx, rounded to two decimals.
- 16px font, 24px line height →
24 / 16 = 1.5. This is the classic, comfortable reading ratio. - 16px font, 20px line height →
20 / 16 = 1.25. Tighter, common for headings or dense UI. - 18px font, 27px line height →
27 / 18 = 1.5. Same ratio, larger text — proof the unitless value scales. - 14px font, 21px line height →
21 / 14 = 1.5. Again the same ratio holds across sizes. - 20px font, 30px line height →
30 / 20 = 1.5.
Notice that the same ratio keeps appearing. That is the whole point: a unitless value describes a relationship, not a fixed measurement, so it behaves identically whether your base is 14px or 20px.
If the font size is left empty or set to 0, the tool shows a dash (—) rather than a number, because dividing by zero is undefined. Fill in both fields to see a result.
Tips and Best Practices
- Aim for 1.4 to 1.6 for body text. Most long-form content reads best in that band. Below 1.4 feels tight; above 1.7 can feel loose and disconnected.
- Use unitless for inheritance. When
line-heightis set as a number, child elements inherit the ratio, not a computed pixel value. Withpxorem, children inherit a resolved length, which can produce surprising results inside nested elements. - Reserve px for one-off overrides. Pixel line-heights are fine when you need pixel-perfect alignment with a mockup, but reach for the unitless form as your default.
- Pair with a type scale. Define base sizes with a modular scale, then apply a single unitless line-height across the scale for visual consistency.
- Test with larger fonts. Bump your browser's minimum font size and confirm paragraphs still breathe. Unitless values make this pass automatically.
Frequently Asked Questions
Is unitless line-height the same as em?
No. An em line-height is resolved against the element's own font size at compute time, which can compound oddly inside nested text. A unitless number is a pure multiplier applied to the current font size and is the value most style guides recommend.
Why does my design tool show pixels but CSS wants a ratio? Design tools think in fixed artboard measurements, while the web renders across countless device and user settings. Converting to a unitless ratio lets your intended proportion survive those differences.
Can I use decimals like 1.45? Yes. The calculator rounds to two decimal places, which is plenty of precision for typography. Most teams standardize on tidy values such as 1.4, 1.5, or 1.6.
Does this work for any font? Line-height is independent of the typeface. The ratio describes spacing relative to font size, so the same number works whether you use a serif, sans-serif, or monospace face.
What happens if I enter letters? The input fields reject non-numeric characters. You can type digits and a single decimal point; anything else is ignored, so the calculation never breaks.
Do I need to install anything? No. The calculator runs entirely in your browser with plain JavaScript. There is no download, no signup, and nothing is sent to a server.
Related Tools
More calculator tools are on the way. In the meantime, explore the rest of the free utilities in the Tools section — all built to run privately in your browser.