Performance: Block vs inline vs inline-block
This concept affects how elements are sized and laid out, impacting layout calculations and paint performance.
Jump into concepts and practice - no test required
div { display: inline-block; width: 200px; height: 100px; }div { display: inline; width: 200px; height: 100px; }| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Block element for large containers | Moderate (creates block boxes) | 1 per container | Moderate | [OK] Good |
| Inline element with width/height set | Low | Multiple reflows when styles change | Low | [X] Bad |
| Inline-block for sized inline elements | Moderate | Single reflow | Low | [OK] Good |
inline-block with a hyphen.display: block; sets block, not inline-block. block-inline and inlineblock are invalid.<div class='box'>Box 1</div>
<div class='box'>Box 2</div>
<style>
.box { display: inline-block; width: 100px; height: 50px; background: lightblue; margin: 5px; }
</style><button class='btn'>One</button>
<button class='btn'>Two</button>
<button class='btn'>Three</button>
<style>
.btn { display: inline; width: 100px; height: 40px; }
</style>display: inline causes buttons to ignore width and height, so they don't size as expected.display: inline ignores width and height properties. -> Option B