CSS writing-mode Property

The CSS writing-mode property controls whether text is laid out horizontally or vertically and determines the direction in which lines of text progress.

It is useful for multilingual content, vertical headings, labels, and layouts that use different writing systems. The property also affects the inline and block directions used by CSS layout and logical properties.

Syntax

The writing-mode property accepts a keyword that determines the orientation of text lines and the direction in which successive lines are placed.

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

Common declarations include:

.horizontal-text {
  writing-mode: horizontal-tb;
}
.vertical-right {
  writing-mode: vertical-rl;
}
.vertical-left {
  writing-mode: vertical-lr;
}
.sideways-text {
  writing-mode: sideways-rl;
}

The property also accepts CSS-wide keywords such as initial, inherit, unset, revert, and revert-layer.

Property Values

Value Description
horizontal-tb Text lines are horizontal, and successive lines progress from top to bottom. This is the initial value.
vertical-rl Text lines are vertical, and successive lines progress from right to left.
vertical-lr Text lines are vertical, and successive lines progress from left to right.
sideways-rl Text lines progress from right to left, with characters displayed sideways rather than using the normal upright orientation of vertical scripts.
sideways-lr Text lines progress from left to right, with characters displayed sideways in the opposite orientation from sideways-rl.
initial Resets the property to horizontal-tb.
inherit Uses the computed writing mode of the parent element.
unset Uses the inherited value because writing-mode is an inherited property.
revert Reverts the property according to the CSS cascade.
revert-layer Reverts the property according to the previous cascade layer.

Older CSS also defined values such as lr, lr-tb, rl, rl-tb, tb, and tb-rl. These are legacy compatibility values and should not be used in new stylesheets.

How It Works

CSS layout uses two logical axes: the inline axis and the block axis.

The inline axis follows the direction in which text is arranged within a line. The block axis follows the direction in which successive lines or block-level elements are placed.

In a typical English document using horizontal-tb, the inline axis is horizontal and the block axis is vertical.

When a vertical writing mode is applied, these axes change orientation.

.vertical-content {
  writing-mode: vertical-rl;
}

In this example, text is arranged in vertical lines, and successive lines progress from right to left.

The writing mode affects more than text appearance. It also influences logical dimensions, margins, padding, borders, and other layout behavior.

Inline and Block Directions

Writing Mode Inline Axis Block Progression
horizontal-tb Horizontal Top to bottom
vertical-rl Vertical Right to left
vertical-lr Vertical Left to right
sideways-rl Vertical Right to left
sideways-lr Vertical Left to right

The direction property also influences inline progression, particularly for right-to-left languages. Writing mode alone does not determine every aspect of text direction.

horizontal-tb

The horizontal-tb value is the default writing mode for most web content.

Text is arranged in horizontal lines, and successive lines progress from the top of the container toward the bottom.

.standard-text {
  writing-mode: horizontal-tb;
}

For left-to-right languages such as English, characters normally progress from left to right within each line.

For right-to-left languages such as Arabic and Hebrew, the inline direction can run from right to left while the lines still progress from top to bottom.

This value is appropriate for most headings, paragraphs, forms, and navigation elements.

vertical-rl

The vertical-rl value arranges text in vertical lines, with successive lines progressing from right to left.

.vertical-heading {
  writing-mode: vertical-rl;
}

This writing mode is commonly associated with traditional vertical Japanese and Chinese typography.

In vertical writing, characters from scripts designed for vertical layout may remain upright, while Latin letters may be rotated according to the text orientation rules.

For example, a short English label may appear vertically with its letters rotated as part of the line.

Vertical Text with Upright Characters

The text-orientation property can control how characters appear inside a vertical writing mode.

.upright-text {
  writing-mode: vertical-rl;
  text-orientation: upright;
}

This keeps characters upright rather than rotating them sideways. It can be useful for certain labels, although it changes the visual presentation of Latin text.

vertical-lr

The vertical-lr value arranges text in vertical lines, with successive lines progressing from left to right.

.vertical-left-text {
  writing-mode: vertical-lr;
}

The inline axis remains vertical, but the block progression is opposite to vertical-rl.

This value is useful when a vertical layout requires columns to advance from the left side of the container toward the right.

For Latin text, the orientation of characters follows the applicable vertical text orientation rules.

sideways-rl and sideways-lr

The sideways-rl and sideways-lr values arrange text along a vertical inline axis while displaying characters sideways.

Using sideways-rl

The sideways-rl value produces vertical line progression from right to left, with sideways character orientation.

.sideways-right {
  writing-mode: sideways-rl;
}

This can be useful for labels or decorative text that should appear rotated along a vertical edge.

Using sideways-lr

The sideways-lr value produces vertical line progression from left to right, with sideways characters oriented in the opposite direction.

.sideways-left {
  writing-mode: sideways-lr;
}

Unlike the vertical-rl and vertical-lr modes, sideways writing modes do not use upright vertical glyph orientation for scripts that normally support it.

Browser support: Support for sideways writing modes has historically varied. Test these values in the browsers your site supports.

writing-mode vs. direction

The writing-mode and direction properties are related, but they control different aspects of text layout.

Property Purpose
writing-mode Controls whether lines are horizontal or vertical and determines block progression.
direction Controls the base inline direction of text, such as left-to-right or right-to-left.
text-orientation Controls the orientation of characters within vertical writing modes.

For example:

.arabic-text {
  writing-mode: horizontal-tb;
  direction: rtl;
}

The text remains in horizontal lines, but its base inline direction is right to left.

For HTML content, use the dir attribute to identify text direction whenever possible.

<p lang="ar" dir="rtl">مرحبا بالعالم</p>

The HTML dir attribute communicates direction as part of the document's meaning, rather than relying only on presentation styles.

Writing Modes and Logical Properties

CSS logical properties describe dimensions and spacing relative to the inline and block axes rather than fixed physical directions.

Because writing-mode changes these axes, logical properties can adapt automatically to horizontal and vertical layouts.

Logical Dimensions

The inline-size and block-size properties provide logical alternatives to physical width and height.

.logical-box {
  writing-mode: vertical-rl;
  inline-size: 200px;
  block-size: 100px;
}

In this vertical writing mode, inline-size controls the physical height, while block-size controls the physical width.

Logical Margins and Padding

Logical spacing properties also respond to the writing mode.

.logical-content {
  writing-mode: vertical-rl;
  margin-block-start: 20px;
  padding-inline-start: 10px;
}

In this example, margin-block-start applies spacing on the right side of the element, while padding-inline-start follows the start of the vertical inline direction.

Logical properties are especially useful when building layouts that support multiple languages and writing systems.

Examples

Example 1: Standard Horizontal Text

The default writing mode displays text in horizontal lines.

.horizontal-example {
  writing-mode: horizontal-tb;
}

Successive lines progress from top to bottom.

Example 2: Vertical Heading

A heading can be displayed vertically along the edge of a container.

.vertical-title {
  writing-mode: vertical-rl;
}

This is useful for decorative headings, side labels, and vertical navigation designs.

Example 3: Left-to-Right Vertical Columns

The vertical-lr value makes successive vertical lines progress from left to right.

.vertical-columns {
  writing-mode: vertical-lr;
}

The result differs from vertical-rl in the direction of block progression.

Example 4: Upright Vertical Characters

The text-orientation property can keep characters upright in a vertical layout.

.upright-label {
  writing-mode: vertical-rl;
  text-orientation: upright;
}

This produces a stacked appearance for many Latin characters.

Example 5: Sideways Text

The sideways-lr value can create a sideways label along a vertical edge.

.side-label {
  writing-mode: sideways-lr;
}

Check browser compatibility before relying on this value for essential content.

Example 6: Responsive Writing Mode

Media queries can switch between vertical and horizontal text layouts.

.responsive-label {
  writing-mode: vertical-rl;
}
@media (max-width: 600px) {
  .responsive-label {
    writing-mode: horizontal-tb;
  }
}

This example displays a vertical label on wider screens and returns it to horizontal text on smaller screens.

Inheritance

The writing-mode property is inherited. Descendant elements normally use the computed writing mode of their parent unless they specify a different value.

.parent {
  writing-mode: vertical-rl;
}
.child {
  /* Inherits vertical-rl */
}

The initial value is horizontal-tb.

Because writing mode affects layout axes, inherited values can change the arrangement of text and the behavior of logical properties throughout a container.

To restore horizontal text inside a vertical layout, explicitly set writing-mode: horizontal-tb on the appropriate child element.

Practical Example

This example compares horizontal, vertical right-to-left, vertical left-to-right, and upright vertical text using the same short label.

HTML

<div class="writing-mode-demo">
  <div class="writing-mode-example">
    <strong>horizontal-tb</strong>
    <div class="writing-mode-box">
      <span class="mode-horizontal">CSS Layout</span>
    </div>
  </div>
  <div class="writing-mode-example">
    <strong>vertical-rl</strong>
    <div class="writing-mode-box">
      <span class="mode-vertical-rl">CSS Layout</span>
    </div>
  </div>
  <div class="writing-mode-example">
    <strong>vertical-lr</strong>
    <div class="writing-mode-box">
      <span class="mode-vertical-lr">CSS Layout</span>
    </div>
  </div>
  <div class="writing-mode-example">
    <strong>vertical-rl + upright</strong>
    <div class="writing-mode-box">
      <span class="mode-upright">CSS Layout</span>
    </div>
  </div>
</div>

CSS

.writing-mode-demo {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}
.writing-mode-example {
  width: 150px;
}
.writing-mode-example strong {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
}
.writing-mode-box {
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 150px;
  height: 180px;
  padding: 12px;
  border: 1px solid #ccc;
  background: #f5f5f5;
}
.mode-horizontal {
  writing-mode: horizontal-tb;
}
.mode-vertical-rl {
  writing-mode: vertical-rl;
}
.mode-vertical-lr {
  writing-mode: vertical-lr;
}
.mode-upright {
  writing-mode: vertical-rl;
  text-orientation: upright;
}
Browser Result
horizontal-tb
CSS Layout
vertical-rl
CSS Layout
vertical-lr
CSS Layout
vertical-rl + upright
CSS Layout

Result: The first box displays horizontal text. The second and third arrange the label vertically using different block progression directions. The fourth keeps the characters upright within a vertical writing mode.

The example demonstrates how writing-mode changes the orientation of text and how text-orientation can further control the appearance of characters.

Common Mistakes

Confusing writing-mode with direction

The writing-mode property controls the orientation of text lines and block progression. The direction property controls the base inline direction.

Use the HTML dir attribute when identifying the direction of language content.

Expecting All Vertical Characters to Remain Upright

In vertical writing modes, Latin characters may appear sideways while characters from other writing systems remain upright.

Use text-orientation when a specific character orientation is required.

Using transform Instead of writing-mode

A CSS transform can rotate an element visually, but it does not change the element's writing mode or logical layout axes.

/* Rotates the element visually */
.rotated {
  transform: rotate(90deg);
}
/* Changes the writing mode */
.vertical {
  writing-mode: vertical-rl;
}

Use writing-mode when the text should participate in vertical layout rather than simply appear rotated.

Ignoring Logical Dimensions

In vertical writing modes, physical width and height do not correspond to the inline and block axes in the same way as they do in horizontal layouts.

Consider using inline-size and block-size when building writing-mode-aware layouts.

Relying on Unsupported Sideways Values

Support for sideways-rl and sideways-lr has varied across browser versions.

Provide a supported fallback when sideways writing modes are important to the design.

.sideways-label {
  writing-mode: vertical-rl;
  writing-mode: sideways-rl;
}

Applying Vertical Writing to Large Containers Unintentionally

Because writing-mode is inherited, setting it on a parent can change the layout of all descendant text.

Apply it to the smallest appropriate container when only a heading or label should be vertical.

Important Considerations

  • Writing systems: Vertical writing is important for some East Asian languages and specialized typography.
  • Text direction: Use the HTML dir attribute and appropriate lang values for multilingual content.
  • Character orientation: The text-orientation property controls upright and sideways character presentation within vertical writing modes.
  • Logical properties: Properties such as inline-size, block-size, and margin-block-start adapt to the writing mode.
  • Inheritance: Writing modes are inherited and can affect entire sections of a document.
  • Responsive design: Vertical labels may need to return to horizontal text on smaller screens.
  • Browser compatibility: Sideways values require additional compatibility testing.
  • Accessibility: Preserve a logical reading order and avoid using vertical text for long passages when it would make content difficult to read.
  • Layout behavior: Changing the writing mode can affect sizing, alignment, overflow, and other layout calculations.

For ordinary English-language content, horizontal-tb is generally appropriate. Use vertical writing modes when required by the language or when they provide a clear design benefit.

Browser Support

The CSS writing-mode property is widely supported in modern browsers, including Chrome, Edge, Firefox, Safari, and Opera.

The horizontal-tb, vertical-rl, and vertical-lr values have broad support. Availability of sideways-rl and sideways-lr may vary in older browser versions.

For current compatibility information, visit Can I Use? .

Specifications

The writing-mode property is defined in the CSS Writing Modes specifications, which describe horizontal and vertical text layout, writing directions, and related layout behavior.