Skip to content
Tutorials Center
My learning

Topics

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.

CSS
.banner {
  block-size: 12rem;
}

Try it

block-size follows the writing mode

In the vertical box the roles swap: inline-size: 150px is its height and block-size: 90px is its width.

Syntax

CSS
block-size: auto | <length> | <percentage> | min-content | max-content
          | fit-content | fit-content(<length-percentage>) | stretch
  • Initial value: auto
  • Applies to: same as width and height
  • 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 height in horizontal text. Setting block-size: 200px and height: 200px is the same on a horizontal-tb element. 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-size that is smaller than the content makes it overflow. Prefer min-block-size for 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 is auto.
  • Aspect ratio. If you set aspect-ratio and leave block-size as auto, it is computed from the inline size.
  • Box sizing. With box-sizing: content-box, padding and border are added on top. With border-box they are included. See box-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.