CSS Writing Modes â Vertical Text, RTL & International Layouts
In this tutorial, you'll learn about CSS Writing Modes. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
CSS writing modes control the direction of text flow â horizontal (left-to-right or right-to-left) and vertical (top-to-bottom). If your site serves users in multiple languages, understanding writing modes is essential.
What You'll Learn
By the end, you'll use writing-mode for vertical text in East Asian designs, direction: rtl for Arabic and Hebrew content, logical properties (margin-inline, padding-block) that adapt to writing direction, and text-orientation for mixed writing modes.
Prerequisite: You should understand CSS box model. CSS Box Model covers what you need.
Where This Fits
flowchart LR
A["CSS Styling"] --> B["**CSS Writing Modes**"]
B --> C["CSS Reference"]
C --> D["Frontend-Ready Developer"]
style B fill:#f97316,stroke:#c2410c,color:#fff
style A fill:#e5e7eb,stroke:#9ca3af,color:#374151
style D fill:#22c55e,stroke:#16a34a,color:#fff
Writing Mode â Top to Bottom or Left to Right
The writing-mode property changes how text flows within an element:
.vertical-rl { writing-mode: vertical-rl; } /* Right to left, top to bottom */
.vertical-lr { writing-mode: vertical-lr; } /* Left to right, top to bottom */
| Value | Text Flow | Common Use |
|---|---|---|
horizontal-tb |
Left â right, top â bottom | Default (English, most languages) |
vertical-rl |
Top â bottom, right â left | Traditional Chinese, Japanese, Korean |
vertical-lr |
Top â bottom, left â right | Mongolian, some UI labels |
Example
.vertical-text {
writing-mode: vertical-rl;
height: 200px;
font-size: 1.2rem;
}
<div class="vertical-text">
This text flows from top to bottom, right to left.
</div>
Use case: Vertical headings for East Asian design aesthetics, menu labels on narrow sidebars, artistic typography.
Direction â Left to Right vs Right to Left
The direction property controls the inline text direction:
.rtl { direction: rtl; } /* Right to left (Arabic, Hebrew) */
.ltr { direction: ltr; } /* Left to right (English, default) */
<p class="rtl">ŲØ°Ø§ ŲØĩ باŲŲØēØŠ Ø§ŲØšØąØ¨ŲØŠ</p>
Use case: Sites serving Arabic, Hebrew, Persian, Urdu, or other RTL languages.
Note: For full RTL support, also set unicode-bidi: embed or use the HTML dir="rtl" attribute on the <html> element â this affects the entire page including scrollbars, alignment, and navigation order.
Logical Properties â Adapt to Any Writing Mode
Physical properties (left, right, top, bottom) are fixed. If you switch from LTR to RTL, margin-left: 16px still pushes from the left â but in an RTL layout, it should push from the right. Logical properties solve this:
/* Physical (fixed direction) */
.element {
margin-left: 16px;
padding-top: 8px;
width: 300px;
border-right: 2px solid;
}
/* Logical (adapts to writing direction) */
.element {
margin-inline-start: 16px; /* margin-left in LTR, margin-right in RTL */
padding-block-start: 8px; /* padding-top */
inline-size: 300px; /* width */
border-inline-end: 2px solid; /* border-right in LTR, border-left in RTL */
}
| Physical | Logical (Inline) | Logical (Block) |
|---|---|---|
width |
inline-size |
â |
height |
â | block-size |
margin-left |
margin-inline-start |
â |
margin-right |
margin-inline-end |
â |
margin-top |
â | margin-block-start |
margin-bottom |
â | margin-block-end |
padding-left |
padding-inline-start |
â |
padding-top |
â | padding-block-start |
border-left |
border-inline-start |
â |
border-top |
â | border-block-start |
Analogy: Physical properties are like giving someone directions using "left" and "right" â they change depending on where the person is facing. Logical properties use "inline" and "block" â like "forward" and "sideways" â they adapt to the person's orientation.
Text Orientation â Mixing Vertical and Horizontal
When using vertical writing modes, you may want to keep certain characters horizontal (like numbers or Latin words):
.mixed-text {
writing-mode: vertical-rl;
text-orientation: mixed; /* Default: CJK vertical, Latin sideways */
}
.rotate-text {
writing-mode: vertical-rl;
text-orientation: upright; /* All characters upright */
}
.sideways-text {
writing-mode: vertical-rl;
text-orientation: sideways; /* All characters rotated 90° */
}
| Value | Effect |
|---|---|
mixed |
CJK characters upright, Latin/numbers rotated sideways (default) |
upright |
All characters upright (good for vertical headings) |
sideways |
All characters rotated 90° |
Common Writing Mode Mistakes
1. Using Physical Properties for RTL Sites
/* â Breaks in RTL */
.sidebar { margin-left: 16px; }
/* â
Works everywhere */
.sidebar { margin-inline-start: 16px; }
2. Not Setting HTML dir Attribute
/* â CSS direction alone doesn't fix element ordering */
.rtl { direction: rtl; }
/* â
Set on the root element for full support */
/* <html dir="rtl"> */
The HTML dir attribute controls how the browser lays out elements (not just text). CSS direction alone doesn't reorder flex items or grid cells.
3. Forgetting text-orientation for Mixed Content
/* â Latin text is hard to read in vertical mode */
.vertical { writing-mode: vertical-rl; }
/* â
Better: keep Latin sideways */
.vertical { writing-mode: vertical-rl; text-orientation: mixed; }
4. Applying Vertical Writing Mode to the Whole Page
/* â The entire page flows vertically â very unusual */
html { writing-mode: vertical-rl; }
Vertical writing mode is usually applied to specific elements (sidebars, headings), not the full page.
Security Angle â RTL Security in Applications
Security dashboards from Durga Antivirus Pro support full RTL layouts for Arabic and Hebrew-speaking users. Using logical properties throughout the CSS ensures the dashboard layout mirrors correctly without duplicating styles.
Try It Yourself
Common Mistakes Beginners Make
1. Skipping the Fundamentals
Many beginners jump straight to advanced topics without mastering the basics. Take time to understand the core concepts before moving on.
2. Not Practicing Enough
Reading tutorials without writing code leads to shallow understanding. Code along with every example and experiment on your own.
3. Ignoring Error Messages
Error messages tell you exactly what went wrong. Read them carefully â they usually point to the line and type of issue.
4. Copy-Pasting Without Understanding
It's tempting to copy code from tutorials, but typing it yourself and understanding each line builds real skill.
5. Giving Up Too Early
Every developer hits frustrating bugs. Take breaks, ask for help, and remember that struggling is part of learning.
Practice Questions
Q1: What does writing-mode: vertical-rl do?
{{< details "Show answer" >}}
Text flows from top to bottom, then right to left â like traditional Chinese or Japanese writing.
{{< /details >}}
Q2: What's the difference between direction: rtl and writing-mode: vertical-rl?
{{< details "Show answer" >}}
direction: rtl keeps horizontal text but flows it right-to-left (Arabic, Hebrew). writing-mode: vertical-rl makes text flow top-to-bottom (East Asian).
{{< /details >}}
Q3: What problem do logical properties solve?
{{< details "Show answer" >}}
Physical properties (margin-left) are fixed to one direction. Logical properties (margin-inline-start) adapt to the writing mode â automatically switching in RTL layouts.
{{< /details >}}
Q4: When should you NOT use writing-mode: vertical-rl on an entire page?
{{< details "Show answer" >}}
Almost always. Vertical writing is usually decorative or for specific content. Applying it globally makes the page unusable for most readers.
{{< /details >}}
Q5: How do you make numbers in vertical text display upright instead of rotated?
{{< details "Show answer" >}}
Use text-orientation: upright. This keeps all characters (including Latin and numbers) in their upright orientation instead of rotating them.
{{< /details >}}
FAQ
What is a writing mode in CSS?
Writing mode controls text direction â horizontal (LTR or RTL) or vertical (top-to-bottom). It includes writing-mode, direction, and text-orientation.
Which CSS property adapts to RTL automatically?
Logical properties like margin-inline-start, padding-inline-end, and border-inline-start adapt automatically to the writing direction.
Do I need logical properties for English-only sites?
Not strictly, but they future-proof your code. If you ever add RTL support, logical properties work automatically without rewriting.
What's the HTML equivalent of CSS direction: rtl?
The HTML dir="rtl" attribute on the <html> element. It's preferred over CSS for page-level direction because it handles element ordering.
How do I test RTL layouts?
Set <html dir="rtl"> and refresh. Check that text alignment, margins, padding, borders, and navigation all mirror correctly.
FAQ
FAQ
What's Next?
Continue with more CSS topics:
What's Next
Congratulations on completing this Css Writing Modes tutorial! Here's where to go from here:
- Practice daily â Consistency is more important than long study sessions
- Build a project â Apply what you learned by building something real
- Explore related topics â Check out other tutorials in the same category
- Join the community â Discuss with other learners and share your progress
Remember: every expert was once a beginner. Keep coding!
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro