CSS Essentials·CSS without guesswork

Normal flow and display

Learn how block and inline elements flow by default and how the display property changes that layout.

Beginner 10 min read Lesson 4 of 480 Challenge included
What you will be able to do
  • Tell block from inline elements and how each behaves in document flow.
  • Use inline-block to get inline flow with a settable width and height.
  • Use display: none to remove an element from the layout entirely.
  • Explain why a layout collapses when block and inline are confused.

In plain English

Every element on a page sits in a stream called document flow, a bit like words in a sentence. Block elements such as paragraphs and divs stack vertically and stretch the full width, while inline elements such as links and spans sit side by side and only take the space they need. The display property tells the browser which of these behaviours to use, and display: none removes an element from the flow entirely. Understanding flow is the key to knowing why a layout breaks before you reach for a hack.

Step by step

  1. 1Open a small page that has a paragraph, a link and a span.
  2. 2Look in the browser and note which elements stack and which sit inline.
  3. 3Give the span display: inline-block and add a width to see it take shape.
  4. 4Set display: none on one element and confirm it leaves no space behind.
normal-flow.cssCSS
p {
  display: block;
}

a {
  display: inline;
}

.badge {
  display: inline-block;
  width: 6rem;
}

.hidden {
  display: none;
}

Common mistakes

  • Beginners often give width and height to an inline element and are surprised when nothing changes.
  • A common error is expecting two divs to sit side by side just because there is room for them.
  • Some people use display: none to hide an element and then forget it is gone from the layout, not just invisible.
  • Mixing up inline-block and inline is easy when an element will not accept padding the way you expect.
Your turn

Lay out a badge row

Easy

Style a set of badges so they sit side by side but can still have a set width and height.

CSS · starter
.badge {
  width: 6rem;
}
Check your understanding before moving on.
Knowledge checkQuestion 1

Which display value removes an element from the layout completely, so it takes no space?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Next: Spacing and sizing
Lesson 4 of 480 · 0% of course