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.
.card { inline-size: 20rem; }
Try it
Same declaration, different axis: the second box gets its 160 pixels from top to bottom.
Syntax
inline-size: auto | <length> | <percentage> | min-content | max-content | fit-content | fit-content(<length-percentage>) | stretch
- Initial value:
auto - Applies to: same as
widthandheight(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
widthorheight. Inhorizontal-tb,inline-sizeiswidth. Invertical-rlandvertical-lr, it isheight. Declaring bothwidthandinline-sizeon 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. Seewriting-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-sizeandmax-inline-sizeas guard rails, andbox-sizingto decide whether padding and border are included. - Container queries. The
inline-sizevalue ofcontainer-typeis named after this axis: it lets the container's inline size be queried. - Keep a consistent style. Mixing
widthandinline-sizein 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.
Related
block-sizeโ the logical heightmin-inline-sizeandmax-inline-sizeโ limitswidthโ the physical property- logical properties โ overview
- Lessons: Writing Modes, Width and Height