Performance: Flex direction control
Controls how flex items are laid out, affecting layout calculation and paint performance.
<div id="container" class="flex flex-col">...</div> <script> const container = document.getElementById('container'); container.classList.replace('flex-col', 'flex-row'); </script>
<div class="flex flex-col">...</div> <script> document.querySelectorAll('.flex').forEach(el => { el.classList.remove('flex-col'); el.classList.add('flex-row'); }); </script>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Changing flex direction on many elements individually | Many class changes | N reflows for N elements | High paint cost | [X] Bad |
| Changing flex direction on a single container | One class change | Single reflow | Low paint cost | [OK] Good |
flex-row arranges items horizontally from left to right.flex-col stacks vertically, and -reverse variants reverse order.flex-col stacks items vertically top to bottom.flex-col-reverse reverses vertical order, stacking bottom to top.flex-row-reverse on a flex container with items A, B, C?flex-row-reverse arranges items horizontally but reverses order.<div class="flex flex-col-reverse"> <div>Item 1</div> <div>Item 2</div> <div>Item 3</div> </div>
flex-col-reverse stacks items vertically but reverses order from bottom to top.flex-col or its reverse.flex-col-reverse which reverses vertical order.Pass the test and this pattern moves unknown