0
0
Tailwindmarkup~8 mins

Order and self-alignment in Tailwind - Performance & Optimization

Choose your learning style9 modes available
Performance: Order and self-alignment
MEDIUM IMPACT
This affects how quickly the browser can arrange and align flex or grid items during layout and paint.
Reordering and aligning items in a flex or grid container
Tailwind
<div class="flex">
  <div class="self-start">Item 1</div>
  <div class="self-center">Item 2</div>
  <div class="self-end">Item 3</div>
</div>
Avoids changing order property; uses only self-alignment to position items, reducing layout recalculations and visual shifts.
📈 Performance GainSingle reflow, reduced CLS, smoother rendering
Reordering and aligning items in a flex or grid container
Tailwind
<div class="flex">
  <div class="order-3 self-start">Item 1</div>
  <div class="order-1 self-center">Item 2</div>
  <div class="order-2 self-end">Item 3</div>
</div>
Using many different order values and self-alignment properties causes multiple layout recalculations and can trigger layout shifts.
📉 Performance CostTriggers multiple reflows and increases CLS due to layout shifts
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Using many order values with self-alignmentLowMultiple reflows per order changeMedium due to layout shifts[X] Bad
Using only self-alignment without order changesLowSingle reflowLow paint cost[OK] Good
Rendering Pipeline
Order and self-alignment affect the Layout and Paint stages by changing how items are positioned and aligned inside flex or grid containers.
Layout
Paint
Composite
⚠️ BottleneckLayout stage is most expensive because changing order forces recalculation of item positions.
Core Web Vital Affected
CLS
This affects how quickly the browser can arrange and align flex or grid items during layout and paint.
Optimization Tips
1Avoid frequent changes to the order property to reduce layout recalculations.
2Prefer self-alignment properties for positioning items within flex or grid containers.
3Minimize layout shifts by keeping item order stable and using alignment for visual adjustments.
Performance Quiz - 3 Questions
Test your performance knowledge
Which CSS property change is more likely to cause multiple reflows and layout shifts?
AChanging the order property on flex items
BChanging the background color of an item
CChanging the text content inside an item
DChanging the self-alignment property on flex items
DevTools: Performance
How to check: Record a performance profile while interacting with the page. Look for Layout and Recalculate Style events when order or self-alignment changes.
What to look for: Multiple Layout events indicate costly reflows; fewer events mean better performance.