On this page
Box Model & Sizing
Prev: properties | Up: properties | Next: Display & Layout
Rel: Box Model & Formatting Contexts, Math & Sizing Functions
Ref: MDN Web Docs — CSS Box Model
Tags: #public #web #css #properties #box-model
Contents
box-sizing: border-box
By default (content-box), width and height exclude padding and borders. Setting border-box makes declared dimensions include padding and borders for predictable layouts:
*, *::before, *::after {
box-sizing: border-box;
}
Logical Properties & Intrinsic Sizing
Prefer logical properties (inline = text flow axis, block = perpendicular axis) over physical left/right/top/bottom so layouts adapt automatically to RTL or vertical writing modes:
.panel {
inline-size: min(100%, 65ch);
margin-inline: auto;
padding-block: 1rem;
padding-inline: 1.5rem;
}
aspect-ratio & overflow
.video-box {
width: 100%;
aspect-ratio: 16 / 9;
overflow: hidden;
}
Linked from
- tuts/css/functions/math_and_sizing_functions
- tuts/css/properties
- tuts/css/properties/box_model
- tuts/css/properties/box_model/aspect-ratio
- tuts/css/properties/box_model/box-sizing
- tuts/css/properties/box_model/inline-size
- tuts/css/properties/box_model/margin
- tuts/css/properties/box_model/overflow
- tuts/css/properties/box_model/padding
- tuts/css/properties/box_model_and_sizing
- tuts/css/properties/display_and_layout
- tuts/css/tutorials/box_model_and_formatting_contexts
- tuts/html/elements/tables_and_media
- tuts/html/tutorials/media_and_responsive_images
Related notes
- tuts/css/properties Linked here; links to this page; shared tags: #css, #properties, #web
- tuts/css/properties/display_and_layout Linked here; links to this page; shared tags: #css, #properties, #web
- tuts/css/functions/math_and_sizing_functions Linked here; links to this page; shared tags: #css, #web
- tuts/css/tutorials/box_model_and_formatting_contexts Linked here; links to this page; shared tags: #css, #web
- tuts/css/properties/box_model links to this page; shared tags: #css, #properties, #web
- tuts/css/properties/box_model/aspect-ratio links to this page; shared tags: #css, #properties, #web
- tuts/css/properties/box_model/box-sizing links to this page; shared tags: #css, #properties, #web
- tuts/css/properties/box_model/inline-size links to this page; shared tags: #css, #properties, #web
- tuts/css/properties/box_model/margin links to this page; shared tags: #css, #properties, #web
- tuts/css/properties/box_model/overflow links to this page; shared tags: #css, #properties, #web