Skip to content
Learn Netverks

Lesson

Step 12/134 9% through track

core-css-margins

CSS Margins

Last reviewed May 28, 2026 Content v20260528
Track mode
iframe_html
Means
HTML preview sandbox
Reading
~1 min
Level
advanced

This lesson

This lesson teaches CSS Margins—the ideas, syntax, and habits you need before moving on in CSS.

Without a solid grasp of CSS Margins, you will repeat mistakes in CSS exercises and on real pages or scripts.

You will apply CSS Margins in contexts like: All browser UIs, component libraries, marketing sites, and many native apps that reuse web views.

Read the lesson, edit HTML/CSS in the playground, press Run to preview, then answer the lesson MCQs.

When intermediate lessons feel comfortable and you are ready for production-style trade-offs.

Margins create space outside an element. They are useful but can become unpredictable with collapse and mixed conventions.

Key behaviors

  • Vertical margins between block elements can collapse.
  • margin: 0 auto centers fixed-width blocks horizontally.
  • Negative margins are advanced and easy to misuse.

Pitfall

Mixing arbitrary margins across components creates spacing debt. Prefer spacing scales and layout wrappers.

Important interview questions and answers

  1. Q: What is margin collapsing?
    A: Adjacent vertical margins merge into one margin equal to the larger value.
  2. Q: Why avoid negative margins casually?
    A: They can cause overlap bugs and fragile responsive behavior.
  3. Q: Better alternative for list spacing?
    A: Use parent stack/gap patterns when possible.

Pitfall: Check cascade order—author stylesheet loses to inline styles and !important surprises.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs in your browser in a sandboxed frame. Backend runners appear when this track’s profile allows them.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • What part of this lesson needs a second read?
  • What would you try differently in a real project?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump