GO-Ve01
ServicesDevelopersBooksDictionaryPapersWikidataEncyclopediaSearchBabelCareersDeck

CSS box model

The CSS box model module defines the margin and padding properties, which along with the height, width and border properties, make up the CSS box model.

The **CSS box model** module defines the `margin` and `padding` properties, which along with the [height](/docs/Web/CSS/Guides/Box_sizing), [width](/docs/Web/CSS/Guides/Box_sizing) and [border properties](/docs/Web/CSS/Guides/Backgrounds_and_borders), make up the CSS [box model](/docs/Web/CSS/Guides/Box_model/Introduction).

Every visible element on a webpage is a box laid out according to the [visual formatting model](/docs/Web/CSS/Guides/Display/Visual_formatting_model). CSS properties define their size, position, and stacking level, with the box model properties (and others) defining the extrinsic size of each box, and the space around them.

Each box has a rectangular content area, inside which any text, images, and other content is displayed. The content may be surrounded by padding, a border, and a margin, on one or more sides. The padding is around the content, the border is around the padding, and the margin sits outside the border. The box model describes how these features — the content, padding, border, and margin — work together to create a box as displayed by CSS.

![The components of the CSS box model](boxmodel.png)

The CSS box model module defines physical (or "page relative") properties such as `margin-top` and `padding-top`. Flow-relative properties such as `margin-block-start` and `margin-inline-start` (which relate to text direction) are defined in [Logical Properties and Values](/docs/Web/CSS/Guides/Logical_properties_and_values). The box model module is extended by the [CSS box sizing module](/docs/Web/CSS/Guides/Box_sizing), which introduces the intrinsic size value and enables defining aspect ratio for elements that are auto-sized in at least one dimension.

## Reference

### Properties

- margin shorthand
- margin-bottom
- margin-left
- margin-right
- margin-top
- margin-trim
- padding shorthand
- padding-bottom
- padding-left
- padding-right
- padding-top

### Data types

- box-edge
- [`<visual-box>`](/docs/Web/CSS/Reference/Values/box-edge#visual-box)
- [`<layout-box>`](/docs/Web/CSS/Reference/Values/box-edge#layout-box)
- [`<paint-box>`](/docs/Web/CSS/Reference/Values/box-edge#paint-box)
- [`<coord-box>`](/docs/Web/CSS/Reference/Values/box-edge#coord-box)
- [`<geometry-box>`](/docs/Web/CSS/Reference/Values/box-edge#geometry-box)

## Guides

- [Introduction to the CSS box model](/docs/Web/CSS/Guides/Box_model/Introduction)
- : Explains one of the fundamental concepts of CSS: the box model. This model defines how CSS lays out elements, including their content, padding, border, and margin areas.

- [Mastering margin collapsing](/docs/Web/CSS/Guides/Box_model/Margin_collapsing)
- : Sometimes, two adjacent margins are collapsed into one. This article describes the rules that govern when and why this happens, and how to control it.

- [Visual formatting model](/docs/Web/CSS/Guides/Display/Visual_formatting_model)
- : Explains the visual formatting model.

## Related concepts

- [CSS backgrounds and borders](/docs/Web/CSS/Guides/Backgrounds_and_borders) module
- border-width shorthand
- border-bottom-width
- border-left-width
- border-right-width
- border-top-width
- [CSS logical properties](/docs/Web/CSS/Guides/Logical_properties_and_values) module
- block-size
- inline-size
- max-block-size
- max-inline-size
- min-block-size
- min-inline-size
- margin-block
- margin-block-end
- margin-block-start
- margin-inline
- margin-inline-end
- margin-inline-start
- padding-block
- padding-block-end
- padding-block-start
- padding-inline
- padding-inline-end
- padding-inline-start
- border-block
- border-block-end
- border-block-end-width
- border-block-start
- border-block-start-width
- border-block-style
- border-block-width
- border-inline
- border-inline-end
- border-inline-end-width
- border-inline-start
- border-inline-start-width
- border-inline-width
- [CSS box sizing](/docs/Web/CSS/Guides/Box_sizing) module
- aspect-ratio
- box-sizing
- contain-intrinsic-block-size
- contain-intrinsic-height
- contain-intrinsic-inline-size
- contain-intrinsic-size
- contain-intrinsic-width
- height
- max-height
- max-width
- min-height
- min-width
- width
- [CSS overflow](/docs/Web/CSS/Guides/Overflow) module
- overflow shorthand
- overflow-block
- overflow-clip-margin
- overflow-inline
- overflow-x
- overflow-y
- text-overflow

## Specifications

## See also

- [CSS display](/docs/Web/CSS/Guides/Display) module
- [CSS flex layout](/docs/Web/CSS/Guides/Flexible_box_layout) module
- [CSS grid layout](/docs/Web/CSS/Guides/Grid_layout) module
- [CSS table](/docs/Web/CSS/Guides/Table) module
- [CSS positioned layout](/docs/Web/CSS/Guides/Positioned_layout) module
- [CSS fragmentation](/docs/Web/CSS/Guides/Fragmentation) module
- [Understanding aspect ratios](/docs/Web/CSS/Guides/Box_sizing/Aspect_ratios)

source: MDN Web Docs mirror · page

Cite this

"CSS box model". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Box_model

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·