CSS Reference ยท Container Queries and Logical Properties
The block-size property
Reference for the CSS block-size property: the logical height that follows the writing mode, with values, a live example and notes on min and max limits.
The block-size property sets the size of an element along the block axis, the direction in which blocks (such as paragraphs) stack. In horizontal writing modes that is the height. In vertical writing modes the blocks stack sideways, so block-size becomes the width.
It is the logical counterpart of height and the partner of inline-size.
.banner { block-size: 12rem; }
Try it
In the vertical box the roles swap: inline-size: 150px is its height and block-size: 90px is its width.
Syntax
block-size: auto | <length> | <percentage> | min-content | max-content | fit-content | fit-content(<length-percentage>) | stretch
- Initial value:
auto - Applies to: same as
widthandheight - Inherited: no
- Animatable: yes, as a length, percentage or
calc()value - Computed value: as for
height, whatever the physical property would compute to - Percentages: relative to the block size of the containing block (a percentage only resolves if that size is definite)
Values
| Value | Description |
|---|---|
auto |
The size comes from the content. In normal block layout this is the height needed to show all children. |
<length> |
A fixed size such as 12rem or 200px. Content that is bigger overflows. |
<percentage> |
A share of the containing block's block size, if that size is set explicitly; otherwise it behaves like auto. |
min-content, max-content, fit-content |
Intrinsic sizing keywords. In the block axis they usually give the same result as auto. |
stretch |
Fills the available space in the block axis. Newer; check a compatibility table. |
Usage notes
- Equivalent to
heightin horizontal text. Settingblock-size: 200pxandheight: 200pxis the same on ahorizontal-tbelement. The logical form adapts if the element or its ancestors later change writing mode. - Fixed block sizes clip or overflow. Text grows downward in the block axis, so an explicit
block-sizethat is smaller than the content makes it overflow. Prefermin-block-sizefor boxes that must be at least a certain size but can grow. - Percentages need a definite parent. As with
height,block-size: 50%does nothing useful if the parent's block size isauto. - Aspect ratio. If you set
aspect-ratioand leaveblock-sizeasauto, it is computed from the inline size. - Box sizing. With
box-sizing: content-box, padding and border are added on top. Withborder-boxthey are included. Seebox-sizing. - Container queries. Querying the container's block size requires
container-type: size, which means the block size cannot come from content.
Browser support
Supported in all current major browsers and part of Baseline; the stretch keyword is newer, so check a compatibility table.
Related
inline-sizeโ the logical widthmin-block-sizeandmax-block-sizeโ limitsheightโ the physical property- logical properties โ overview
- Lessons: Writing Modes, Width and Height