CSS box model 2026-11-05
The CSS box model describes the content, padding, border and margin regions used to lay out generated boxes. These define a CSS content box, CSS padding box, CSS border box and CSS margin box respectively. A box's declared width must be interpreted together with the applicable sizing rules.[ref]
For a simple horizontal box with content width , left/right padding , border widths and margins , the total margin-box width is
With , padding ten on each side, borders two on each side and margins ten on each side, the total is 144 CSS pixels. Its border box is 124 pixels wide.
CSS box-sizing changes which area a width declaration sizes. With the same padding and borders but box-sizing: border-box; width: 100px, the border box is 100 pixels and the content width is 76 pixels in this example. Margins are still outside that declared border-box size.[ref]
The example assumes ordinary nonnegative fixed horizontal values. Vertical margins can participate in CSS margin collapsing, and an inline element split across lines can generate several fragments. The box model supplies the regions; the formatting context determines how particular boxes are generated and positioned.
CSS content box 2026-11-05
The CSS content box is the innermost box region bounded by the content edges, inside padding, border and margins. It is the area assigned for the box's content by the applicable layout rules.[ref]
Suppose the content width is CSS pixels, with eight-pixel left/right padding and two-pixel left/right borders. Then the CSS padding box width is and the CSS border box width is pixels. Six-pixel margins on both sides increase the CSS margin box width to pixels. These are different measurements of the same simple box, not competing answers to one unspecified width question.
With box-sizing: content-box; width: 120px, the declared width requests that content dimension. With box-sizing: border-box; width: 120px and the same padding and borders, the requested border dimension instead leaves pixels for content, before any further constraints.
A content area is not a guarantee that all painted content fits inside it. A long unbroken item or a descendant can cause CSS overflow. Also, an ordinary inline element can fragment across CSS line boxes; its geometry should not be reduced to one fixed-width rectangle merely because a width declaration appears in its style. Read the content region together with CSS box-sizing, box kind and the layout context.
CSS padding box 2026-11-05
The CSS padding box is the rectangle enclosed by the outer padding edges. It contains the CSS content box and padding, but excludes the border and margins.[ref]
For content dimensions by CSS pixels and eight-pixel padding on all sides, the padding dimensions are
A further two-pixel border on each side makes the CSS border box by pixels. Padding is thus space inside the border rather than an external gap between neighboring boxes.
This distinction explains a common design change. Increasing padding while keeping a fixed content width enlarges the outer box. Increasing padding inside a fixed border-box width instead leaves less room for content, subject to the zero floor and other sizing constraints of CSS box-sizing. The same padding declaration can therefore have different consequences for text wrapping depending on the sizing edge.
The CSS padding box can also serve as a reference in particular layout rules, such as some cases of CSS absolute positioning. Use the applicable rule rather than assuming all geometric references mean the CSS content box. Padding geometry alone likewise does not define every painted or interactive boundary; those depend on their own properties and behavior.
CSS scrollport 2026-11-05
A CSS scrollport is the viewing region through which a CSS scroll container's scrollable contents are seen. The overflow specification identifies it with the container's padding box. A CSS scroll position determines the alignment of the larger contents within this region.[ref]
Consider a stipulated two-dimensional example with a -by--pixel viewing region and contents occupying a -by--pixel rectangle. Use left-to-right horizontal coordinates, a top-left origin and no scrollbar-size complication. At scroll offset , the visible content rectangle is
The largest offsets that align its far edges with the contents' far edges are in this geometry. These coordinates describe a viewing alignment, not a change in the content's dimensions.
Box edges matter too. A box with content dimensions by CSS pixels and ten-pixel padding on every side has a -by- CSS padding box. Two-pixel borders then give a -by- CSS border box. Under the stated scrolling assumptions, the border dimensions are not the scrollport dimensions.
The scrollport is also distinct from the page's layout viewport. A small scrolling panel can have its own viewing region inside a larger page. Descendant DOM nodes remain in the document when their rendered contents lie outside that panel's current view.
Writing direction, layout alignment and scrolling APIs can affect origins and offset conventions. State those conventions before interpreting a number as a distance from the upper-left corner. The rectangle example supplies explicit conventions rather than imposing them on every possible CSS scroll container.