Performance: Line height and leading
Line height affects text readability and vertical spacing, impacting paint and layout performance when changed frequently.
Jump into concepts and practice - no test required
<p class="leading-relaxed">Text with standard Tailwind leading</p><p class="leading-[2.5rem]">Text with custom large line height</p>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Arbitrary inline line-height | Minimal | 1 per text block | Moderate | [X] Bad |
| Tailwind predefined leading classes | Minimal | 1 on initial load | Low | [OK] Good |
leading-relaxed control in a text block?leading- classesleading- classes set the line height, which is the vertical space between lines of text.leading-relaxed doesleading-relaxed increases the line height to make text more spaced out and easier to read.leading-5 corresponds to 1.25 line height, which is 20px if the font size is 16px.leading-6 is 1.5, leading-4 is 1, and leading-7 is 1.75, so only leading-5 matches 1.25.<p class="leading-tight">This is a line of text.</p> <p class="leading-loose">This is another line of text.</p>
leading-tight and leading-looseleading-tight sets a smaller line height (less space), while leading-loose sets a larger line height (more space).<p class="leading-10">Sample text</p>
leading-10 is a valid Tailwind class setting line-height to 2.5rem.leading-10 does not existmd: apply at medium screen sizes and above.leading-normal md:leading-relaxed fits.