0
0
Tailwindmarkup~8 mins

Line height and leading in Tailwind - Performance & Optimization

Choose your learning style9 modes available
Performance: Line height and leading
LOW IMPACT
Line height affects text readability and vertical spacing, impacting paint and layout performance when changed frequently.
Adjusting text vertical spacing for readability
Tailwind
<p class="leading-relaxed">Text with standard Tailwind leading</p>
Using predefined Tailwind line-height classes ensures consistent spacing and avoids unexpected layout shifts.
📈 Performance Gainsingle reflow on load, stable layout reduces CLS
Adjusting text vertical spacing for readability
Tailwind
<p class="leading-[2.5rem]">Text with custom large line height</p>
Using arbitrary large line heights inline causes layout recalculations and potential layout shifts on resize.
📉 Performance Costtriggers 1 reflow per text block, increases CLS risk
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Arbitrary inline line-heightMinimal1 per text blockModerate[X] Bad
Tailwind predefined leading classesMinimal1 on initial loadLow[OK] Good
Rendering Pipeline
Line height changes affect the Layout and Paint stages by changing text block height and spacing, which can cause reflows and repaints.
Layout
Paint
Composite
⚠️ BottleneckLayout
Core Web Vital Affected
CLS
Line height affects text readability and vertical spacing, impacting paint and layout performance when changed frequently.
Optimization Tips
1Use Tailwind's predefined leading classes for consistent line height.
2Avoid arbitrary inline line-height values to prevent layout shifts.
3Consistent line height reduces reflows and improves CLS.
Performance Quiz - 3 Questions
Test your performance knowledge
Which line-height usage helps reduce layout shifts and improve CLS?
AUsing consistent Tailwind leading classes
BUsing arbitrary inline large line-height values
CChanging line-height dynamically on every frame
DNot setting line-height at all
DevTools: Performance
How to check: Record a performance profile while resizing or loading the page, then look for Layout and Recalculate Style events related to text elements.
What to look for: Frequent Layout events or long Layout durations indicate costly line-height changes causing reflows.