CSS basics: Spacing with margin
Margin creates space outside an element. Block margins can collapse in normal flow.
Current edit
Understand the pattern
Margin creates space outside an element. Block margins can collapse in normal flow.
Margin creates space outside an element. Block margins can collapse in normal flow.
Misconceptions to reject
- If the page fits one desktop viewport, no narrower viewport needs checking.
- Hiding all overflow always makes content accessible.
The preview is a sanitized subset, not a full browser compatibility test.
Worked example and expected result
h1 { margin: 0; }
p { margin-top: 1rem; }
p { margin-bottom: 1.5rem; }Margin creates space outside an element. Block margins can collapse in normal flow.
Explain it
Apply it elsewhere
Keep the momentum.
Complete the lab, then explain and apply the pattern.
Next: CSS basics: BordersTry an incident drillAnonymous lesson and mastery progress lasts for this session. Sign in to keep synced lesson XP between sessions; mastery stays device-local. No speed bonus, lost lives, or hint penalties.
Keep learning
- 01CSS basics: Spacing with paddingPadding creates space inside the border; it does not separate the element from its neighbors.Practice
- 02CSS basics: BordersA visible border needs a style as well as a width and color; it participates in box sizing.Practice
- 03CSS basics: Background surfacesA background should keep foreground content readable rather than carry meaning alone.Practice