Performance: Width utilities
Width utilities affect layout calculation and paint times by changing element sizes, impacting page rendering speed and visual stability.
Jump into concepts and practice - no test required
<div class="max-w-full md:max-w-96"></div><div class="w-full md:w-96"></div>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Fixed width changes on breakpoint (w-96) | Low | Triggers reflow on resize | Medium | [!] OK |
| Using max-width utilities (max-w-full, max-w-96) | Low | Minimal reflows | Low | [OK] Good |
| Using inline styles with JS to set width repeatedly | High | Multiple reflows | High | [X] Bad |
w-fullw-full sets the width to 100% of the parent container.w-auto lets width adjust to content, w-1/2 sets width to 50%, and w-0 sets width to zero.w-full -> Option Aw-full [OK]w-full class [OK]w-auto with full widthw-1/2 means full widthw-0 expecting full widthw-1/4 means width is 1/4 or 25% of the parent container.w-1/3 is about 33%, w-1/2 is 50%, and w-3/4 is 75% width.w-1/4 -> Option Aw-1/4 [OK]w-1/4, w-1/2, etc. [OK]w-1/3 with 25%w-3/4 expecting 25%<div class="w-3/5">Content</div>
w-3/5w-1/2, 75% is w-3/4, and 100% is w-full.w-3/5 = 60% width [OK]w-3/5 means 3%w-1/2<div class="w-7/3">Box</div>
7/3 in Tailwind widthw-7/3 is invalid.<div class="?">Box</div>
md: prefix applies styles at medium screen sizes and above.w-full for small screens and md:w-1/3 for medium+ screens.w-full md:w-1/3 -> Option Bw-full md:w-1/3 [OK]md: for screen size changes [OK]w-auto instead of fixed width