SystemTutor
About
Sign in
Loading course documentation…
SystemTutor

COURSES

  • Data Structures & Algorithms
  • CSS MasterclassNew course
  • System DesignNew course

PRACTICE

  • Algorithm practice
  • CSS practice

LEGAL

  • Privacy Policy
  • Terms of Service
  • About

© 2026 SystemTutor. All rights reserved.

Built with 🫶 by Shatlyk

Welcome to CSS
The Box Model and SizingWriting Modes and Logical PropertiesSizing ElementsBorders and ShadowsDisplay and Document FlowNormal FlowFloats and ColumnsPositioning and StackingStacking and Z-Index Measuring boxes and predicting their positions
Box Model and Flow

Normal Flow

Understand how elements occupy space in normal flow.

Normal flow is the browser’s default layout. Block elements stack one after another, while text and inline elements share lines.

The examples here use horizontal writing, with text read from left to right.

Follow the document order

.notes {
  max-width: 36rem;
  padding: 1rem;
  border: 1px solid green;
}

With the browser's usual display styles:

  • Block boxes: The heading and paragraphs stack vertically in their document order.
  • Inline boxes: Text, strong, and the link share lines inside those blocks.
  • Line wrapping: When a line runs out of width, text continues on the next line.

The layout follows the content's structure. You do not need to give each paragraph a coordinate.

Let content determine height

The section has no set height, so it grows with its content. If its available width shrinks, the paragraphs wrap onto more lines and become taller. Later blocks move downward to make room.

This is a useful default for articles and cards with variable text. Test the example with a longer heading or another paragraph before deciding that the section needs a fixed height.

Understand the containing block

A containing block is the box CSS uses to calculate sizes and positions. Here, the paragraphs use the parent section’s content area as their reference.

.notes p {
  width: 50%;
}

With a 16-pixel root font size, the section’s maximum content width of 36rem is 576 pixels. At that width each paragraph measures 288 pixels across. Narrow the section to 400 pixels of content width and each paragraph measures 200 pixels. They still stack: making blocks narrower does not automatically place them side by side.

Positioning can change which ancestor supplies this reference. The Positioning and Stacking lesson traces the reference for a label anchored to a card.

Recognize collapsing margins

In a separate example, use two adjacent paragraphs in ordinary block flow:

.first-note {
  margin: 0 0 24px;
}

.second-note {
  margin: 16px 0 0;
}

Their adjoining vertical margins collapse into one margin. Because both are positive, the gap is 24 pixels, the larger value, rather than 40 pixels.

Margin collapse has boundaries and conditions:

  • Horizontal margins do not collapse.
  • Padding and borders do not collapse.
  • A parent’s top or bottom margin can combine with its first or last child’s margin when nothing separates them, such as a border or padding.
  • Margins between flex or grid items do not collapse.

The first paragraph has 24px below it and the second has 16px above it. The gap between them measures 24px in ordinary block flow and 40px when they are flex items in a column.

If the section has a top border or top padding, its first child's top margin cannot collapse through that edge.

When collapsing margins include negative values, combine the largest positive value with the most negative value. If the second paragraph's top margin changes from 16px to -8px, the collapsed margin becomes 24px - 8px = 16px. If all the collapsing margins are negative, use the most negative value: -24px and -8px collapse to -24px.

Notice when content leaves normal flow

Absolute and fixed positioning remove a box from normal flow: its former place is not reserved for neighboring content. Relative positioning keeps the original space even when the box is visually offset. Floats allow surrounding inline content to wrap around them.

Those behaviors solve particular layout problems. Begin with normal flow, then choose another behavior when the content needs it.

Key Takeaways

  • Normal flow: Blocks stack in document order while inline content forms wrapping lines.
  • Content height: In-flow content can expand an automatically sized parent and move later content.
  • Containing block: Reference dimensions determine how values such as percentage widths resolve.
  • Margin collapse: Adjoining vertical margins can combine instead of adding together.
  • Placement: A narrower block does not automatically move beside another block.

Try it yourself

Try it yourself

Space two notes in normal flow

HTML + CSS

Loading code editor…

Live preview

Updating…

Final output

No comparison yetChecks after 3s without edits
Loading your draft…

How is this lesson?

Previous lessonDisplay and Document FlowNext lessonFloats and Columns
Edit on GitHubReport on GitHub
On this page
%

On this page

Follow the document orderLet content determine heightUnderstand the containing blockRecognize collapsing marginsNotice when content leaves normal flowKey TakeawaysTry it yourself