CSS Display
display answers a quiet question: how does this box join the page? Some elements stack as full-width blocks; others sit inside a sentence; some can be hidden from layout entirely. This lesson maps the everyday values — and leaves deep inline-block practice for the next session.
A display toolkit
📊 Display at a glance
| Value | Everyday job |
|---|---|
block |
Starts on its own line; often stretches to fill the row |
inline |
Lives in the text line; width/height usually ignored |
inline-block |
Sits in a line like text, but accepts width/height/padding like a box |
none |
Removes the element from layout (space collapses) |
flex / grid |
Powerful layout modes — later lessons, not this one |
Default HTML already picks a display for many tags (div is block, span is inline, button is often inline-block-ish). CSS lets you override that when the flow needs a different job.
Block — own line, roomy box
Block boxes begin on a new line and typically take the available width. Headings, paragraphs, and divs behave this way by default.
Force block
css.badge {
display: block;
width: 12rem;
padding: 0.5rem 0.75rem;
background: #e8f0ff;
}
Inline — inside the sentence
Inline boxes sit in the text flow. They wrap with words. Setting width or height on a pure inline element usually does nothing useful — that is why people reach for block or inline-block.
Force inline
css.note-label {
display: inline;
color: #0b5fff;
font-weight: 600;
}
Inline-block — a short preview
inline-block keeps neighbors on one line when there is room, yet still respects width, height, and padding. You will practice it carefully in the next lesson; here, just recognize the hybrid.
Inline-block glance
css.chip {
display: inline-block;
padding: 0.35rem 0.7rem;
border: 1px solid #c5c5c5;
border-radius: 999px;
}
None — leave the layout
display: none hides the element and collapses its space. Screen readers and layout both treat it as gone. Prefer a class toggle over scattering one-off rules.
Hide with none
css.is-hidden {
display: none;
}
visibility: hidden is a different story — the box can still reserve space. This lesson stays with display: none for true removal from layout. We will not dig into visibility here.
A calm display habit
Change display for flow reasons — not for button cosmetics (previous lesson) and not as a shortcut for every layout problem (flex/grid wait). Name intentional states with classes.
Show and hide classes
css.panel {
display: block;
padding: 1rem;
border: 1px solid #ddd;
}
.panel.is-hidden {
display: none;
}
Compare three modes
css.demo-block { display: block; background: #e8f0ff; margin: 0.25rem 0; }
.demo-inline { display: inline; background: #fff3cd; }
.demo-ib { display: inline-block; width: 6rem; background: #d8f5e7; }
Try it yourself
- Force a
spantodisplay: blockand give it width + padding. - Force a short
div(or heading) todisplay: inlineand watch it sit in a sentence. - Add a
.chipwithinline-block— notice width/padding work. - Hide a panel with
.is-hidden { display: none; }and toggle the class. - Write one sentence: when would you pick block vs inline for a label?
Common mistakes
- Expecting
width/heightto work on pureinlineelements - Using
display: nonewhen you only wanted to mute visuals (and forgetting the space collapses) - Treating this lesson like button hover skins (that was Buttons)
- Dumping Flexbox/Grid recipes here instead of learning the basic four values
- Confusing “hidden from layout” with the deeper
inline-blocklesson next
Summary
displaycontrols how a box joins page flowblocktakes its own line;inlinelives in textinline-blockis the hybrid — practiced nextnoneremoves the element and its space from layout- Change display for flow jobs; leave fancy layouts for later lessons
🧠 Test Your Knowledge
Test Your Knowledge
Challenge yourself with this interactive quiz and see how well you understand the topic
📝 Instructions
- Read each question carefully
- Select the best answer for each question
- You can retake the quiz as many times as you want
- Your progress will be shown at the top