inline-size
Sets the element’s size along the text line. In horizontal writing that’s the width, and its pair block-size sets the height.
- Initial value
auto- Inherited
- No
- Animatable
- yes, as a length or percentage
- Applies to
- all elements except non-replaced inline elements (e.g. span), table rows, and row groups
- JavaScript
element.style.inlineSize = "320px"
Example
#.card {
inline-size: min(100%, 280px);
padding: 12px;
border-radius: 14px;
background: #18181b;
}
.card img {
display: block;
inline-size: 100%;
block-size: 120px;
object-fit: cover;
border-radius: 10px;
}<article class="card">
<img src="/collections/covers/kurs-html-css-od-podstaw.webp" alt="" width="1536" height="1024">
<strong style="display: block; margin-top: 8px;">HTML and CSS course</strong>
<small style="color: #a1a1aa;">11 modules · 738 tasks</small>
</article>Definition and usage
#The inline-size property is the logical equivalent of width. It sets the element’s size on the inline axis, the direction text flows within a line. In ordinary horizontal text that’s simply the width, and both properties give the same result.
Its pair, block-size, sets the size on the block axis, along which consecutive paragraphs stack. In horizontal writing that’s the height. Once an element gets writing-mode: vertical-rl, the roles swap: inline-size controls the height, and block-size the width.
Both have constrained versions: min-inline-size, max-inline-size, min-block-size, and max-block-size. They work like min-width, max-width, and their vertical counterparts. All of them accept the same values as width: auto, lengths, percentages, plus min-content, max-content, and fit-content.
Just like width, inline-size has no effect on inline elements such as <span>. You’ll meet the same vocabulary in container queries: container-type: inline-size tracks exactly this inline size.
Syntax
#inline-size: auto | <length> | <percentage> | min-content | max-content | fit-content;
block-size: auto | <length> | <percentage> | min-content | max-content | fit-content;Values
#- A block-level element takes up all the available length of the line, meaning the parent’s full width.
<length>
A fixed inline size. In horizontal text that’s 160px of width.<percentage>
Half the inline size of the containing block.block axis
The pair for the block axis. In horizontal text it sets the element’s height.upper limit
The paragraph is at most about 24 characters per line. In vertical writing, the same rule would limit the column’s height.vertical writing mode
In vertical writing, the inline axis runs top to bottom, soinline-size: 100pxsets the element’s height, not its width. The width now comes from the content.
Values in practice
#auto
.demo { inline-size: auto; }160px
.demo { inline-size: 160px; }50%
.demo { inline-size: 50%; }block-size: 80px
.demo { block-size: 80px; }max-inline-size: 24ch
.demo { max-inline-size: 24ch; }vertical-rl
inline-size: 100px sets the element’s height, not its width. The width now comes from the content..stage { writing-mode: vertical-rl; width: 100%; height: 170px; }
.demo { inline-size: 100px; }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- A text column works well with
max-inline-size: 65ch. In vertical writing, the same rule reasonably limits the column’s height. - Don’t set
widthandinline-sizeon the same element. They describe the same dimension, so whichever declaration comes later in the cascade wins, and that’s easy to miss. - If
inline-sizedoesn’t seem to work, check thedisplay. Just likewidth, it has no effect on<span>or<a>without switching toinline-blockorblock.
Related entries
#- widthSets the width of an element.
- heightSets the height of an element.
- max-widthSets a maximum width the element won’t grow beyond.
- margin-inlineSets the margins at the start and end of a line. The logical version of margin-left and margin-right, aware of writing direction.
- container-typeTurns an element into a container that @container rules can query for its size. Also covers container-name and the container shorthand.
Spotted a mistake or missing an example? Write to us.