Performance: Border width utilities
Border width utilities affect the paint and layout stages by changing element borders, impacting rendering speed and visual stability.
Jump into concepts and practice - no test required
<div class="border-2"></div> <div class="border-4"></div> <div class="border-8"></div>
<div class="border-[3px]"></div> <div class="border-[5px]"></div> <div class="border-[7px]"></div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Arbitrary border widths (e.g., border-[3px], border-[5px]) | Low | Multiple reflows if layout changes | High paint cost due to unique styles | [X] Bad |
| Predefined Tailwind border utilities (e.g., border-2, border-4) | Low | Single reflow if layout changes | Lower paint cost due to reused styles | [OK] Good |
border-{size} to set border width on all sides.border-4 sets border width to 4 pixels on all sides.border-{side}-{width} with short side names: t (top), r (right), b (bottom), l (left).border-t-2 correctly sets top border width to 2 pixels.<div class="border-l-8 border-r-2 border-t border-b-0 border-black border-solid">Content</div>border-l-8 sets left border 8px, border-r-2 right border 2px, border-t defaults to 1px, border-b-0 bottom border 0px.border-black and border-solid ensure border is visible with black solid lines.<div class="border-t-3 border-b-5 border-black">Box</div> but the top border does not appear. What is the likely problem?border-solid, borders won't show.border-black sets color, so color is not the issue here.border-style like border-solid to see borders -> Option Cborder-b-1 for 1px bottom border by default (small screens). Then md:border-b-4 for medium screens, lg:border-b-8 for large screens.border-b border-b-1 md:border-b-4 lg:border-b-8 correctly uses border-b-1 (default), md:border-b-4, and lg:border-b-8. The border-b class alone sets 1px but is redundant with border-b-1.