Line Height Calculator
Turn a pixel line height into the unitless line-height ratio that CSS recommends, or work the other way and get pixels from a ratio. Enter a font size, then flip between the px to ratio and ratio to px tabs to fill in the value you have. Both results appear at once so you can copy the number you need.
How to calculate line-height
- Enter the font size in pixels in the Font size (px) field.
- Pick the px to ratio tab to convert a pixel value, or ratio to px to convert a ratio.
- Type the line height in pixels, or the unitless ratio, into the second field.
- Read both the Unitless line-height and Line height in pixels cards.
- Press Copy ratio to drop the unitless value straight into your CSS.
Examples
Body copy: pixels to a ratio
16px font, 24px line (px to ratio)
ratio 1.5
Wider spacing: pixels to a ratio
20px font, 32px line (px to ratio)
ratio 1.6
Sizing up from a ratio
18px font, ratio 1.6 (ratio to px)
28.8px
Frequently asked questions
What is a unitless line-height?
A unitless line-height is a plain number like 1.5 with no unit attached. CSS multiplies it by each element's own font-size, so the spacing stays proportional even when child elements use different font sizes.
How do I convert a pixel line height to a ratio?
Divide the line height in pixels by the font size in pixels. A 24px line on a 16px font is 24 divided by 16, giving a ratio of 1.5. The px to ratio tab does this for you as you type.
How do I go from a ratio back to pixels?
Multiply the font size by the ratio. On an 18px font a ratio of 1.6 works out to 28.8px, which is the computed line box height. Switch to the ratio to px tab to see this result.
Why is a unitless line-height preferred over px?
A fixed px or em line-height is calculated once and then inherited as that exact length, which can crowd larger child text. A unitless value is re-multiplied for each element, so nested headings and body text always get spacing in proportion to their own size.
What is a good line-height for body text?
A ratio between roughly 1.4 and 1.6 reads comfortably for paragraphs. Headings can go tighter, around 1.1 to 1.3, because their lines are short and too much leading looks disconnected.
Does line-height include the font size itself?
Yes. Line-height is the full height of each line box, not the gap between lines. A 16px font at a 1.5 ratio produces 24px line boxes, so the extra room split above and below the text is 8px in total.
How precise are the results?
Values are shown to up to six decimal places and trailing zeros are trimmed, so 1.5 stays 1.5 while an awkward division shows its full precision. The maths itself is exact; only the display is shortened.
Can I enter fractional font sizes?
Yes. Any positive font size works, including decimals like 15.5px, and the line height in pixels can be zero or larger. The font size must be greater than zero or the tool asks you to enter a positive value.
Is anything sent to a server?
No. The conversion runs entirely in your browser, so the sizes you enter are never uploaded or stored. You can use it offline once the page has loaded.
Learn more
- Why unitless line-height wins in CSS
How CSS line-height inheritance works, why a unitless ratio beats px and em, and practical ratios for body text, headings and UI.
Related tools
Type Scale Calculator
Generate a modular type scale from a base size and a ratio. Get px and rem for every step, from small print to display headings. Free and exact.
PX to REM Calculator
Convert px to rem and rem to px against any root font-size. Set the root, type a value, and copy clean numbers for scalable CSS typography.
Letter Spacing Calculator
Convert Photoshop or Figma tracking to CSS letter-spacing in em and px. Tracking is in thousandths of an em, so 50 becomes 0.05em. Exact and free.
.env to JSON
Convert a .env file to JSON, or JSON back to .env. Parses KEY=value lines, comments, quotes and export. Runs entirely in your browser.
ASCII Table
Full ASCII table for all 128 codes with decimal, hex, octal and binary values, character names and descriptions. Search by code, hex or character.
Aspect Ratio Box Generator
Generate CSS for a responsive aspect-ratio container. Use the modern aspect-ratio property or the padding-top fallback, then copy the ready code.