Performance: Importance of order
MEDIUM IMPACT
The order of CSS rules affects how quickly the browser applies styles and can impact layout stability and rendering speed.
/* CSS with ordered rules to avoid overrides and recalculations */ .container { display: block; } .container { display: flex; } .button { color: blue; } .button { color: red; font-weight: bold; }
/* CSS with unordered rules causing overrides and recalculations */ .button { color: blue; } .button { color: red; font-weight: bold; } .container { display: flex; } .container { display: block; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Unordered CSS rules with frequent overrides | Multiple style recalculations | Multiple reflows triggered | Higher paint cost due to layout shifts | [X] Bad |
| Ordered CSS rules minimizing overrides | Single style recalculation | Minimal reflows | Lower paint cost with stable layout | [OK] Good |