CSS box sizing
The CSS box sizing module enables you to specify how elements fit their content or fit into a particular layout context. It defines sizing, minimum sizing, and maximum sizing properties, and also extends the CSS sizing properties with keywords that represent content-based intrinsic size and context-based extrinsic size.
Elements can either be extrinsically or intrinsically sized. The CSS box model defines page-relative properties to explicitly, or "extrinsically" set an element's size, including width, height, padding, and margin properties (along with border properties defined in the CSS backgrounds and borders module). This CSS box sizing module extends the CSS box model module to enable an element to be sized intrinsically — setting element size based on the size of its content.
The sizing values introduced in this module allow elements with size containment to take explicit intrinsic sizes, as if their in-flow content's width and height match the specified explicit intrinsic size, rather than being sized as if they were empty.
This module also introduced the ability to define an aspect ratio for an element's box, meaning the browser can automatically adjust an element's dimensions to maintain a specified aspect ratio as long as one of the dimensions is automatically sized.
The logical properties and values module expanded the properties available in the box model and box sizing modules to include writing-mode-relative equivalents of the corresponding physical box model and intrinsic box sizing properties.
Reference
>Properties
aspect-ratiobox-sizingcontain-intrinsic-block-sizecontain-intrinsic-heightcontain-intrinsic-inline-sizecontain-intrinsic-sizecontain-intrinsic-widthheightmax-heightmax-widthmin-heightmin-widthwidth
The CSS box sizing module also introduces the min-intrinsic-sizing property. Currently, no browsers support this feature.
Data types and values
<ratio>data typemin-contentvaluemax-contentvaluefit-contentvalue
Functions
Glossary terms
Guides
- Understanding aspect ratios
-
Learn about the
aspect-ratioproperty, discuss aspect ratios for replaced and non-replaced elements, and examine some common aspect ratio use cases. - 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.
- Controlling ratios of flex items along the main axis
-
Explains intrinsic sizing as a precursor to understanding how to control the size and flexibility of flex items along the main axis using
flex-grow,flex-shrink, andflex-basis.
Related concepts
- CSS logical properties module
min-inline-sizeblock-sizeinline-sizemax-block-sizemax-inline-sizemin-block-sizemin-inline-sizemargin-blockmargin-inlinepadding-blockpadding-inlineborder-blockborder-inlinecontain-intrinsic-block-sizecontain-intrinsic-inline-sizeoverflow-blockoverflow-inlineoverscroll-behavior-blockoverscroll-behavior-inline
- CSS box model module
marginshorthandmargin-bottommargin-leftmargin-rightmargin-topmargin-trimpaddingshorthandpadding-bottompadding-leftpadding-rightpadding-top
- CSS backgrounds and borders module
bordershorthandborder-widthshorthandborder-bottom-widthborder-left-widthborder-right-widthborder-top-width
- CSS overflow module
- CSS grid layout module
- CSS flexible box layout module
Specifications
| Specification |
|---|
| CSS Box Sizing Module Level 4> |
| CSS Box Sizing Module Level 3> |
See also
- CSS display module
- CSS flex layout module
- CSS grid layout module
- CSS positioned layout module
- CSS fragmentation module