Performance: Display property
The display property affects how elements are rendered and how much space they take, impacting layout speed and visual stability.
Jump into concepts and practice - no test required
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 |
display: none; property do to an element on a webpage?display: none;visibility: hidden; which hides but keeps space, display: none; removes the element entirely.display: none; = hidden and no space [OK]: to assign values, not equals =.display and the value to create a flex container is flex.display: flex; [OK]<div class='container'>
<span>A</span>
<span>B</span>
<span>C</span>
</div>
.container {
display: flex;
flex-direction: column;
}display: flex; with flex-direction: column;flex-direction: column; stacks vertically [OK]p {
display: none;
}display: none; and visibility: hidden;display: none; removes element and space, visibility: hidden; hides element but keeps space.visibility: hidden; to hide content but preserve layout space.display: none; to visibility: hidden; -> Option Bvisibility: hidden; [OK]display: flex; on container creates a flexible row layout. justify-content: space-around; spaces items evenly with space around them.display: flex; on the container with justify-content: space-around;. -> Option A