CSS block-size

The block-size property in CSS defines the size of an element in the block direction of its writing mode. The block direction can be vertical or horizontal, depending on the writing mode (e.g., ltr, rtl, or vertical-rl). This property is useful for creating flexible layouts that adapt to different writing modes.


Syntax of block-size

</>
Copy
block-size: auto | value | initial | inherit;

Values

ValueDescription
autoThe block size is automatically determined based on the content and other properties (default).
valueSpecifies the block size using any valid CSS unit, such as px, em, %, etc.
initialSets the property to its default value (auto).
inheritInherits the value from its parent element.

Default Value

auto


Examples for block-size

Using the CSS block-size Property

The following examples demonstrate how to use the block-size property with different values:

</>
Copy
/* Block size is automatically determined */
.element {
  block-size: auto;
}

/* Block size set to 200px */
.element {
  block-size: 200px;
}

/* Block size set to 50% of the parent element */
.element {
  block-size: 50%;
}

/* Block size inherits from the parent element */
.element {
  block-size: inherit;
}

Example for Fixed Block Size

Below is an example demonstrating how to use block-size: 200px to set a fixed block size for an element:

index.html

</>
Copy
<!DOCTYPE html>
<html lang="en">
<head>
<style>
  .box {
    block-size: 200px;
    background: red;
  }
</style>
</head>
<body>

<h1>Block Size: 200px</h1>
<div class="box"></div>

</body>
</html>

Since the div used in this example is a block, the block direction is vertical, and therefore the block size of 200px is in the vertical direction.

Browser Support

The block-size property is supported in most modern browsers. Below is a compatibility table:

BrowserVersion
Chrome57.0
Edge79.0
Firefox41.0
Safari12.1
Opera44.0