The lh and rhl units
html: line-height
html {
font-size: 1.1rem;
line-height: 1.4;
}
line-height: 1.4;: This sets the line height for the entire HTML document relative to the font size. Aline-heightof 1.4 means the space between lines of text is 1.4 times the font size. This improves readability by providing adequate spacing between lines.
section: padding
section {
padding: 2rlh;
margin-trim: block;
}
padding: 2rlh;: This sets the padding inside eachsectionelement. The value2rlhuses therlh(root line height) unit, which is calculated based on theline-heightof thehtmlelement. Givenhtml { line-height: 1.4; }, the root line height (rlh) becomes 1.4 times the root font size. Here,2rlhmeans padding is set to twice the root line height.
h1, p: margin-block
h1 {
font-size: 2rem;
line-height: 1.2;
}
h1, p {
margin-block: 1rlh;
}
margin-block: 1rlh;: This sets the margin on both theblock-startandblock-end(top and bottom) ofh1andpelements to1rlh. The value1rlhuses therlh(root line height) unit and it ensures consistent vertical spacing relative to the root line height. Given thehtml { line-height: 1.4; },1rlhcorresponds to a margin equal to the root line height, facilitating consistent and proportional spacing.

Summary
htmlelement: Sets a global line height of 1.4, establishing the base root line height (rlh) for the document.sectionelement: Applies padding based on twice the root line height (2rlh) and trims margins.h1, pelements: Assigns a block margin of1rlh, ensuring proportional and consistent vertical spacing relative to the root line height, enhancing the layout’s readability and visual balance.
The result is a vertical rhythm that matches the height of a line of text even though no actual text is present between elements.
Leave a Reply