Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

vi — viewport inline-axis unit

The vi unit represents 1% of the large viewport’s dimension along the inline axis of the box it applies to. That box’s writing mode determines the axis.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

<number>vi

vi is a length unit: 1vi is 1% of the large viewport’s dimension along the inline axis of the box to which the unit applies. The box’s writing-mode determines that axis. With writing-mode: horizontal-tb on that box, 1vi equals 1vw; with writing-mode: vertical-rl, it equals 1vh. It is not a percentage of the parent’s size.

vi equals lvi; svi uses the small viewport and dvi the dynamic viewport. Expanded browser controls can obscure content sized with vi.

The example sets horizontal writing on the html root element, and the bar inherits that writing mode. At a large viewport width of 800 CSS pixels, the bar should measure 400 × 24 CSS pixels.

Examples

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>vi — viewport inline size</title>
  <style>
    html { writing-mode: horizontal-tb; overflow: hidden; }
    body { margin: 0; }
    .bar { inline-size: 50vi; block-size: 24px; background: teal; }
    .reference { width: 50lvw; height: 0; }
  </style>
</head>
<body>
  <div class="bar" aria-hidden="true"></div>
  <div class="reference" aria-hidden="true"></div>
  <script>
    if (!CSS.supports('inline-size', '50vi')) {
      console.log('vi unsupported');
    } else {
      const bar = getComputedStyle(document.querySelector('.bar'));
      const reference = getComputedStyle(document.querySelector('.reference'));
      console.log(`50vi matches half the large viewport width: ${bar.inlineSize === reference.width}`);
      console.log(`block-size: ${bar.blockSize}`);
    }
  </script>
</body>
</html>

Result

50vi matches half the large viewport width: true
block-size: 24px

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources