CSS - block-size Property



The block-size property of CSS determines the horizontal or vertical size of an element's block, based on the writing mode of the element. It relates to the width or the height properties of CSS, based on the value of writing-mode.

When the writing mode is vertically orientated, the value of block-size relates to the width of the element, else it relates to the height of the element.

Possible Values

The CSS property block-size takes the same value as the width and height properties.

Applies To

All elements but non-replaced inline elements, table rows, and row groups.

Syntax

Following are the different ways in which the block-size can be declared:

Length Value

block-size: 100px;
block-size: 20em;

percentage Value

block-size: 45%;

Keyword Value

block-size: max-content;
block-size: min-content;
block-size: fit-content;
block-size: auto;

Global Value

block-size: inherit;
block-size: initial;
block-size: revert;
block-size: revert-layer;
block-size: unset;

CSS block-size - Using Length Values

Following example demonstrates the output with writing-mode: vertical-rl and block-size is given a length value:

<html>
<head>
<style>
   .container {
      writing-mode: vertical-rl;
      background-color: pink;
      border: 2px solid blue;
      display: inline-block;
   }

   .sampleText-px {
      block-size: 100px;
   }

   .sampleText-em {
      block-size: 20em;
   }
</style>
</head>
<body>
   <h2>block-size - length value</h2>
   <div class="container sampleText-px">Sample Text-px</div>
   <div class="container sampleText-em">Sample Text-em</div>
</body>
</html>

Following example demonstrates the output with writing-mode: horizontal-tb and block-size is given a length value:

<html>
<head>
<style>
   .container {
      writing-mode: horizontal-tb;
      background-color: pink;
      border: 2px solid blue;
      display: inline-block;
   }

   .sampleText-px {
      block-size: 100px;
   }

   .sampleText-em {
      block-size: 20em;
   }
</style>
</head>
<body>
   <h2>block-size - length value with writing-mode: horizontal-tb</h2>
   <div class="container sampleText-px">Sample Text-px</div>
   <div class="container sampleText-em">Sample Text-em</div>
</body>
</html>

CSS block-size - Using Percentage Values

Following example demonstrates the output with writing-mode: vertical-rl and block-size is given as a percentage value:

<html>
<head>
<style>
   .container {
      writing-mode: vertical-rl;
      background-color: pink;
      border: 2px solid blue;
      display: inline-block;
   }

   .sampleText-10per {
      block-size: 10%;
   }

   .sampleText-65per {
      block-size: 65%;
   }
</style>
</head>
<body>
   <h2>block-size - percentage value with writing-mode: vertical-rl</h2>
   <div class="container sampleText-10per">Sample Text-10%</div>
   <div class="container sampleText-65per">Sample Text-65%</div>
</body>
</html>

Following example demonstrates the output with writing-mode: horizontal-tb and block-size is given as a percentage value:

<html>
<head>
<style>
   .container {
      writing-mode: horizontal-tb;
      background-color: pink;
      border: 2px solid blue;
      display: inline-block;
   }

   .sampleText-10per {
      block-size: 10%;
   }

   .sampleText-65per {
      block-size: 65%;
   }
</style>
</head>
<body>
   <h2>block-size - percentage value with writing-mode: horizontal-tb</h2>
   <div class="container sampleText-10per">Sample Text-10%</div>
   <div class="container sampleText-65per">Sample Text-65%</div>
</body>
</html>

CSS block-size - Using Keyword Values

Following example demonstrates the output with writing-mode: vertical-rl and block-size is given as a keyword value:

<html>
<head>
<style>
   .container {
      writing-mode: vertical-rl;
      background-color: pink;
      border: 2px solid blue;
      display: inline-block;
   }

   .sampleText-auto {
      block-size: auto;
   }

   .sampleText-max {
      block-size: max-content;
   }

   .sampleText-min {
      block-size: min-content;
   }

   .sampleText-fit {
      block-size: fit-content;
   }
</style>
</head>
<body>
   <h2>block-size - keyword value with writing-mode: vertical-rl</h2>
   <div class="container sampleText-auto">Sample Text - auto</div>
   <div class="container sampleText-max">Sample Text - max-content</div>
   <div class="container sampleText-min">Sample Text - min-content</div>
   <div class="container sampleText-fit">Sample Text - fit-content feature</div>
</body>
</html>

Following example demonstrates the output with writing-mode: horizontal-tb and block-size is given as a keyword value:

<html>
<head>
<style>
   .container {
      writing-mode: horizontal-tb;
      background-color: pink;
      border: 2px solid blue;
      display: inline-block;
   }

   .sampleText-auto {
      block-size: auto;
   }

   .sampleText-max {
      block-size: max-content;
   }

   .sampleText-min {
      block-size: min-content;
   }

   .sampleText-fit {
      block-size: fit-content;
   }
</style>
</head>
<body>
   <h2>block-size - keyword value with writing-mode: horizontal-tb</h2>
   <div class="container sampleText-auto">Sample Text - auto</div>
   <div class="container sampleText-max">Sample Text - max-content</div>
   <div class="container sampleText-min">Sample Text - min-content</div>
   <div class="container sampleText-fit">Sample Text - fit-content feature</div>
</body>
</html>
Advertisements