π CSS block-size β Complete Tutorial
π What Is block-size?
The block-size property defines the size of an element in the block direction. The block direction depends on the documentβs writing mode:
- β‘ In horizontal writing (English): block = height
- β¬ In vertical writing (Japanese, Chinese): block = width
>>βUse block-size for layouts that automatically adapt to writing modes and international languages.β
Note
β Logical equivalent of height
β Writing-mode aware
β Supports responsive + multilingual UI
β Writing-mode aware
β Supports responsive + multilingual UI
π¦ Syntax
block-size syntax
block-size: <length> | <percentage> | auto | max-content | min-content | fit-content();π Understanding Logical Directions
| Writing Mode | Block Direction | block-size Equals |
|---|---|---|
| horizontal-tb (default) | vertical | height |
| vertical-rl | horizontal | width |
π 1. Basic Example (Horizontal Writing)
Block-size = height
.box {
block-size: 200px; /* same as height: 200px */
}π 2. Vertical Writing Mode Example
Vertical writing
.vertical-text {
writing-mode: vertical-rl;
block-size: 200px; /* now acts like width */
}In vertical-rl mode, block direction is horizontal β so block-size expands width.
π 3. Using Percentages
Percentage block-size
.panel {
block-size: 50%;
}Applies to the block dimension relative to the parentβs block-size (height in horizontal writing).
π 4. Using Intrinsic Sizing Keywords
Intrinsic block sizes
.box {
block-size: max-content; /* Expand to longest content */
block-size: min-content; /* Shrink to smallest */
block-size: fit-content(300px); /* Fit but clamp */
}π 5. Replace Height With Block-Size in Responsive Layouts
Logical height replacement
.card {
block-size: 300px;
}Using logical properties makes your UI future-proof and multilingual-ready.
π 6. Limiting Block Size
Min and max block size
.note {
min-block-size: 150px;
max-block-size: 300px;
}π§ͺ Real-World Use Cases
1οΈβ£ Card Component with Consistent Vertical Size
Card component
.card {
block-size: 250px;
padding: 1rem;
}2οΈβ£ Vertical Language Support (Japanese Layout)
Japanese layout
.japan {
writing-mode: vertical-rl;
block-size: 200px; /* horizontal sizing */
}3οΈβ£ Responsive Fullscreen Section
Fullscreen block
section.full {
block-size: 100vh;
}Works just like height, but adjusts for writing modes automatically.
β οΈ Common Mistakes
- β Mixing logical (block-size) and physical (height) sizing β conflicts
- β Forgetting writing mode affects block direction
- β Assuming block-size changes width (only in vertical modes!)
Note
Use block-size consistently when building international-friendly layouts.
π₯ Summary
The block-size property is the logical equivalent ofheight in CSS (or width in vertical writing modes). It makes your layout responsive to writing direction, language, and orientation.
>>βThink in block and inline directions β not top and side β for modern, global CSS.β
Learn more βMDN Docs π