Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

CSS property `line-height`

`line-height` determines the height of text line boxes and therefore its vertical rhythm.

Version: CSS modules; captured CSSWG editor index includes draft and obsolete features requiring review

Syntax

normal | <number> | <length> | <percentage>

line-height determines the height of text line boxes and therefore its vertical rhythm.

The example measures two lines first at a 16px line height and then at 24px, showing the whole block grow from 32 to 48 pixels.

Grammar: normal | <number> | <length> | <percentage>.

A unitless number inherits as a multiplier, whereas a length inherits as a computed value; descendants with another font size therefore retain the proportion only in the first case. A small value can overlap lines but does not itself clip glyphs.

Examples

<!doctype html>
<html lang="en"><meta charset="utf-8"><title>line-height behavior</title>
<body><span id="probe">one<br>two</span><pre id="result"></pre><script>
const probe=document.querySelector('#probe');probe.style.cssText='display:inline-block;font-size:16px;line-height:16px';
const compact=Math.round(probe.getBoundingClientRect().height);probe.style.lineHeight='24px';const open=Math.round(probe.getBoundingClientRect().height);
document.querySelector('#result').textContent='height='+compact+'->'+open+'; computed='+getComputedStyle(probe).lineHeight;
</script></body></html>

Result

height=32->48; computed=24px

The example was executed locally in an isolated, network-free Chrome session; the result comes from the browser CSS API.

Sources