Most demos need a newer browser

They use :has() and container queries. Update your browser, or on an iPhone update iOS to 16.4 or later.

CSS Vertical Text

CSS vertical text with writing-mode: vertical-rl and sideways-lr for table headers, edge labels, and book spines where horizontal text would not fit.

Level
Beginner
Published
Updated
Reading time
8 min

Try it

4 live demos

Section 02

Setup guide

The label runs up the edge, so it names the section without using a line of the card.

Edge label, sideways-lr
Field guide Cookbook Short stories Atlas Poems Letters
Book spines, vertical-rl
Hours Monday Tuesday Wednesday Thursday Friday
Design32412
Build45364
Review11112
Table headers, sideways-lr

Three places vertical text earns its keep

Other ways to build it

Quarterly report
transform: rotate(-90deg)
Quarterly report
writing-mode: sideways-lr

writing-mode versus rotate

See the code

Open

text-orientation: mixed

Open

text-orientation: upright

Upright letters

See the code

縦書き

縦書きの見本です。行は右から左へ進みます。数字の12は一文字分に収まります。

Vertical Japanese

See the code

Build it

8 snippets to copy

CSS Vertical Text

HTML

<div class="vt-trio">
  <figure class="vt-item">
    <div class="vt-card">
      <span class="vt-edge">Section 02</span>
      <div class="vt-body">
        <p class="vt-body-title">Setup guide</p>
        <p class="vt-body-text">The label runs up the edge, so it names the section without using a line of the card.</p>
      </div>
    </div>
    <figcaption>Edge label, sideways-lr</figcaption>
  </figure>
  <figure class="vt-item">
    <div class="vt-shelf">
      <span class="vt-spine">Field guide</span>
      <span class="vt-spine">Cookbook</span>
      <span class="vt-spine">Short stories</span>
      <span class="vt-spine">Atlas</span>
      <span class="vt-spine">Poems</span>
      <span class="vt-spine">Letters</span>
    </div>
    <figcaption>Book spines, vertical-rl</figcaption>
  </figure>
  <figure class="vt-item">
    <table class="vt-table">
      <thead>
        <tr>
          <th scope="col">Hours</th>
          <th scope="col">Monday</th>
          <th scope="col">Tuesday</th>
          <th scope="col">Wednesday</th>
          <th scope="col">Thursday</th>
          <th scope="col">Friday</th>
        </tr>
      </thead>
      <tbody>
        <tr><th scope="row">Design</th><td>3</td><td>2</td><td>4</td><td>1</td><td>2</td></tr>
        <tr><th scope="row">Build</th><td>4</td><td>5</td><td>3</td><td>6</td><td>4</td></tr>
        <tr><th scope="row">Review</th><td>1</td><td>1</td><td>1</td><td>1</td><td>2</td></tr>
      </tbody>
    </table>
    <figcaption>Table headers, sideways-lr</figcaption>
  </figure>
</div>

CSS

.vt-trio {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12.5rem, 1fr));
  align-items: end;
  gap: 2rem 1.5rem;
  width: 100%;
  max-width: 48rem;
}

.vt-item {
  display: grid;
  justify-items: center;
  gap: .7rem;
  margin: 0;
}

.vt-item figcaption {
  font-family: monospace;
  font-size: .75rem;
  color: #88888f;
}

/* 1. a section label down the edge of a card, read bottom to top */
.vt-card {
  display: flex;
  width: 100%;
  max-width: 15rem;
  height: 11rem;
  overflow: hidden;
  border: 1px solid #2a2a2d;
  border-radius: 12px;
  background: #1c1c1e;
}

/* the fallback: top to bottom, then turned over so it reads
   upward. rotate keeps the box where it was; at 180deg the
   box is the same shape, so nothing around it moves. */
.vt-edge {
  writing-mode: vertical-rl;
  rotate: 180deg;
  padding: .9rem .5rem;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: #0c0c0d;
  background: #57d9a3;
}

.vt-body {
  padding: 1rem 1.1rem;
}

.vt-body-title {
  margin: 0 0 .4rem;
  font-weight: 700;
  color: #f0f0f0;
}

.vt-body-text {
  margin: 0;
  font-size: .85rem;
  line-height: 1.55;
  color: #88888f;
}

/* 2. a shelf of spines, read top to bottom like a book
   standing on a shelf */
.vt-shelf {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 11rem;
  padding: 0 .6rem;
  border-bottom: 8px solid #8a5a3c;
  border-radius: 0 0 4px 4px;
}

/* in vertical-rl, height is the length of the line and
   the side padding sets the thickness of the book */
.vt-spine {
  writing-mode: vertical-rl;
  box-sizing: border-box;
  height: var(--vt-h, 85%);
  padding: .8rem var(--vt-pad, .5rem);
  border-radius: 3px 3px 0 0;
  font-size: .8rem;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
  color: #0c0c0d;
  background: var(--vt-c, #38bdf8);
  box-shadow: inset 0 .45rem 0 rgba(0, 0, 0, .16), inset 0 -.45rem 0 rgba(0, 0, 0, .16);
}

.vt-spine:nth-child(1) { --vt-h: 86%; --vt-c: #38bdf8; }
.vt-spine:nth-child(2) { --vt-h: 72%; --vt-c: #ffd444; --vt-pad: .7rem; }
.vt-spine:nth-child(3) { --vt-h: 94%; --vt-c: #f472b6; }
.vt-spine:nth-child(4) { --vt-h: 66%; --vt-c: #57d9a3; --vt-pad: .4rem; }
.vt-spine:nth-child(5) { --vt-h: 82%; --vt-c: #c084fc; --vt-pad: .65rem; }
.vt-spine:nth-child(6) { --vt-h: 78%; --vt-c: #ff9040; }

/* 3. table headers that run upward, so columns of short
   numbers stay narrow */
.vt-table {
  border-collapse: collapse;
  font-size: .85rem;
  color: #f0f0f0;
}

.vt-table th,
.vt-table td {
  padding: .4rem .55rem;
  border: 1px solid #2a2a2d;
}

.vt-table thead th {
  vertical-align: bottom;
  font-weight: 600;
  text-align: left;
}

.vt-table thead th + th {
  writing-mode: vertical-rl;
  rotate: 180deg;
  padding: .55rem .4rem;
}

.vt-table td {
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.vt-table tbody th {
  font-weight: 600;
  text-align: left;
}

/* where sideways-lr exists it reads upward on its own,
   with no turn */
@supports (writing-mode: sideways-lr) {
  .vt-edge,
  .vt-table thead th + th {
    writing-mode: sideways-lr;
    rotate: none;
  }
}

writing-mode versus rotate

Two rows, each with a purple label and a striped box after it. The dashed coral outline shows the space the label holds in the layout. The rotated label paints as 41.6 by 150 pixels but its layout box stays 150 by 42, so the text spills out above and below the slot and the striped box starts only 158 pixels in. The writing-mode version measures 48 by 144 in the layout itself, the slot wraps it exactly, and the next item starts 56 pixels in with no overlap. Pick writing-mode whenever the vertical text sits in a layout. Use rotate only for decoration that is positioned on its own and must not affect anything around it.

HTML

<div class="vt-compare">
  <figure class="vt-case">
    <div class="vt-row">
      <span class="vt-slot"><span class="vt-tab vt-rotated">Quarterly report</span></span>
      <span class="vt-next"></span>
    </div>
    <figcaption>transform: rotate(-90deg)</figcaption>
  </figure>
  <figure class="vt-case">
    <div class="vt-row">
      <span class="vt-slot"><span class="vt-tab vt-turned">Quarterly report</span></span>
      <span class="vt-next"></span>
    </div>
    <figcaption>writing-mode: sideways-lr</figcaption>
  </figure>
</div>

CSS

.vt-compare {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 1.5rem;
  width: 100%;
  max-width: 40rem;
}

.vt-case {
  display: grid;
  gap: .6rem;
  margin: 0;
}

.vt-case figcaption {
  font-family: monospace;
  font-size: .75rem;
  color: #88888f;
}

/* a row with something after the label, so the space the
   label takes is plain to see */
.vt-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  height: 11rem;
  padding: 0 .75rem;
  border: 1px solid #2a2a2d;
  border-radius: 10px;
  background: #1c1c1e;
}

/* the dashed box is the space the label holds in the
   layout. grid, so every engine wraps it round a vertical
   child: as a plain block, WebKit measured it narrower
   than the label inside it */
.vt-slot {
  display: grid;
  flex: none;
  outline: 1px dashed #ff6b6b;
  outline-offset: 2px;
}

.vt-tab {
  display: block;
  padding: .5rem .7rem;
  border-radius: 6px;
  font-weight: 700;
  white-space: nowrap;
  color: #0c0c0d;
  background: #c084fc;
}

/* turns the picture only: the layout still holds a wide,
   short box, so the row keeps the gap and the label
   spills out above and below it */
.vt-rotated {
  transform: rotate(-90deg);
}

/* changes the layout: the box itself is tall and narrow */
.vt-turned {
  writing-mode: vertical-rl;
  rotate: 180deg;
}

.vt-next {
  flex: 1;
  align-self: stretch;
  margin: .75rem 0;
  border-radius: 6px;
  background: repeating-linear-gradient(135deg, #2a2a2d 0 6px, transparent 6px 12px);
}

@supports (writing-mode: sideways-lr) {
  .vt-turned {
    writing-mode: sideways-lr;
    rotate: none;
  }
}

Upright letters

Two pink signs, both with writing-mode: vertical-rl. The left keeps the default text-orientation: mixed, so the word "Open" lies on its side. The right adds text-orientation: upright and text-transform: uppercase, so each capital stands up one under the next. The upright version is taller because each letter gets its full height instead of lying flat. The markup says "Open" in both, and the capitals come from the transform rather than being typed in. Pick this for short words only, such as a sign, a badge, or a column label in capitals. Long text stacked upright is slow to read.

HTML

<div class="vt-signs">
  <figure class="vt-case">
    <p class="vt-sign">Open</p>
    <figcaption>text-orientation: mixed</figcaption>
  </figure>
  <figure class="vt-case">
    <p class="vt-sign vt-upright">Open</p>
    <figcaption>text-orientation: upright</figcaption>
  </figure>
</div>

CSS

.vt-signs {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: 2.5rem;
}

.vt-case {
  display: grid;
  justify-items: center;
  gap: .6rem;
  margin: 0;
}

.vt-case figcaption {
  font-family: monospace;
  font-size: .75rem;
  color: #88888f;
}

/* mixed is the default: Latin letters lie on their side */
.vt-sign {
  writing-mode: vertical-rl;
  margin: 0;
  padding: 1rem .7rem;
  border: 2px solid #f472b6;
  border-radius: 10px;
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1;
  color: #f472b6;
}

/* upright stands each letter up, one under the next.
   Capitals stack evenly; the markup keeps "Open" so it
   reads as a word, not as letters. */
.vt-upright {
  text-orientation: upright;
  text-transform: uppercase;
  letter-spacing: .12em;
}

Vertical Japanese

A panel with writing-mode: vertical-rl and lang="ja", holding a title and one paragraph of Japanese. The text reads "vertical writing" as the title, then "This is a sample of vertical writing. Lines advance from right to left. The number 12 fits in the space of one character." Lines run top to bottom and stack right to left, and Japanese characters stand upright on their own with no text-orientation needed. The number 12 sits inside <span class="vt-tcy">12</span> with text-combine-upright: all, so the two digits fit side by side in one character's space. Pick this for Japanese, Chinese, or Korean set vertically, such as a title, a poem, a menu, or a sidebar. Use text-combine-upright for one or two digit numbers inside it.

HTML

<div class="vt-cjk" lang="ja">
  <p class="vt-cjk-title">縦書き</p>
  <p>縦書きの見本です。行は右から左へ進みます。数字の<span class="vt-tcy">12</span>は一文字分に収まります。</p>
</div>

CSS

/* lines run top to bottom and stack right to left; Japanese
   characters stay upright on their own, with no
   text-orientation needed */
.vt-cjk {
  writing-mode: vertical-rl;
  height: 15rem;
  margin: 0;
  padding: 1rem 1.2rem;
  border: 1px solid #2a2a2d;
  border-radius: 10px;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif JP", serif;
  font-size: 1.2rem;
  line-height: 1.9;
  color: #f0f0f0;
  background: #1c1c1e;
}

.vt-cjk-title {
  margin: 0 0 0 .6rem;
  font-weight: 700;
  color: #b8ff57;
}

.vt-cjk p {
  margin: 0;
}

/* two digits set side by side inside one character's space */
.vt-tcy {
  text-combine-upright: all;
}

Understand it

How it works and 6 properties

writing-mode: vertical-rl and writing-mode: sideways-lr turn text upright and change the box itself, so the layout measures the text as tall rather than wide. That makes vertical text different from a rotated box, which keeps its horizontal dimensions and spills out of the space the layout gave it. The demo below shows three places where vertical text fits better than horizontal: an edge label on a card, book spines on a shelf, and table column headers for narrow numeric columns.

The technique is writing-mode for anything that participates in layout, and transform: rotate() only for decoration that sits outside the flow and must not affect anything around it. CSS vertical tabs uses the same property for a tab component, while this page is about the text itself wherever you need it.

How it works

The edge label uses writing-mode: vertical-rl plus rotate: 180deg as a fallback, and sideways-lr with no rotation where supported. Both read bottom to top, and both measure tall in the layout. The book spines use vertical-rl alone, which reads top to bottom like a spine on a shelf, and the height of each spine becomes the length of the text. The table headers use the same pair as the edge label, so the words run upward and the columns stay narrow. No inner span is needed because writing-mode works directly on the <th>.

writing-mode changes the box the layout works with, not only the picture. The writing-mode version measures 48 by 144 pixels in the layout, and the layout gives it a slot that tall. The same text rotated with transform: rotate(-90deg) paints as 41.6 by 150.3 but its layout box stays 150 by 42, the unrotated size, so the text spills out above and below the space it was given. That spillage is why rotated labels break layouts when something else gets added nearby: the picture turned but the box did not, and the layout still reserves a wide, short slot for text that now runs tall.

sideways-lr reads bottom to top on its own, so no rotation is needed. vertical-rl reads top to bottom by default, which works for the spines but not for the edge label or the table headers. Those use vertical-rl plus rotate: 180deg as the fallback, and inside an @supports (writing-mode: sideways-lr) block they switch to sideways-lr with rotate: none. Turning vertical-rl over makes it read upward and keeps the box the same shape, which is why the rotation at 180 degrees is safe here where a 90 degree turn would not be.

The table saves about 180 pixels of width compared to horizontal headers. With every header forced back to horizontal, the table measures 426 pixels wide, which is wider than the content area on a phone at 390 pixels. The vertical version is 245 pixels, so the whole table fits without sideways scroll. That space saving is the reason vertical headers exist: when columns hold single digits or short codes and the header names are long, the horizontal version wastes most of its width on empty cells.

The spines set their heights as percentages, which works here because the shelf has a fixed height for the percentages to resolve against. Each spine also sets its side padding through a custom property, which is what makes some books look thicker than others, and the varied heights and colors come from :nth-child. In vertical-rl the height is the length of the line and padding controls thickness.

Accessibility is unchanged. The table's structure is the same whether the headers are vertical or horizontal. The vertical writing changes the visual layout only. Japanese characters stand upright on their own under the default text-orientation: mixed, and text-combine-upright: all on a span makes two digits fit side by side in the space of one character.

Accessibility notes

Touch screens work the same way as pointer devices here. Nothing depends on hover and there are no interactive controls in the demos, so the examples are display only and need no touch-specific adjustments.

Mistakes worth avoiding

  • Using transform: rotate(-90deg) when the text sits in a layout. The picture turns but the layout box does not, so the text spills out of the space it was given and overlaps other content.
  • Forgetting the fallback rotation. sideways-lr alone reads bottom to top, but vertical-rl alone reads top to bottom. For upward text, pair vertical-rl with rotate: 180deg as the base, and switch to sideways-lr with rotate: none inside @supports.
  • Setting percentage heights without a fixed container. The spines here use height: 85% and that resolves because the shelf has a fixed height. Without it the percentages have nothing to resolve against and the layout breaks.
  • Assuming long vertical text is readable. Short labels and titles work fine. Paragraphs stacked upright are slow to read and hard to scan, so keep vertical text to headings, labels, and short phrases.
  • Nesting a <span> inside the element when writing-mode works directly on the <th>. The table headers in the demo apply the mode to the header cells themselves with no inner wrapper needed.

Ship it

6 features in 4 browsers, 5 questions

Browser support

Feature Chrome Firefox Safari Edge
writing-mode48411112
text-orientation48411479
@supports2822912
transform43.53.112
grid575210.116
flexbox21286.112

The figures for writing-mode and text-orientation are the first unprefixed full support versions. Prefixed support started earlier: Chrome 8 and Safari 5.1 for writing-mode, Safari 10.1 for text-orientation. The code on this page uses only the unprefixed properties. Can I Use has no separate feature for sideways-lr or text-combine-upright, so no version numbers are listed for those.

What you can build with it

  • Table column headers. Long header names over narrow columns of numbers or codes, where horizontal headers would make the table too wide. This is the table variant.
  • Edge labels on cards. A section number or category name running down the side of a card, where a horizontal label would use a full line. This is the edge label in the main demo.
  • Book spines on a shelf. Titles reading top to bottom the way spines are printed, such as a library or a set of volumes. This is the shelf in the main demo.
  • Sidebar headings. Labels in a narrow sidebar where horizontal text would wrap awkwardly or get truncated.
  • Vertical Japanese, Chinese, or Korean. Traditional vertical layout for East Asian languages, where lines run top to bottom and stack right to left. Use text-combine-upright for two-digit numbers.

Frequently asked questions

How do you make vertical text in CSS?
Use writing-mode: vertical-rl for text that reads top to bottom, or writing-mode: sideways-lr for text that reads bottom to top. Both change the layout box to measure the text as tall rather than wide, so the text participates in the layout instead of spilling out of it. For text that must read upward and needs a fallback, use vertical-rl with rotate: 180deg as the base, and switch to sideways-lr with rotate: none inside an @supports block.
What is the difference between writing-mode and transform for rotating text?
writing-mode changes the box itself, so the layout measures vertical text as tall and gives it the space it needs. transform: rotate() turns only the picture and leaves the layout box at its original size, so the text spills out. Use writing-mode when the text sits in a layout, and rotate only for decoration that is positioned on its own and must not affect the flow.
How do I make text read from bottom to top?
writing-mode: sideways-lr reads bottom to top without needing a rotation. For a fallback, use writing-mode: vertical-rl with rotate: 180deg, which flips the text over. The @supports (writing-mode: sideways-lr) block then switches to the cleaner version.
Can I use vertical text for long paragraphs?
Vertical text works best for short labels, headings, and titles. Readers scan long vertical paragraphs more slowly than horizontal ones, and the layout is harder to skim. Keep it to edge labels, table headers, sidebar headings, and similar short content.
How do I make Japanese text vertical?
Use writing-mode: vertical-rl, which reads top to bottom and stacks lines right to left. Japanese characters stand upright on their own under the default text-orientation: mixed. For two-digit numbers inside the text, wrap them in a span with text-combine-upright: all so they sit side by side in the space of one character.