Performance: Height utilities
Height utilities affect the layout and paint phases by changing element dimensions, impacting rendering speed and visual stability.
Jump into concepts and practice - no test required
<div class="h-[calc(100vh-50px)]"></div><div style="height: calc(100vh - 50px);"></div>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Inline style with calc() | Low | Multiple on resize | Medium | [X] Bad |
| Tailwind arbitrary height utility | Low | Single on load | Low | [!] OK |
| Tailwind predefined height utility | Low | Single on load | Low | [OK] Good |
| Inline media queries for height | Low | Multiple on resize | Medium | [X] Bad |
| Tailwind responsive height utilities | Low | Single on resize | Low | [OK] Good |
h-16 do to an element?h-16 sets height using a spacing scale where 16 equals 4rem.min-h- prefix for minimum height utilities.full means 100% of the parent size, so min-h-full sets min-height to 100%.<div class="max-h-24 overflow-auto">Content</div>
max-h-24 sets maximum height to 6rem (24 x 0.25rem).overflow-auto adds a scrollbar inside the div.h-20 and the height is too large. What is the mistake?h-20 means height of 5rem (20 x 0.25rem = 5rem), so this matches the desired height.h-20 is 5rem, so if height is too large, the user might have used a custom scale or misunderstood the unit.h-20 sets height to 20rem, which is too large -> Option Dh-32 sets height 8rem. 12rem = 48 x 0.25rem, so max-h-48 sets max height 12rem.h-32. On medium screens and above, max height 12rem with scroll means md:max-h-48 md:overflow-auto.