CSS - Display
Overview
Quick links: Exercises • Checks • Print as PDF
Estimated time: 12–15 minutes
Display determines how elements participate in layout. Learn common display values and when to use them.
Learning Objectives
- Differentiate block, inline, inline-block, and contents.
- Understand implications on margin/padding and width/height behavior.
Details & Examples
- block: takes full available width; respects width/height, margins stack vertically
- inline: flows with text; width/height ignored
- inline-block: inline flow but respects width/height
- display: contents: element box disappears, children participate in parent layout
.pill { display: inline-block; padding: .25rem .5rem; border: 1px solid var(--border); border-radius: 999px; }
.wrapper { display: contents; }
Try it
Common Pitfalls
- display: contentsremoves the box; some assistive tech support may vary—test carefully.
Checks for Understanding
- Why does heightnot apply todisplay: inlineelements?
Show answers
- Inline elements are sized by line box metrics, not width/height.
Exercises
- Convert an inline badge to an inline-block pill with padding and rounded corners.
- Use display: contentsto flatten a wrapper and verify semantics aren’t harmed (test with accessibility tools).
Suggested answers
- display:inline-block; padding:.25rem .5rem; border-radius:999px;
- Wrap children, apply display: contentsto the wrapper, then test semantics