Performance: Display property
MEDIUM IMPACT
The display property affects how elements are rendered and how much space they take, impacting layout speed and visual stability.
element.style.visibility = 'hidden'; // hides element but keeps space // later element.style.visibility = 'visible'; // shows element
element.style.display = 'none'; // hides element // later element.style.display = 'block'; // shows element
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Changing display from 'none' to 'block' | 1 DOM update | 1 full reflow | 1 repaint | [X] Bad |
| Changing visibility from 'hidden' to 'visible' | 1 DOM update | 0 reflows | 1 repaint | [OK] Good |