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 →
Also covered in
What to know first
- viewportA viewport is the visible region of a browser or graphical interface in which a document or other content is displayed.
- CSSCSS (Cascading Style Sheets) is a stylesheet language for specifying the presentation and layout of structured documents.
- flexboxFlexbox is a CSS one-dimensional layout model for arranging, sizing, aligning, and distributing items along a row or column.
- HTMLHTML is the standard markup language for structuring content and elements in documents on the web.
Related concepts
- paddingcontrasts with · Padding is the provision of extra values, characters, bytes, or space around or within data or an element to meet length, boundary, block-size, spacing, or alignment requirements.
- 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 describes each element as a rectangular box composed of content, padding, border, and margin areas that determine its dimensions and surrounding space.
- 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.
Questions about margin property
What is margin property?
The CSS margin property specifies the outer space around an element’s border, separating it from neighboring content.
Which Manning books explain margin property?
Tiny CSS Projects, CSS in Depth, Second Edition, Web Design Playground, Second Edition, Web Design Playground and Build a Website with ChatGPT.
What should I know before learning margin property?
Manning books that teach margin property usually introduce viewport, CSS, flexbox and HTML first.
What is the difference between margin property and padding?
The CSS margin property specifies the outer space around an element’s border, separating it from neighboring content. Padding is the provision of extra values, characters, bytes, or space around or within data or an element to meet length, boundary, block-size, spacing, or alignment requirements.
What is margin property part of?
Margin property is part of CSS box model. The CSS box model describes each element as a rectangular box composed of content, padding, border, and margin areas that determine its dimensions and surrounding space.
What is margin property also called?
Margin property is also called margin shorthand property.
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.




