Course contentsShow
← Web Development
Lesson 462 of 2,9828. Advanced CSS Selectors and FeaturesFree lesson

Logical Sizing Properties

Apply block-size and inline-size for dimensions that respect writing mode, replacing width and height where appropriate.

Logical Sizing Properties

You'll learn how to set element dimensions that automatically adapt to different writing modes and text directions.

The Limitation of width and height

When you use width and height in CSS, you're setting dimensions that are always horizontal and vertical—no matter how the content flows. In languages that flow vertically (like traditional Chinese or Japanese), or when you use writing-mode to change text direction, these physical properties don't adapt.

Meet inline-size and block-size

Logical sizing properties respect the direction of content flow:

  • inline-size controls the dimension along the line of text (replaces width in horizontal languages)
  • block-size controls the dimension perpendicular to text lines (replaces height in horizontal languages)

Think of it like this: inline-size stretches in the direction you read, while block-size stretches in the direction paragraphs stack.

Practical Example

.card {
  inline-size: 300px;  /* Instead of width: 300px */
  block-size: 200px;   /* Instead of height: 200px */
}

/* If writing-mode changes to vertical, these values
   automatically apply to the correct dimensions */
.vertical-text {
  writing-mode: vertical-rl;
  inline-size: 300px;  /* Now controls HEIGHT (text flows down) */
  block-size: 200px;   /* Now controls WIDTH (blocks stack sideways) */
}

You also get logical variants: min-inline-size, max-inline-size, min-block-size, and max-block-size.

When to Use Them

Use logical sizing when building components that should work internationally or when you might change writing modes. They make your CSS truly layout-agnostic.

Key Takeaway: Use inline-size and block-size instead of width and height to create dimension rules that automatically adapt to any writing direction.