Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

writing-mode — text layout direction

The writing-mode property selects horizontal or vertical lines and the direction in which successive lines and blocks stack. It does not replace control over text direction or character orientation.

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

Syntax

writing-mode: horizontal-tb | vertical-rl | vertical-lr | sideways-rl | sideways-lr;

writing-mode determines line orientation and block flow direction. It is inherited, initially horizontal-tb, and not animatable.

horizontal-tb creates horizontal lines stacked from top to bottom. vertical-rl creates vertical lines stacked from right to left, while vertical-lr stacks them from left to right. With direction: ltr, text runs from top to bottom in both vertical modes.

sideways-rl and sideways-lr also create vertical lines, but use rotated horizontal typography. With direction: ltr, text runs downward and upward respectively; lines stack leftward and rightward respectively. In vertical-rl and vertical-lr, text-orientation controls character orientation; changing writing-mode alone does not make every letter upright.

direction sets the base direction within a line, not the block stacking direction. In vertical layout, logical inline-size corresponds to height and block-size to width. The example uses text-orientation: upright to show two columns of upright letters.

Examples

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Right-to-left vertical columns</title>
  <style>
    #sample {
      writing-mode: vertical-rl;
      text-orientation: upright;
      direction: ltr;
      white-space: nowrap;
      font: 1.5rem/1.5 monospace;
      border: 1px solid;
      padding: 0.5rem;
    }
  </style>
</head>
<body>
  <main>
    <h1>Vertical text</h1>
    <p id="sample"><span>ABC</span><br><span>DEF</span></p>
  </main>
  <script>
    const sample = document.getElementById('sample');
    const columns = Array.from(sample.querySelectorAll('span'), line => {
      const text = line.firstChild;
      return Array.from(text.data, (letter, index) => {
        const range = document.createRange();
        range.setStart(text, index);
        range.setEnd(text, index + 1);
        const { x, y } = range.getBoundingClientRect();
        return { letter, x, y };
      }).sort((a, b) => a.y - b.y);
    }).sort((a, b) => a[0].x - b[0].x);
    const rows = columns[0].map((_, row) => columns.map(column => column[row].letter).join(' '));
    console.log(`writing-mode: ${getComputedStyle(sample).writingMode}\n${rows.join('\n')}`);
  </script>
</body>
</html>

Result

writing-mode: vertical-rl
D A
E B
F C

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