Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Container Queries and Logical Properties

The inline-size property

Reference for the CSS inline-size property: the logical width that follows the writing mode, with values, examples and how it relates to width and height.

The inline-size property sets the size of an element along the inline axis, the direction in which text runs within a line. In horizontal writing modes (English, Spanish, Arabic and so on) that is the width; in vertical writing modes (traditional Japanese or Chinese, for example) it is the height.

It is the logical counterpart of width. Using logical properties lets one component adapt to different writing modes without a second set of rules.

CSS
.card {
  inline-size: 20rem;
}

Try it

inline-size follows the writing mode

Same declaration, different axis: the second box gets its 160 pixels from top to bottom.

Syntax

CSS
inline-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 (all elements except non-replaced inline boxes, table rows and row groups)
  • Inherited: no
  • Animatable: yes, as a length, percentage or calc() value
  • Computed value: as for width, whatever the physical property would compute to
  • Percentages: relative to the inline size of the containing block

Values

Value Description
auto The browser computes the size from the layout mode. For blocks, this fills the available inline space.
<length> A fixed size such as 20rem or 300px.
<percentage> A share of the containing block's inline size.
min-content The narrowest size without overflow, such as the longest word.
max-content The size of the content on a single line.
fit-content The content size, but never more than the available space.
fit-content(<length-percentage>) Like fit-content but using the given value as the limit.
stretch Makes the box fill the available inline space (minus its margins), even where auto would shrink-wrap. Newer; check a compatibility table.

Usage notes

  • Maps to width or height. In horizontal-tb, inline-size is width. In vertical-rl and vertical-lr, it is height. Declaring both width and inline-size on an element means the last one in the cascade wins for the same axis.
  • Writing mode comes from the element itself. The axis is chosen by the element's own writing-mode, not its parent's. See writing-mode.
  • Percentages follow the axis too. inline-size: 50% is half of the containing block's inline size, even in vertical text.
  • Combine with min/max. Use min-inline-size and max-inline-size as guard rails, and box-sizing to decide whether padding and border are included.
  • Container queries. The inline-size value of container-type is named after this axis: it lets the container's inline size be queried.
  • Keep a consistent style. Mixing width and inline-size in the same code base works, but it is easier to read if you choose logical properties for components that must respect writing modes and use physical ones for things that never rotate, such as images with a fixed pixel size.

Browser support

Supported in all current major browsers and part of Baseline; the stretch keyword is newer and its support varies, so check a compatibility table.