Performance: Space between children (space-x, space-y)
This affects the browser's layout and paint performance by adding consistent spacing between child elements without extra wrappers or margin hacks.
Jump into concepts and practice - no test required
<div class="flex space-x-4"> <div>Item 1</div> <div>Item 2</div> <div>Item 3</div> </div>
<div class="flex"> <div class="mr-4">Item 1</div> <div class="mr-4">Item 2</div> <div>Item 3</div> </div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual margin on children | Multiple margin style changes | Triggers multiple reflows (one per child) | Higher paint cost due to layout thrashing | [X] Bad |
| Tailwind space-x/space-y (sibling selectors) | Single container style change | Single reflow for container | Lower paint cost, smoother rendering | [OK] Good |
space-x-4 do when applied to a container with multiple child elements?space-x classspace-x class adds horizontal space between child elements inside a container.44 corresponds to 1rem (16px) spacing.space-x-4 = horizontal 1rem space [OK]space-y classes.2 equals 0.5rem spacing.<div class="flex space-x-6"> <button>One</button> <button>Two</button> <button>Three</button> </div>
space-x-6space-x-6 class adds horizontal space between children.6 equals 1.5rem. Since 1rem = 16px, 1.5rem = 24px.space-x-4 on a vertical stack. What will happen?space-x-4 effectspace-x-4 adds horizontal space between children, not vertical.4 and 0.5rem corresponds to 2 in Tailwind spacing scale.space-x-4, vertical space between rows uses space-y-2.