Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Turn Text Vertical With writing-mode

In this lesson, you gave The Lantern Press an issue banner like the spine of the printed zine, then turned its text on its side with writing-mode. Here are the main points and the banner’s final code.

Key Points

  • inline-size and block-size size a box along the text. In horizontal text, inline-size is the width and block-size is the height, so the banner starts out 256 pixels wide and 48 pixels tall.
  • writing-mode sets which way lines run. The default, horizontal-tb, runs lines across and stacks them from top to bottom. vertical-rl runs each line from top to bottom and stacks the lines from right to left.
  • In vertical-rl, the inline start is the top, so the banner’s border-inline-start and padding-inline-start move to its top edge. The block start is the right, so the words sit against the banner’s right edge.
  • Watch out: inline-size is the width only in horizontal text. In vertical text, it’s the height, so the banner becomes 256 pixels tall and 48 pixels wide.
  • For this left-to-right banner, going from horizontal to vertical-rl moves each edge name a quarter turn clockwise: inline start from the left to the top, block start from the top to the right, inline end to the bottom, and block end to the left. With dir="rtl", inline start moves to the bottom instead and inline end to the top, while vertical-rl still stacks the lines from right to left.
  • The quarter turn is only a way to remember the map. A picture turned on its side would keep its old 256-by-48 spot and hang over the content below. The browser lays the text out instead, so the banner takes up 48 by 256 pixels and the In This Issue heading moves down 208 pixels to clear it.
  • Inline means along a line of text and block means across the lines. Logical properties follow those axes, whichever way the writing mode turns them.

The Final Code

The banner’s HTML, at the top of <main> in index.html:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 Your poet bio card now flips to right to left with one set of rules. However, English and Arabic both stack their lines from top to bottom, so the block axis never moved.

00:10 In this video, you’ll turn text on its side and watch where each logical property goes.

00:17 Teo wants an issue banner like the spine of the printed zine, with the issue’s name on it. Add a paragraph with the class issue-banner at the top of the main element.

00:28 In the components layer, give it a rule with an inline-size of 16 rems and a block-size of 3 rems. A margin of zero clears the paragraph’s default margins.

00:38 Then come the pull quote’s padding and red line at the inline start, and the masthead’s dark colors.

00:45 Save, and the banner appears above the contents. It’s 256 pixels wide and 48 pixels tall, with the red line on its left. In horizontal text, inline-size is the width and block-size is the height.

01:02 To set text on its side, CSS has the writing-mode property. Its default value, horizontal-tb, is what every page so far has used.

01:11 Lines run across, and they stack from top to bottom. Now add writing-mode: vertical-rl at the top of the banner’s rule. Vertical means each line runs from top to bottom.

01:24 RL means the lines stack from right to left. The rest of the rule stays as it was. Your turn: pause the video and predict which side of the banner the red line is on when you save.

01:43 Save, and the red line runs along the top of the banner. The text now starts at the top, so the top is the inline start. The border and the padding follow it there.

01:55 The sizes swapped, too. The banner is now 256 pixels tall and only 48 pixels wide. inline-size is the length of a line, and lines now run down the page, so it sets the height.

02:09 Watch out for this one. inline-size is the width only in horizontal text.

02:16 block-size sets the width. And the words sit at the right of the banner, not the left. Lines stack from right to left in this mode, so the right edge is the block start.

02:28 Here’s the whole map. In the horizontal banner, the starts are the left and the top. For this left-to-right banner, vertical-rl moves each name a quarter turn clockwise.

02:40 Inline start goes to the top, and block start to the right. Inline end goes to the bottom, and block end to the left. With dir="rtl", inline start moves to the bottom instead, and inline end to the top, but the lines still stack from right to left.

02:58 The quarter turn is only a way to remember the map. A picture turned on its side would keep its old wide spot and hang over the heading below. The browser lays the text out instead, so the banner takes up 48 by 256 pixels, and the In This Issue heading moves down 208 pixels to clear it.

03:18 Here’s the rule: inline means along a line of text, and block means across the lines. Logical properties follow those axes, whichever way the writing mode turns them.

03:30 So Teo’s banner never names a side of the screen, and every edge landed where the text needed it. Next, in Exercise: Make the Contents Card Logical, you’ll rework the contents card and its vertical issue label so they hold up in any writing direction.

Become a Member to join the conversation.