liveBook · Manning

Margin property

As explained in Web Design Playground

A CSS property controlling the outer spacing around an element that separates it from neighboring content.

A margin is space outside an element’s border. Think of it as breathing room: it can keep neighboring elements apart or stop content from brushing against the edge of the browser window. In the CSS box model, the order from inside out is content, padding, border, then margin. section 9.11 section 9.15

You can control each side separately:

  • Use `margin-top` and `margin-bottom` for space above and below an element. section 9.11
  • Use `margin-right` and `margin-left` for space on either side. section 9.11
  • Use a positive value to move elements apart. A negative value can bring them closer or make them overlap. section 9.11
.pullquote {
    margin: 1.5em 2.5em 2em 3em;
}

The single `margin` declaration sets all four sides of this pull quote. Read its values in order: top, right, bottom, left. section 9.11

Give paragraphs room to breathe

Try `p { margin-bottom: 1em; }` to put space beneath each paragraph. Margin values can also use units such as `px` or `rem`, percentages, or `auto`. Browsers supply default margins, so check those before deciding how much space to add. section 9.11

How Web Design Playground covers it

How deep it goes
Defines margin within the box model and demonstrates side-specific values, shorthand, negative values, and browser defaults; defers broader page layout.
Examples
Uses a pull quote with four margin values, paragraph bottom spacing, and separate margins on list and div elements.
What it assumes
Assumes familiarity with page elements and basic CSS rules while explaining margin’s place in the element box.
What you can do after
Operate/configure it with CSS declarations to space elements or create intentional overlap.
How it connects
Connects margin to the CSS box model, padding, borders, and the design principle of proximity.

Also explained in

Compare how 5 books explain margin property →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Design Playground. The section links point to the parts of the book it draws on.