sodcalculator

10 Tech How-To

CSS Text Orientation: How to Control Text Direction

Guide 10-56267 · Updated · Step by step

CSS text orientation controls the rotation and direction of text characters within a line, especially in vertical writing modes. You set it with the text-orientation property, which works alongside writing-mode to determine whether text runs upright, sideways, or in a mixed orientation. This guide explains the property, its values, how it interacts with other CSS features, and common pitfalls.

Background: Why Text Orientation Matters

Most web content is written horizontally, left to right. But East Asian languages like Japanese and Chinese are frequently set vertically, and even Latin scripts sometimes appear in vertical layouts for design or signage. The CSS Writing Modes specification introduced properties to handle these layouts. text-orientation specifically controls the rotation of individual glyphs when the line itself is vertical (e.g., writing-mode: vertical-rl). Without it, browsers have default behaviors that may not match your intent, particularly for Latin text, numbers, or punctuation.

How the Property Works

The text-orientation property applies to text within a vertical writing mode. Its main values are:

  • mixed (default): Horizontal scripts (like Latin) rotate 90° clockwise, while vertical scripts (like CJK) remain upright. This is the standard for mixed-language vertical text.
  • upright: All characters are laid out upright, meaning Latin letters and numbers are not rotated. This is often used for headings or short labels where readability is key.
  • sideways: All characters are rotated 90° clockwise, as if the whole line were turned. This is similar to writing-mode: sideways-lr but within a vertical-rl context.
  • sideways-right: An alias for sideways in vertical writing modes; it is the same as sideways.
  • use-glyph-orientation: A legacy value that forces the browser to use the deprecated glyph-orientation-vertical SVG property. It is not recommended for new work.

For example, with writing-mode: vertical-rl and text-orientation: upright, the word “Hello” appears as H-e-l-l-o from top to bottom, each letter upright. With mixed, it appears as “Hello” rotated 90° clockwise, so the top of the letters points to the right.

Choosing the Right Value

Selecting the correct value depends on your content and design goals:

  • For traditional Japanese or Chinese vertical text, use mixed (the default) to keep CJK characters upright while Latin and numbers rotate.
  • For vertical Latin text that must remain readable without tilting your head, use upright. This is common for labels on spines or vertical navigation.
  • For a purely stylistic rotated look, sideways is simpler and often preferable to rotating the whole element with transform, because it keeps the layout flow intact.

Interaction with Other CSS Properties

text-orientation does not work alone. It requires a vertical writing-mode to have any effect. The relevant writing modes are:

  • vertical-rl: Lines run top-to-bottom, and the next line is to the left.
  • vertical-lr: Lines run top-to-bottom, and the next line is to the right.
  • sideways-rl and sideways-lr: These are shorthand that force text-orientation: sideways regardless of other settings.

Also, text-combine-upright (often used with upright) lets you combine multiple characters into a single upright square, like “10” in Japanese vertical text. For example, text-combine-upright: all makes the digits “10” appear as a two-digit number in one character cell.

Common Problems and Misconceptions

One frequent mistake is expecting text-orientation to work on horizontal text. It does nothing unless the writing mode is vertical. Another is confusing text-orientation with direction (which controls LTR/RTL) or unicode-bidi (which handles bidirectional text). They are separate properties.

Misconception: upright makes all characters upright, but punctuation and symbols may still rotate depending on the font and browser. For full control, you may need to wrap such characters in spans with text-orientation: upright or mixed individually.

Also, browser support is generally good for the main values, but older browsers may not support sideways or use-glyph-orientation. Always test in your target browsers.

Comparison with Transform and Writing Modes

You might be tempted to rotate text using transform: rotate(90deg). That works visually but does not affect layout flow, so the element still occupies its original space, often causing overlap or misalignment. text-orientation works within the layout, so the line box and the text flow correctly. For vertical text, using writing-mode plus text-orientation is the cleanest approach.

Compare writing-mode: vertical-rl with text-orientation: sideways versus writing-mode: sideways-rl. The latter is a shorthand that forces sideways orientation, which is equivalent but more concise if you only need that.

Practical Examples

Here are a few real-world snippets:

  1. Vertical Japanese with Latin: writing-mode: vertical-rl; text-orientation: mixed; – CJK upright, Latin rotated.
  2. Vertical English label: writing-mode: vertical-rl; text-orientation: upright; – every letter upright, reading top to bottom.
  3. Sideways heading: writing-mode: vertical-rl; text-orientation: sideways; – the whole line rotated 90° clockwise.

Remember that text-orientation is inherited, so you can set it on a container to affect all descendants.

Frequently Asked Questions

Does text-orientation work on horizontal text?

No. The property only has an effect when the writing mode is vertical (vertical-rl, vertical-lr, or sideways). On horizontal text, it is ignored.

What is the difference between text-orientation and writing-mode?

writing-mode sets the direction of lines (horizontal or vertical) and the block flow direction. text-orientation controls how individual characters are rotated within those lines. You need both to get the desired vertical text layout.

How do I make numbers appear upright in vertical text?

Use text-orientation: upright on the element containing the numbers. If you want a two-digit number to stay together in one square, also apply text-combine-upright: all.

Is text-orientation supported in all browsers?

Modern browsers support mixed, upright, and sideways. Legacy values like use-glyph-orientation have limited support. Check Can I Use for the latest details.

Can I use text-orientation with CSS columns or flexbox?

Yes, it works inside any layout context as long as the writing mode is vertical. However, be aware that flex or grid may affect the alignment of the text block; test accordingly.

Does text-orientation affect line height or spacing?

It can. Upright text often requires more vertical space per character than sideways text, because characters are not rotated. Browsers handle this automatically, but you may need to adjust line-height for optimal appearance.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →