Margin property
The CSS margin property specifies the outer space around an element’s border, separating it from neighboring content.
Tiny CSS Projects
A CSS property that sets the space outside an element's border on each side.
- How it is used
- Spaces interface elements, centers width-limited layouts, and adjusts card content across screen sizes.
- How deep it goes
- Works through side-specific and shorthand values, auto centering, negative margins, browser defaults, and margin collapse in concrete layouts.
- Examples
- Uses a centered newspaper, checkout cards, form controls, and a profile image protruding above its card.
- What you can do after
- Apply it via CSS to control outer gaps, center constrained content, and correct spacing failures caused by defaults or collapsing margins.
CSS in Depth, Second Edition
The CSS margin property sets the outer spacing around an element, with physical sides including top, bottom, left, and right margins.
- How it is used
- Uses margins to center constrained columns and control outside spacing in page layouts.
- How deep it goes
- Explains auto margins, shorthand order, spacing trade-offs, and line-height effects, while only briefly noting margin collapse.
- Examples
- Works through a centered content column, hero-image spacing, navigation gaps, and heading-to-paragraph spacing.
- What you can do after
- Apply it via CSS to center a constrained block and choose outside spacing without mistaking visible text gaps for margin values.
Read how CSS in Depth, Second Edition explains margin property →
Web Design Playground, Second Edition
The CSS margin property specifies the space outside an element's border.
- How it is used
- Controls spacing between elements, text blocks, and viewport edges within the CSS box model.
- How deep it goes
- Explains the box-model role, side properties, units, negative values, shorthand order, defaults, and resets.
- Examples
- Uses paragraph spacing, a pull quote, navigation lists, surrounding content, and a four-sided shorthand declaration.
- What you can do after
- Apply margin declarations and shorthand to create spacing, separation, intentional overlap, and responsive layouts.
Read how Web Design Playground, Second Edition explains margin property →
Web Design Playground
A CSS property controlling the outer spacing around an element that separates it from neighboring content.
- How it is used
- Controls the space between page elements to help group related items and separate unrelated ones.
- 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 you can do after
- Operate/configure it with CSS declarations to space elements or create intentional overlap.
Build a Website with ChatGPT
A margin property specifies the outer space surrounding an element's border.
- How it is used
- Controls spacing between page elements and the browser viewport.
- How deep it goes
- Defines side-specific and shorthand declarations, including positive spacing and negative overlap.
- Examples
- Uses a footer with four distinct margins and an equivalent shorthand declaration.
- What you can do after
- Apply spacing through CSS side properties, shorthand declarations, and adjusted pixel values.
Read how Build a Website with ChatGPT explains margin property →
Related concepts
- paddingcontrasts with · Padding is the addition or insertion of extra space, values, or data into or around a structure or input to meet a specified size, boundary, alignment, or processing requirement.
- collapsing marginused by · Collapsing margin is CSS behavior in which adjoining vertical margins combine into a single effective margin rather than being added together.
- CSS box modelpart of · The CSS box model represents each element as a rectangular box comprising content, padding, border, and margin areas.
- user-agent styleconfigured by · A user-agent style is a default set of presentation rules supplied by a browser for rendering document elements when author styles do not override them.
- element boxpart of · An element box is the rectangular CSS layout representation of an element, including its content, padding, border, and margin areas.
- autoconfigured by · auto is a CSS keyword whose value is determined by the relevant property’s rules, layout algorithm, available space, and content.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.




