Performance: Align items (cross axis)
This affects the browser's layout and paint phases by controlling how flex items align along the cross axis, impacting reflows and paint costs.
<div class="flex items-center"> <div>Item 1</div> <div>Item 2</div> </div>
<div class="flex" style="align-items: center;"> <div>Item 1</div> <div>Item 2</div> </div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Inline style align-items | Minimal | 1 per container | Medium | [X] Bad |
| Tailwind items-center utility | Minimal | 1 per container | Low | [OK] Good |
items-center do in a flex container?items-center doesitems-center centers items along the cross axis, so vertically center in a row.items-start aligns at the top/start, items-end aligns at the bottom/end, items-center centers, items-stretch stretches.items-end.<div class="flex items-start h-32 bg-gray-100"> <div class="w-16 h-16 bg-blue-500"></div> <div class="w-16 h-16 bg-red-500"></div> </div>What will be the vertical alignment of the blue and red boxes inside the container?
flex and items-start. items-start aligns items at the start of the cross axis (top for row).items-center instead of the correct class. What is the problem?items-center effectitems-center centers items on the cross axis, so they keep their height and align in the middle.items-stretchitems-stretch makes items fill the container height, stretching them vertically.flex-col and want to align items horizontally centered. Which Tailwind class should you use?flex-col, the main axis is vertical, so the cross axis is horizontal.items-center aligns items centered on the cross axis, so horizontally centered in this case.Pass the test and this pattern moves unknown