Box
block-size
block-size sets the size of an element in the direction its lines stack. In horizontal text it works like height, and in vertical text like width.
Syntax
auto | <length-percentage [0,∞]> | min-content | max-content | fit-content | fit-content(<length-percentage [0,∞]>)Preview
Code
.box {
writing-mode: vertical-rl;
block-size: 200px;
}Controls
About
Writing the value
- A length such as
200px: uses that size. Content that does not fit overflows the box. auto: the initial value. Grows and shrinks with the number of lines inside.min-content,max-content,fit-content: for a normal box of text, all of them fit the content (the same asauto).
The preview box uses vertical text (writing-mode: vertical-rl), so lines stack from right to left and block-size sets the width of the box. With auto the width fits the number of columns, and with a length, columns that do not fit are cut off on the left (the preview box hides overflowing content). Remove the helper writing-mode from the code to switch to horizontal text, where block-size sets the height.
When to use it
Use it on pages that switch between vertical and horizontal text, to size the direction lines stack in with a single declaration. Together with inline-size, the box keeps the same shape relative to the text in either direction.
Watch out
- It sets the same thing as
heightin horizontal text andwidthin vertical text, so if you write both, the later one wins. %is a share of the parent's size in the same direction (the height, in horizontal text). In horizontal text, it behaves likeautowhen the parent's height is not fixed.- For the minimum and maximum, use
min-block-sizeandmax-block-size, which work likemin-heightandmax-height.