Module 4 · Layout · Lesson 1 of 5

CSS Display & Visibility

Intermediate ⏱ 15 min2 sections · 1 exercise · 4-question quiz

Before Flexbox and Grid comes the property that decides what kind of box an element even is. block, inline, inline-block, none — the display value is the first question of every layout.

1. The three classic values

ValueBehaviorWidth/height respected?
blockFull line, stacks vertically (div, p, h1)Yes
inlineFlows within text (span, a, strong)No — and no vertical margins
inline-blockFlows inline, but accepts box sizingYes

The classic trap: trying to size a span or add vertical padding to a link and watching nothing happen — inline elements ignore those. Switch to inline-block (or make the parent a flex container) and the box model returns.

2. Hiding: none vs hidden

CSS — two ways to disappear
modal   { display: none; }        /* gone: takes no space */
.ghost   { visibility: hidden; }    /* invisible: space kept */
.faded   { opacity: 0; }            /* invisible but interactive! */

display: none removes the element from layout entirely. visibility: hidden leaves its gap behind. opacity: 0 is purely visual — the element still receives clicks, which is a real bug source. Choose deliberately.

3. Try it yourself

The badge (a span) ignores its padding. Make it inline-block so the box model applies, then hide the second card completely with display: none.

exercise.html — editable

4. Quiz — check your understanding

CSS Display & Visibility Quiz

4 questions · pass at 60%

Q1. Which display value ignores width, height and vertical margins?

Inline boxes flow with text and reject box-model sizing.

Q2. You need a link to accept padding while flowing in a sentence. Use…

inline-block keeps text flow but restores width, height and padding.

Q3. Which hides an element but preserves its space?

visibility: hidden keeps the element's box in the layout, just invisible.

Q4. Why is opacity: 0 risky for hiding interactive elements?

Fully transparent elements remain in the layout and stay clickable/focusable.
🏆
Quiz passed? You're one step closer to your certificate.

Every lesson quiz you pass (60%+) is saved in your browser and counts toward the CSSmatic Certificate of Completion.

Track my progress →