CSS box model
The CSS box model module defines the height
, width
, margin
, and padding
properties, which along with border properties make up the CSS box model.
Every visible element on a webpage is a box laid out according to the 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 CSS box model module defines physical (or "page relative") properties such as width
and margin-top
. Flow-relative properties such as inline-size
and margin-block-start
(which relate to text direction) are defined in Logical Properties and Values. The box model module is extended by the CSS box sizing module, which introduces the intrinsic size value and enables defining aspect ratios for elements that are auto-sized in at least one dimension.
Reference
Properties
Data types
Guides
- Introduction to the CSS box model
-
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
-
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
-
Explains the visual formatting model.
Related concepts
- CSS backgrounds and borders module
- CSS logical properties 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 module
- CSS overflow module
Specifications
Specification |
---|
CSS Box Model Module Level 4 |
CSS Box Model Module Level 3 |
See also
- CSS display module
- CSS flex layout module
- CSS grid layout module
- CSS table module
- CSS positioned layout module
- CSS fragmentation module
- Understanding aspect ratios