Performance: Flex direction
MEDIUM IMPACT
Flex direction affects how items are laid out in a flex container, impacting layout calculation and paint performance.
const container = document.querySelector('.flex-container'); container.style.flexDirection = 'column'; // set once // Avoid toggling flexDirection repeatedly
const container = document.querySelector('.flex-container'); container.style.flexDirection = 'column'; container.style.flexDirection = 'row';
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Static flex-direction | Minimal DOM changes | 1 reflow on initial layout | Low paint cost | [OK] Good |
| Frequent flex-direction toggling | Multiple style changes | Multiple reflows per toggle | High paint cost | [X] Bad |