CSS Writing Modes Level 4

Editor’s Draft,

More details about this document
This version:
https://drafts.csswg.org/css-writing-modes-4/
Latest published version:
https://www.w3.org/TR/css-writing-modes-4/
Previous Versions:
Test Suite:
http://test.csswg.org/suites/css-writing-modes-3_dev/nightly-unstable/
Feedback:
CSSWG Issues Repository
Tracker
Inline In Spec
Editors:
Elika J. Etemad / fantasai (Apple)
(Google)
Former Editors:
(Antenna House)
(Microsoft)
(Microsoft)
Suggest an Edit for this Spec:
GitHub Editor

Abstract

CSS Writing Modes Level 4 defines CSS support for various writing modes and their combinations, including left-to-right and right-to-left text ordering as well as horizontal and vertical orientations.

CSS is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, etc.

Status of this document

This is a public copy of the editors’ draft. It is provided for discussion only and may change at any moment. Its publication here does not imply endorsement of its contents by W3C. Don’t cite this document other than as work in progress.

Please send feedback by filing issues in GitHub (preferred), including the spec code “css-writing-modes” in the title, like this: “[css-writing-modes] …summary of comment…”. All issues and comments are archived. Alternately, feedback can be sent to the (archived) public mailing list [email protected].

This document is governed by the 18 August 2025 W3C Process Document.

The following features are at-risk, and may be dropped during the CR period:

“At-risk” is a W3C Process term-of-art, and does not necessarily imply that the feature is in danger of being dropped or delayed. It means that the WG believes the feature may have difficulty being interoperably implemented in a timely manner, and marking it as such allows the WG to drop the feature if necessary when transitioning to the Proposed Rec stage, without having to publish a new Candidate Rec without the feature first.

1. Introduction to Writing Modes

CSS Writing Modes Level 4 defines CSS features to support for various international writing modes, such as left-to-right (e.g. Latin or Indic), right-to-left (e.g. Hebrew or Arabic), bidirectional (e.g. mixed Latin and Arabic) and vertical (e.g. Asian scripts).

A writing mode in CSS is determined by the writing-mode, direction, and text-orientation properties. It is defined primarily in terms of its inline base direction and block flow direction:

The inline base direction is the primary direction in which content is ordered on a line and defines on which sides the “start” and “end” of a line are. The direction property specifies the inline base direction of a box and, together with the unicode-bidi property and the inherent directionality of any text content, determines the ordering of inline-level content within a line.

The block flow direction is the direction in which block-level boxes stack and the direction in which line boxes stack within a block container. The writing-mode property determines the block flow direction.

Writing systems typically have one or two native writing modes. Some examples are:

A horizontal writing mode is one with horizontal lines of text, i.e. a downward or upward block flow. A vertical writing mode is one with vertical lines of text, i.e. a leftward or rightward block flow.

These terms should not be confused with vertical block flow (which is a downward or upward block flow) and horizontal block flow (which is leftward or rightward block flow). To avoid confusion, CSS specifications avoid this latter set of terms.

The typographic mode determines whether to use typographic conventions specific to vertical flow for vertical scripts (vertical typographic mode) or to use the typographic conventions of horizontal writing modes (horizontal typographic mode). This concept distinguishes vertical typesetting from rotated horizontal typesetting.

The text-orientation component of the writing mode controls the glyph orientation in vertical typographic modes, dictating whether a particular typographic character unit is typeset upright or typeset sideways.

See Unicode Technical Note #22 [UTN22] (HTML version) for a more in-depth introduction to writing modes and vertical text.

1.1. Module Interactions

This module replaces and extends the unicode-bidi and direction features defined in [CSS2] sections 8.6 and 9.10. The interaction of its features with other text operations in setting lines of text is described in CSS Text 3 § A Text Processing Order of Operations.

The computed values of the writing-mode, direction, and text-orientation properties (even on elements to which these properties themselves don’t apply [CSS-CASCADE-4]) are broadly able to influence the computed values of other, unrelated properties through calculations such as the computation of font-relative lengths or the cascade of flow-relative properties which purposefully depend on the computed writing mode or on font metrics that can depend on the writing mode.

1.2. Value Definitions and Terminology

This specification follows the CSS property definition conventions from [CSS2] using the value definition syntax from [CSS-VALUES-3]. Value types not defined in this specification are defined in CSS Values & Units [CSS-VALUES-3]. Combination with other CSS modules may expand the definitions of these value types.

In addition to the property-specific values listed in their definitions, all properties defined in this specification also accept the CSS-wide keywords as their property value. For readability they have not been repeated explicitly.

Other important terminology and concepts used in this specification are defined in [CSS2] and [CSS-TEXT-3].

2. Inline Direction and Bidirectionality

While the characters in most scripts are written from left to right, certain scripts are written from right to left. In some documents, in particular those written with the Arabic or Hebrew script, and in some mixed-language contexts, text in a single (visually displayed) block may appear with mixed directionality. This phenomenon is called bidirectionality, or "bidi" for short.

An example of bidirectional text is a Latin name in an Arabic
                 sentence. The sentence overall is typeset right-to-left, but
                 the letters in the Latin word in the middle are typeset
                 left-to-right.

Bidirectionality

The Unicode standard (Unicode Standard Annex #9) defines a complex algorithm for determining the proper ordering of bidirectional text. The algorithm consists of an implicit part based on character properties, as well as explicit controls for embeddings and overrides. CSS relies on this algorithm to achieve proper bidirectional rendering.

Two CSS properties, direction and unicode-bidi, provide explicit embedding, isolation, and override controls in the CSS layer. Because the base directionality of a text depends on the structure and semantics of the document, the direction and unicode-bidi properties should in most cases be used only to map bidi information in the markup to its corresponding CSS styles.

The HTML specifications ([HTML401], section 8.2, and HTML § 15.3.5 Bidirectional text) define bidirectionality behavior for HTML elements.

If a document language provides markup features to control bidi, authors and users should use those features instead and not specify CSS rules to override them.

2.1. Specifying Directionality: the direction property

Name: direction
Value: ltr | rtl
Initial: ltr
Applies to: all elements
Inherited: yes
Percentages: n/a
Computed value: specified value
Canonical order: n/a
Animation type: not animatable

Because HTML UAs can turn off CSS styling, we recommend HTML authors to use the HTML dir attribute and <bdo> element to ensure correct bidirectional layout in the absence of a style sheet. Authors should not use direction in HTML documents.

This property specifies the inline base direction or directionality of any bidi paragraph, embedding, isolate, or override established by the box. (See unicode-bidi.) In addition, it informs the ordering of table column layout, the direction of horizontal overflow, and the default alignment of text within a line, and other layout effects that depend on the box’s inline base direction.

Values for this property have the following meanings:

ltr
This value sets inline base direction (bidi directionality) to line-left-to-line-right.
rtl
This value sets inline base direction (bidi directionality) to line-right-to-line-left.

The direction property has no effect on bidi reordering when specified on inline boxes whose unicode-bidi value is normal, because the box does not open an additional level of embedding with respect to the bidirectional algorithm.

The direction property, when specified for table column boxes, is not inherited by cells in the column since columns are not the ancestors of the cells in the document tree. Thus, CSS cannot easily capture the "dir" attribute inheritance rules described in [HTML401], section 11.3.2.1.

2.2. Embeddings and Overrides: the unicode-bidi property

Name: unicode-bidi
Value: normal | embed | isolate | bidi-override | isolate-override | plaintext
Initial: normal
Applies to: all elements, but see prose
Inherited: no
Percentages: n/a
Computed value: specified value
Canonical order: per grammar
Animation type: not animatable

Because HTML UAs can turn off CSS styling, we recommend HTML authors to use the HTML dir attribute, <bdo> element, and appropriate distinction of text-level vs. grouping-level HTML element types to ensure correct bidirectional layout in the absence of a style sheet. Authors should not use unicode-bidi in HTML documents.

Normally (i.e. when unicode-bidi is normal) an inline box is transparent to the unicode bidi algorithm; content is ordered as if the box’s boundaries were not there. Other values of the unicode-bidi property cause inline boxes to create scopes within the algorithm, and to override the intrinsic directionality of text.

The following informative table summarizes the box-internal and box-external effects of unicode-bidi:

Effect of non-normal values of unicode-bidi on inline boxes
Outside
strong neutral
Inside scoped embed isolate
override bidi-override isolate-override
plaintext plaintext

Values for this property have the following (normative) meanings:

normal
The box does not open an additional level of embedding with respect to the bidirectional algorithm. For inline boxes, implicit reordering works across box boundaries.
embed
If the box is inline, this value creates a directional embedding by opening an additional level of embedding with respect to the bidirectional algorithm. The direction of this embedding level is given by the direction property. Inside the box, reordering is done implicitly.

This value has no effect on boxes that are not inline.

isolate
On an inline box, this bidi-isolates its contents. This is similar to a directional embedding (and increases the embedding level accordingly) except that each sequence of inline-level boxes uninterrupted by any block boundary or forced paragraph break is treated as an isolated sequence:
  • the content within the sequence is ordered as if inside an independent paragraph with the base directionality specified by the box’s direction property.
  • for the purpose of bidi resolution in its containing bidi paragraph, the sequence is treated as if it were a single Object Replacement Character (U+FFFC).
In effect, neither is the content inside the box bidi-affected by the content surrounding the box, nor is the content surrounding the box bidi-affected by the content or specified directionality of the box. However, forced paragraph breaks within the box still create a corresponding break in the containing paragraph.

This value has no effect on boxes that are not inline.

bidi-override
This value puts the box’s immediate inline content in a directional override. For an inline, this means that the box acts like a directional embedding in the bidirectional algorithm, except that reordering within it is strictly in sequence according to the direction property; the implicit part of the bidirectional algorithm is ignored. For a block container, the override is applied to an anonymous inline box that surrounds all of its content.
isolate-override
This combines the isolation behavior of isolate with the directional override behavior of bidi-override: to surrounding content, it is equivalent to isolate, but within the box content is ordered as if bidi-override were specified. It effectively nests a directional override inside an isolated sequence.
plaintext

This value behaves as isolate except that for the purposes of the Unicode bidirectional algorithm, the base directionality of each of the box’s bidi paragraphs (if a block container) or isolated sequences (if an inline) is determined by following the heuristic in rules P2 and P3 of the Unicode bidirectional algorithm (rather than by using the direction property of the box).

Following Unicode Bidirectional Algorithm clause HL3 [UAX9], values other than normal effectively insert the corresponding Unicode bidi control codes into the text stream at the start and end of the inline element before passing the paragraph to the Unicode bidirectional algorithm for reordering. (See § 2.4.2 CSS–Unicode Bidi Control Translation, Text Reordering.)

Bidi control codes injected by unicode-bidi at the start/end of display: inline boxes
unicode-bidi value direction value
ltr rtl
start end start end
normal
embed LRE (U+202A) PDF (U+202C) RLE (U+202B) PDF (U+202C)
isolate LRI (U+2066) PDI (U+2069) RLI (U+2067) PDI (U+2069)
bidi-override* LRO (U+202D) PDF (U+202C) RLO (U+202E) PDF (U+202C)
isolate-override* FSI,LRO (U+2068,U+202D) PDF,PDI (U+202C,U+2069) FSI,RLO (U+2068,U+202E) PDF,PDI (U+202C,U+2069)
plaintext FSI (U+2068) PDI (U+2069) FSI (U+2068) PDI (U+2069)
* The LRO/RLO+PDF pairs are also applied to the root inline box of a block container if these values of unicode-bidi were specified on the block container.

Because the unicode-bidi property does not inherit, setting bidi-override or plaintext on a block box will not affect any descendant blocks. Therefore these values are best used on blocks and inlines that do not contain any block-level structures.

Note that unicode-bidi does not affect the direction property even in the case of plaintext, and thus does not affect direction-dependent layout calculations.

Because the Unicode algorithm has a limit of 125 levels of embedding, care should be taken not to overuse unicode-bidi values other than normal. In particular, a value of inherit should be used with extreme caution in deeply nested inline markup. However, for elements that are, in general, intended to be displayed as blocks, a setting of unicode-bidi: isolate is preferred to keep the element together in case the display is changed to inline (see example below).

2.3. Example of Bidirectional Text

The following example shows an XML document with bidirectional text. It illustrates an important design principle: document language designers should take bidi into account both in the language proper (elements and attributes) and in any accompanying style sheets. The style sheets should be designed so that bidi rules are separate from other style rules, and such rules should not be overridden by other style sheets so that the document language’s bidi behavior is preserved.

In this example, lowercase letters stand for inherently left-to-right characters and uppercase letters represent inherently right-to-left characters. The text stream is shown below in logical backing store order.

<section dir=rtl>
  <para>HEBREW1 HEBREW2 english3 HEBREW4 HEBREW5</para>
  <para>HEBREW6 <emphasis>HEBREW7</emphasis> HEBREW8</para>
</section>
<section dir=ltr>
  <para>english9 english10 english11 HEBREW12 HEBREW13</para>
  <para>english14 english15 english16</para>
  <para>english17 <quote dir=rtl>HEBREW18 english19 HEBREW20</quote></para>
</section>

Since this is arbitrary XML, the style sheet is responsible for setting the writing direction. This is the style sheet:

/* Rules for bidi */
[dir=rtl] {direction: rtl; unicode-bidi: isolate; }
[dir=ltr] {direction: ltr; unicode-bidi: isolate; }

/* Rules for presentation */
section, para  {display: block;}
emphasis       {font-weight: bold;}
quote          {font-style: italic;}

If the line length is long, the formatting of this text might look like this:

               5WERBEH 4WERBEH english3 2WERBEH 1WERBEH

                                8WERBEH 7WERBEH 6WERBEH

english9 english10 english11 13WERBEH 12WERBEH

english14 english15 english16

english17 20WERBEH english19 18WERBEH

The first <section> element is a block with a right-to-left base direction, the second <section> element is a block with a left-to-right base direction. The <para>s are blocks that inherit the base direction from their parents. Thus, the first two <para>s are read starting at the top right, the final three are read starting at the top left.

The <emphasis> element is inline-level, and since its value for unicode-bidi is normal (the initial value), it has no effect on the ordering of the text.

The <quote> element, on the other hand, creates an isolated sequence with the given internal directionality. Note that this causes HEBREW18 to be to the right of english19.

If lines have to be broken, the same text might format like this:

       2WERBEH 1WERBEH
  -EH 4WERBEH english3
                 5WERB

   -EH 7WERBEH 6WERBEH
                 8WERB

english9 english10 en-
glish11 12WERBEH
13WERBEH

english14 english15
english16

english17 18WERBEH
20WERBEH english19

Notice that because HEBREW18 must be read before english19, it is on the line above english19. Just breaking the long line from the earlier formatting would not have worked.

Note also that the first syllable from english19 might have fit on the previous line, but hyphenation of left-to-right words in a right-to-left context, and vice versa, is usually suppressed to avoid having to display a hyphen in the middle of a line.

2.4. Applying the Bidirectional Reordering Algorithm

User agents that support bidirectional text must apply the Unicode bidirectional algorithm to every sequence of inline-level boxes uninterrupted by any block boundary or “bidi type Bforced paragraph break. This sequence forms the paragraph unit in the bidirectional algorithm.

2.4.1. Bidi Paragraph Embedding Levels

In CSS, the paragraph embedding level must be set (following UAX9 clause HL1) according to the direction property of the paragraph’s containing block rather than by the heuristic given in steps P2 and P3 of the Unicode algorithm.

There is, however, one exception: when the computed unicode-bidi of the paragraph’s containing block is plaintext, the Unicode heuristics in P2 and P3 are used as described in [UAX9], without the HL1 override.

2.4.2. CSS–Unicode Bidi Control Translation, Text Reordering

The final order of characters within each bidi paragraph is the same as if the bidi control codes had been added as described for unicode-bidi (above), markup had been stripped, and the resulting character sequence had been passed to an implementation of the Unicode bidirectional algorithm for plain text that produced the same line-breaks as the styled text.

Note that bidi control codes in the source text are still honored, and might not correspond to the document tree structure. This can split inlines or interfere with bidi start/end control pairing in interesting ways.

2.4.3. Bidi Treatment of Atomic Inlines

In this process, replaced elements with display: inline are treated as neutral characters, unless their unicode-bidi property is either embed or bidi-override, in which case they are treated as strong characters in the direction specified for the element. (This is so that, in case the replaced element falls back to rendering inlined text content, its bidi effect on the surrounding text is consistent with its replaced rendering.)

All other atomic inline-level boxes are treated as neutral characters always.

2.4.4. Paragraph Breaks Within Embeddings and Isolates

If an inline box is broken around a bidi paragraph boundary (e.g. if split by a block or forced paragraph break), then the HL3 bidi control codes assigned to the end of the box are also added before the interruption and the codes assigned to the start of the box are also added after it. (In other words, any embedding levels, isolates, or overrides started by the box are closed at the paragraph break and reopened on the other side of it.)

For example, where <BR/> is a forced paragraph break the bidi ordering is identical between

<para>...<i1><i2>...<BR/>...</i2></i1>...</para>

and

<para>...<i1><i2>...</i2></i1><BR/><i1><i2>...</i2></i1>...</para>

for all values of unicode-bidi on inline elements <i1> and <i2>.

Note that this behavior is applied by CSS for CSS-declared bidi controls applied to the box tree; it does not apply to Unicode’s bidi formatting controls, which are defined to terminate their effect at the end of the bidi paragraph.

2.4.5. Reordering-induced Box Fragmentation

Since bidi reordering can split apart and reorder text that is logically contiguous, bidirectional text can cause an inline box containing such text to be split and its fragments reordered within a line.

2.4.5.1. Conditions of Reordering-induced Box Fragmentation

When bidi reordering would split apart an inline box due to intervening content, the inline box is considered to be broken into multiple box fragments. [CSS-BREAK-3] The box is considered to be thus fragmented if it would be divided by intervening content on an infinitely long line, even if line breaking happens to result in both box fragments being placed adjacent to each other on the line. In such cases, the nearest common ancestor of text in the two box fragments (which determines certain aspects of text formatting such as tracking and justification between the two box fragments, see [CSS-TEXT-3]) is considered to be the nearest common ancestor of the two box fragments, not the inline box itself. However, an inline box is not considered to be broken into multiple box fragments due to bidi reordering if no intervening content would force it to split. (These rules maintain the integrity of an inline box where possible, while keeping bidi-induced fragmentation stable across variations in line-breaking.)

In the following example, where lowercase letters represent LTR letters and uppercase letters represent RTL letters, bidi reordering causes the <em>’s inline box to be divided into two box fragments separated by text outside the <em>.

Source code (logical order):

<p>here is <em>some MIXED</em> TEXT.</p>

Rendering (visual order) in a wide containing block, resulting in two inline box fragments separated by external content:

here is some TXET DEXIM.

Rendering (visual order) in a narrow containing block, resulting in two inline box fragments placed adjacent to each other:

here is some DEXIM
TXET.
By contrast, in this example, where the mixed-direction phrase is kept together with an isolation, only one fragment is generated—​the surrounding content will never split the <em>’s inline box even inside an infinitely-long containing block:

Source code (logical order):

<p>here is <em dir=rtl>some MIXED</em> TEXT.</p>

Rendering (visual order) in a wide containing block, resulting in one fragment:

here is some DEXIM TXET.

Rendering (visual order) in a narrow containing block, resulting in one fragment:

here is some DEXIM
TXET.
2.4.5.2. Box Model of Reordering-induced Box Fragments

For each line box, UAs must take the fragments of each inline box and assign the margins, borders and padding in visual order (not logical order). The start-most fragment on the first line box in which the box appears has the start edge’s margin, border, and padding; and the end-most fragment on the last line box in which the box appears has the end edge’s margin, border, and padding. For example, in the horizontal-tb writing mode:

Analogous rules hold for vertical writing modes.

The box-decoration-break property can override this behavior to draw box decorations on both sides of each fragment. [CSS-BREAK-3]

3. Vertical Writing Modes

In addition to extensions to CSS2.1’s support for bidirectional text, this module introduces the rules and properties needed to support vertical text layout in CSS.

3.1. Introduction to Vertical Writing

This subsection is non-normative.

Unlike languages that use the Latin script which are primarily laid out horizontally, Asian languages such as Chinese and Japanese can be laid out vertically. The Japanese example below shows the same text laid out horizontally and vertically. In the horizontal case, text is read from left to right, top to bottom. For the vertical case, the text is read top to bottom, right to left. Indentation from the left edge in the left-to-right horizontal case translates to indentation from the top edge in the top-to-bottom vertical case.

A comparison of horizontal and vertical Japanese shows that
                 although the lines rotate, the characters remain upright.
                 Some glyphs, however change: a period mark shifts from the
                 bottom left of its glyph box to the top right. Running
                 headers, however, may remain
                 laid out horizontally across the top of the page.

Comparison of vertical and horizontal Japanese: iBunko application (iOS)

For Chinese and Japanese lines are ordered either right to left or top to bottom, while for Mongolian and Manchu lines are ordered left to right.

The change from horizontal to vertical writing can affect not just the layout, but also the typesetting. For example, the position of a punctuation mark within its spacing box can change from the horizontal to the vertical case, and in some cases alternate glyphs are used.

Vertical text that includes Latin script text or text from other scripts normally displayed horizontally can display that text in a number of ways. For example, Latin words can be rotated sideways, or each letter can be oriented upright:

A dictionary definition for ヴィルス
                 might write the English word 'virus' rotated 90° clockwise,
                 but stack the letters of the initialisms 'RNA' and 'DNA' upright.

Examples of Latin in vertical Japanese: Daijirin Viewer 1.4 (iOS)

In some special cases such as two-digit numbers in dates, text is fit compactly into a single vertical character box:

An excerpt from MacFan shows several possible vertical layouts
                 for numbers: the two-digit month and day are written as
                 horizontal-in-vertical blocks; the years are written with
                 each character upright; except in the English phrase
                 “for Mac 2011”, where the date is rotated to
                 match the rotated Latin.

Mac Fan, December 2010, p.49

Layouts often involve a mixture of vertical and horizontal elements:

Magazines often mix horizontal and vertical layout; for
                 example, using one orientation for the main article text
                 and a different one for sidebar or illustrative content.

Mixture of vertical and horizontal elements

Vertical text layouts also need to handle bidirectional text layout; clockwise-rotated Arabic, for example, is laid out bottom-to-top.

3.2. Block Flow Direction: the writing-mode property

Name: writing-mode
Value: horizontal-tb | vertical-rl | vertical-lr | sideways-rl | sideways-lr
Initial: horizontal-tb
Applies to: All elements except table row groups, table column groups, table rows, table columns, ruby base containers, ruby annotation containers
Inherited: yes
Percentages: n/a
Computed value: specified value
Canonical order: n/a
Animation type: not animatable

This property specifies whether lines of text are laid out horizontally or vertically and the direction in which blocks progress. Possible values:

horizontal-tb
Top-to-bottom block flow direction. Both the writing mode and the typographic mode are horizontal.
vertical-rl
Right-to-left block flow direction. Both the writing mode and the typographic mode are vertical.
vertical-lr
Left-to-right block flow direction. Both the writing mode and the typographic mode are vertical.
sideways-rl
Right-to-left block flow direction. The writing mode is vertical, while the typographic mode is horizontal.
sideways-lr
Left-to-right block flow direction. The writing mode is vertical, while the typographic mode is horizontal.

The writing-mode property specifies the block flow direction, which determines the ordering direction of block-level boxes in a block formatting context; the ordering direction of line boxes in a block container that contains inlines; the ordering direction of rows in a table; etc. By virtue of determining the stacking direction of line boxes, the writing-mode property also determines whether the line boxes' orientation (and thus the writing mode) is horizontal or vertical. The text-orientation property then determines how text is laid out within the line box.

The content of replaced elements do not rotate due to the writing mode: images and external content such as from <iframe>s, for example, remain upright, and the default object size of 300px×150px does not re-orient. However embedded replaced content involving text (such as MathML content or form elements) should match the replaced element’s writing mode and line orientation if the UA supports such a vertical writing mode for the replaced content.

In the following example, two block elements (1 and 3) separated by an image (2) are presented in various flow writing modes.

Here is a diagram of horizontal writing mode (writing-mode: horizontal-tb):

Diagram of horizontal layout: blocks 1, 2, and 3 are stacked top-to-bottom

Here is a diagram for the right-to-left vertical writing mode commonly used in East Asia (writing-mode: vertical-rl):

Diagram of a right-to-left vertical layout: blocks 1, 2,
                  and 3 are arranged side by side from right to left

And finally, here is a diagram for the left-to-right vertical writing mode used for Manchu and Mongolian (writing-mode: vertical-lr):

Diagram of left-to-right vertical layout: blocks 1, 2,
                  and 3 are arranged side by side from left to right

In the following example, some form controls are rendered inside a block with vertical-rl writing mode. The form controls are rendered to match the writing mode.

<style>
  form { writing-mode: vertical-rl; }
</style>
...
<form>
<p><label>姓名 <input value="艾俐俐"></label>
<p><label>语言 <select><option>English
                       <option>français
                       <option>فارسی
                       <option>中文
                       <option>日本語</select></label>
</form>

Screenshot of vertical layout: the input element is
                laid lengthwise from top to bottom and its contents
                rendered in a vertical typographic mode, matching the
                labels outside it. The drop-down selection control
                after it slides out to the side (towards the after
                edge of the block) rather than downward as it would
                in horizontal writing modes.

If a box has a different writing-mode value than its parent box (i.e. nearest ancestor without display: contents):

As all other inherited CSS properties do, the writing-mode property inherits to SVG elements inlined (rather than linked) into the source document. This could cause unintentional side effects when, for example, an SVG image designed only for horizontal flow was embedded into a vertical flow document.

Authors can prevent this from happening by adding the following rule:

svg { writing-mode: initial; }

3.2.1. Obsolete SVG1.1 writing-mode Values

SVG1.1 [SVG11] defines some additional values: lr, lr-tb, rl, rl-tb, tb, and tb-rl.

These values are obsolete in any context except SVG1 documents and are therefore optional for non-SVG UAs.

3.2.1.1. Supporting SVG1.1 writing-mode values in CSS syntax

UAs that wish to support these values in the context of CSS must compute them as follows:

Mapping of Obsolete SVG1.1 writing-mode values to modern CSS
Specified Computed
lr horizontal-tb
lr-tb
rl
rl-tb
tb vertical-rl
tb-rl

The SVG1.1 values were also present in an older of the CSS writing-mode specification, which is obsoleted by this specification. The additional tb-lr value of that revision is replaced by vertical-lr.

3.2.1.2. Supporting SVG1.1 writing-mode values in presentational attributes

In order to support legacy content with presentational attributes, and to allow authors to create documents that support older clients, SVG UAs must add the following style sheet rules to their default UA stylesheet:

@namespace svg "http://www.w3.org/2000/svg";
svg|*[writing-mode=lr], svg|*[writing-mode=lr-tb],
svg|*[writing-mode=rl], svg|*[writing-mode=rl-tb] {
  writing-mode: horizontal-tb; }
svg|*[writing-mode=tb], svg|*[writing-mode=tb-rl] {
  writing-mode: vertical-rl; }
Authors who wish to create forwards and backwards-compatible SVG content in CSS syntax can use the CSS forwards-compatible parsing rules to do so, e.g.
svg|text { writing-mode: tb; writing-mode: vertical-rl; }

4. Inline-level Alignment

When different kinds of inline-level content are placed together on a line, the baselines of the content and the settings of the vertical-align property control how they are aligned in the transverse direction of the line box. This section discusses what baselines are, how to find them, and how they are used together with the vertical-align property to determine the alignment of inline-level content.

4.1. Introduction to Baselines

This section is non-normative.

A baseline is a line along the inline axis of a line box along which individual glyphs of text are aligned. Baselines guide the design of glyphs in a font (for example, the bottom of most alphabetic glyphs typically align with the alphabetic baseline), and they guide the alignment of glyphs from different fonts or font sizes when typesetting.

Picture of alphabetic text in two font sizes with the baseline and em-boxes

Alphabetic text in two font sizes with the baseline and em-boxes

Different writing systems prefer different baseline tables.

Latin prefers the alphabetic baseline, on top of which most
                 letters rest, though some have descenders that dangle below it.
                 Indic scripts are sometimes typeset with a hanging baseline,
                 since their glyph shapes appear to be hanging from a
                 horizontal line.
                 Han-based systems, whose glyphs are designed to fill a square,
                 tend to align on their bottoms.

Preferred baselines in various writing systems

A well-constructed font contains a baseline table, which indicates the position of one or more baselines within the font’s design coordinate space. (The design coordinate space is scaled with the font size.)

In a well-designed mixed-script font, the glyphs are positioned in the coordinate space to harmonize with one another when typeset together. The baseline table is then constructed to match the shape of the glyphs, each baseline positioned to match the glyphs from its preferred scripts.

The baseline table is a property of the font, and the positions of the various baselines apply to all glyphs in the font.

Different baseline tables can be provided for alignment in horizontal and vertical text. UAs should use the vertical tables in vertical typographic modes and the horizontal tables otherwise.

4.2. Text Baselines

In this specification, only the following baselines are considered:

alphabetic
The alphabetic baseline, which typically aligns with the bottom of uppercase Latin glyphs.
central
The ideographic central baseline, which typically crosses the center of the em box. If the font is missing this baseline, it is assumed to be halfway between the ascender (over) and descender (under) edges of the ideographic em box.

In vertical typographic mode, the central baseline is used as the dominant baseline when text-orientation is mixed or upright. Otherwise the alphabetic baseline is used.

A future CSS module will deal with baselines in more detail and allow the choice of other dominant baselines and alignment options.

4.3. Atomic Inline Baselines

If an atomic inline (such as an inline-block, inline-table, or replaced inline element) does not have a baseline, then the UA synthesizes a baseline table thus:

alphabetic
The alphabetic baseline is assumed to be at the under margin edge.
central
The central baseline is assumed to be halfway between the under and over margin edges of the box.

The vertical-align property in [CSS2] defines the baseline of inline-table and inline-block boxes with some exceptions.

4.4. Baseline Alignment

The dominant baseline (which can change based on the typographic mode) is used in CSS for alignment in two cases:

5. Introduction to Vertical Text Layout

Each writing system has one or more native orientations. Modern scripts can therefore be classified into three orientational categories:

horizontal-only
Scripts that have horizontal, but not vertical, native orientation. Includes: Latin, Arabic, Hebrew, Devanagari
vertical-only
Scripts that have vertical, but not horizontal, native orientation. Includes: Mongolian, Phags Pa
bi-orientational
Scripts that have both vertical and horizontal native orientation. Includes: Han, Hangul, Japanese Kana

A vertical script is one that has a native vertical orientation: i.e. one that is either vertical-only or that is bi-orientational. A horizontal script is one that has a native horizontal orientation: i.e. one that is either horizontal-only or that is bi-orientational. (See Appendix A for a categorization of scripts by native orientation.)

A Venn diagram of these distinctions would show two circles:
                     one labelled 'vertical', the other 'horizontal'. The overlapped
                     region would represent the bi-orientational scripts, while
                     horizontal-only and vertical-only scripts would occupy their
                     respective circles' exclusive regions.

In modern typographic systems, all glyphs are assigned a horizontal orientation, which is used when laying out text horizontally. To lay out vertical text, the UA needs to transform the text from its horizontal orientation. This transformation is the bi-orientational transform, and there are two types:

rotate
Rotate the glyph from horizontal to vertical Rotate the glyph from horizontal to vertical
translate
Translate the glyph from horizontal to vertical Translate the glyph from horizontal to vertical

Scripts with a native vertical orientation have an intrinsic bi-orientational transform, which orients them correctly in vertical text: most CJK (Chinese/Japanese/Korean) characters translate, that is, they are always upright. Characters from other scripts, such as Mongolian, rotate.

Scripts without a native vertical orientation can be either rotated (set sideways) or translated (set upright): the transform used is a stylistic preference depending on the text’s usage, rather than a matter of correctness. The text-orientation property’s mixed and upright values are provided to specify rotation vs. translation of horizontal-only text.

5.1. Orienting Text: the text-orientation property

Name: text-orientation
Value: mixed | upright | sideways
Initial: mixed
Applies to: all elements except table row groups, rows, column groups, and columns; and text
Inherited: yes
Percentages: n/a
Computed value: specified value
Canonical order: n/a
Animation type: not animatable

This property specifies the orientation of text within a line. Current values only have an effect in vertical typographic modes: the property has no effect in horizontal typographic modes.

Values have the following meanings:

mixed

Typographic character units from horizontal-only scripts are typeset sideways, i.e. 90° clockwise from their standard orientation in horizontal text. Typographic character units from vertical scripts are typeset with their intrinsic orientation. See Vertical Orientations for further details.

This value is typical for layout of dominantly vertical-script text.

upright

Typographic character units from horizontal-only scripts are typeset upright, i.e. in their standard horizontal orientation. Typographic character units from vertical scripts are typeset with their intrinsic orientation and shaped normally. See Vertical Orientations for further details.

This value causes the used value of direction to be ltr, and for the purposes of bidi reordering, causes all characters to be treated as strong LTR.

Note: The used value, rather than the computed value, of direction is influenced so that rtl can inherit properly into any descendants (such as the contents of a horizontal inline-block) where this directional override does not apply.

sideways

Causes all text to be typeset sideways, as if in a horizontal layout, but rotated 90° clockwise.

text-orientation: mixed text-orientation: upright text-orientation: sideways
mixed upright sideways

text-orientation values (writing-mode is vertical-rl)

Changing the value of this property may affect inline-level alignment. Refer to Text Baselines for more details.

UAs may accept sideways-right as a value that computes to sideways if needed for backward compatibility reasons.

As of writing, major implementations do not support the automatic LTR treatment of RTL characters for upright typesetting. In such cases, authors may need to explicitly specify unicode-bidi and direction as in the following example:
.vertical-upright-hebrew {
    writing-mode: vertical-rl;
    text-orientation: upright;
    unicode-bidi: bidi-override;
    direction: ltr;
}

5.1.1. Vertical Typesetting and Font Features

When typesetting text in vertical-rl and vertical-lr modes, text is typeset either “upright” or “sideways” as defined below:

upright typesetting
Typographic character units are individually typeset upright in vertical lines with vertical font metrics. The UA must synthesize vertical font metrics for fonts that lack them. (This specification does not define heuristics for synthesizing such metrics.) Additionally, font features (such as alternate glyphs and other transformation) intended for use in vertical typesetting must be used. (E.g. the OpenType vert feature must be enabled.) Furthermore, characters from horizontal cursive scripts (such as Arabic) are shaped in their isolated forms when typeset upright.

Note that even when typeset “upright”, some glyphs should appear rotated. For example, dashes and enclosing punctuation should be oriented relative to the inline axis. In OpenType, this is typically handled by glyph substitution, although not all fonts have alternate glyphs for all relevant codepoints. (East Asian fonts usually provide alternates for East Asian codepoints, but Western fonts typically lack any vertical typesetting features and East Asian fonts typically lack vertical substitutions for Western codepoints.) Unicode published draft data on which characters should appear sideways as the SVO property in this data file; however, this property has been abandoned for the current revision of [UAX50].

Typographic character units which are classified as Tr or Tu in [UAX50] are expected to have alternate glyphs or positioning for typesetting upright in vertical text. In the case of Tr characters, if such vertical alternate glyphs are missing from the font, the UA may wish to [RFC6919] (but is not expected to) synthesize the missing glyphs by typesetting them sideways etc.

sideways typesetting
Typographic character units typeset as a run rotated 90° clockwise from their upright orientation, using horizontal metrics and composition, and vertical typesetting features are not used. However, if the font has features meant to be enabled for sideways text that is typeset in vertical lines (e.g. to adjust brush stroke angles or alignment), those features are used. (An example of such a feature would be the proposed vrtr OpenType font feature.)

5.1.2. Mixed Vertical Orientations

[[!UAX50]] defines the Vertical_Orientation property for the default glyph orientation of mixed-orientation vertical text. When text-orientation is mixed, the UA must determine the orientation of each typographic character unit by its Vertical_Orientation property: typesetting it upright if its orientation property is U, Tu, or Tr; or typesetting it sideways (90° clockwise from horizontal) if its orientation property is R.

Note that UAX50 does not handle scripts that rotate -90° in vertical contexts, so they will not be typeset correctly with mixed orientation. Use sideways-lr for such scripts.

The OpenType vrt2 feature, which is intended for mixed-orientation typesetting, is not used by CSS. It delegates the responsibility for orienting glyphs to the font designer. CSS instead dictates the orientation through [[!UAX50]] and orients glyphs by typesetting them sideways or upright as appropriate.

5.1.3. Obsolete: the SVG1.1 glyph-orientation-vertical property

Name: glyph-orientation-vertical
Value: auto | 0deg | 90deg | 0 | 90
Initial: n/a
Applies to: n/a
Inherited: n/a
Percentages: n/a
Computed value: n/a
Canonical order: n/a
Animation type: n/a

Some SVG user agents will need to process documents containing the obsolete SVG glyph-orientation-vertical property, which was defined to accept an auto keyword as well as <angle> and <integer> values representing multiples of 90°. While supporting this property is optional, UAs that do so must alias glyph-orientation-vertical as a shorthand of text-orientation as follows:

Shorthand glyph-orientation-vertical value Longhand text-orientation value
auto mixed
0deg upright
0 upright
90deg sideways
90 sideways

UAs must ignore and treat as invalid any other values for the glyph-orientation-vertical property; and treat as invalid the glyph-orientation-horizontal property in its entirety.

Note: The 180deg and 270deg values, the radian and gradian values, and the glyph-orientation-horizontal property are not mapped because they have no known use cases nor significant amounts of dependent content, and are therefore not part of CSS, and have been likewise dropped from SVG.

6. Abstract Box Terminology

CSS2.1 [[!CSS2]] defines the box layout model of CSS in detail, but only for the horizontal-tb writing mode. Layout is analogous in writing modes other than horizontal-tb; however directional and dimensional terms in CSS2.1 must be abstracted and remapped appropriately.

This section defines abstract directional and dimensional terms and their mappings in order to define box layout for other writing modes, and to provide terminology for future specs to define their layout concepts abstractly. (The next section explains how to apply them to CSS2.1 layout calculations and how to handle orthogonal flows.) Although they derive from the behavior of text, these abstract mappings exist even for boxes that do not contain any line boxes: they are calculated directly from the values of the writing-mode and direction properties.

There are three sets of directional terms in CSS:

physical
Interpreted relative to the page, independent of writing mode. The physical directions are left, right, top, and bottom.
flow-relative
Interpreted relative to the flow of content. The flow-relative directions are start and end, or block-start, block-end, inline-start, and inline-end if the dimension is also ambiguous.
line-relative
Interpreted relative to the orientation of the line box. The line-relative directions are line-left, line-right, line-over, and line-under.

The physical dimensions are width and height, which correspond to measurements along the x-axis (horizontal dimension) and y-axis (vertical dimension), respectively. Abstract dimensions are identical in both flow-relative and line-relative terms, so there is only one set of these terms.

Physical & flow-relative terms as applicable to typical English text layout
Physical & flow-relative terms as applicable to vertical Chinese text layout

Note: [[CSS-FLEXBOX-1]] also defines flex-relative terms, which are used in describing flex layout.

6.1. Abstract Dimensions

The abstract dimensions are defined below:

block dimension
The dimension perpendicular to the flow of text within a line, i.e. the vertical dimension in horizontal writing modes, and the horizontal dimension in vertical writing modes.
inline dimension
The dimension parallel to the flow of text within a line, i.e. the horizontal dimension in horizontal writing modes, and the vertical dimension in vertical writing modes.
block axis
The axis in the block dimension, i.e. the vertical axis in horizontal writing modes and the horizontal axis in vertical writing modes.
inline axis
The axis in the inline dimension, i.e. the horizontal axis in horizontal writing modes and the vertical axis in vertical writing modes.
block size
logical height
A measurement in the block dimension: refers to the physical height (vertical dimension) in horizontal writing modes, and to the physical width (horizontal dimension) in vertical writing modes.
inline size
logical width
A measurement in the inline dimension: refers to the physical width (horizontal dimension) in horizontal writing modes, and to the physical height (vertical dimension) in vertical writing modes.

6.2. Flow-relative Directions

The flow-relative directions, block-start, block-end, inline-start, and inline-end, are defined relative to the flow of content on the page. In an LTR horizontal-tb writing mode, they correspond to the top, bottom, left, and right directions, respectively. They are defined as follows:

block-start
The side that comes earlier in the block flow direction, as determined by the writing-mode property: the physical top in horizontal-tb mode, the right in vertical-rl, and the left in vertical-lr.
block-end
The side opposite block-start.
inline-start
The side from which text of the inline base direction would start. For boxes with a used direction value of ltr, this means the line-left side. For boxes with a used direction value of rtl, this means the line-right side.
inline-end
The side opposite start.

Where contextually unambiguous or encompassing both meanings, the terms start and end are used in place of block-start/inline-start and block-end/inline-end, respectively.

Note that while determining the block-start and block-end sides of a box depends only on the writing-mode property, determining the inline-start and inline-end sides of a box depends not only on the writing-mode property but also the direction property.

6.3. Line-relative Directions

The line orientation determines which side of a line box is the logical “top” (ascender side). It is given by the writing-mode property. Usually the line-relative “top” corresponds to the block-start side, but this is not always the case: in Mongolian typesetting (and thus by default in vertical-lr writing modes), the line-relative “top” corresponds to the block-end side. Hence the need for distinct terminology.

Mongolian mixed with English

A primarily Mongolian document, such as the one above, is written in vertical lines stacking left to right, but lays its Latin text with the tops of the glyphs towards the right. This makes the text run in the same inline direction as Mongolian (top-to-bottom) and face the same direction it does in other East Asian layouts (which have vertical lines stacking right to left), but the glyphs' tops are facing the bottom of the line stack rather than the top, which in an English paragraph would be upside-down. (See this Diagram of Mongolian Text Layout.)

In addition to a line-relative “top” and “bottom” to map things like 'vertical-align: top', CSS also needs to refer to a line-relative “left” and “right” in order to map things like text-align: left. Thus there are four line-relative directions, which are defined relative to the line orientation as follows:

over or line-over
Nominally the side that corresponds to the ascender side or “top” side of a line box. (The side overlines are typically drawn on.)
under or line-under
Opposite of over: the line-relative “bottom” or descender side. (The side underlines are typically drawn on.)
line-left
The line-relative "left" side of a line box, which is nominally the side from which LTR text would start.
line-right
The line-relative "right" side of a line box, which is nominally the side from which RTL text would start. (Opposite of line-left.)

See the table below for the exact mappings between physical and line-relative directions.

Line orientation compass

Line orientation in horizontal-tb

Typical orientation in vertical

Line orientation in vertical-rl, vertical-lr, and sideways-rl

Typical orientation in vertical

Line orientation in sideways-lr

Baseline of an upright glyph is drawn vertically from the top center

Vertical baseline of an upright glyph

When text-orientation: upright, the baseline is still vertical, and the vertical baseline in the font is used, or the vertical baseline is synthesized if the font does not provide.

Since the baseline is vertical, the definitions for mixed or sideways above still apply; i.e., line-over is on right, and line-under is on left.

This is in line with font systems such as OpenType which defines the ascender on right and the descender on left in their vertical metrics.

6.4. Abstract-to-Physical Mappings

The following table summarizes the abstract-to-physical mappings (based on the used direction and writing-mode):

Abstract-Physical Mapping
writing-mode horizontal-tb vertical-rl, sideways-rl vertical-lr sideways-lr
direction ltr rtl ltr rtl ltr rtl ltr rtl
block-size height width
inline-size width height
block-start top right left
block-end bottom left right
inline-start left right top bottom top bottom bottom top
inline-end right left bottom top bottom top top bottom
over top right left
under bottom left right
line-left left top bottom
line-right right bottom top

Note: The used direction depends on the computed writing-mode and text-orientation: in vertical writing modes, a text-orientation value of upright forces the used direction to ltr.

7. Abstract Box Layout

7.1. Principles of Layout in Vertical Writing Modes

CSS box layout in vertical writing modes is analogous to layout in the horizontal writing modes, following the principles outlined below:

Layout calculation rules (such as those in CSS2.1, Section 10.3) that apply to the horizontal dimension in horizontal writing modes instead apply to the vertical dimension in vertical writing modes. Likewise, layout calculation rules (such as those in CSS2.1, Section 10.6) that apply to the vertical dimension in horizontal writing modes instead apply to the horizontal dimension in vertical writing modes. Thus: