π What is direction?
The direction property controls the inline text direction inside an element β determining whether text flows left-to-right (LTR) or right-to-left (RTL). It is essential for multilingual interfaces, especially those supporting languages like Arabic, Hebrew, Farsi (RTL), or English, Tamil, Japanese, etc. (LTR).
Note
β Important for internationalization (i18n)
β Affects inline content, text alignment, floats, and table layout
π― Why Use direction?
- Support right-to-left languages (Arabic, Hebrew, Urdu)
- Design bilingual or multilingual UI layouts
- Control inline flow inside widgets and components
- Fix rendering direction of numbers, punctuation, and icons
- Ensure proper alignment of mixed LTR + RTL text
π Syntax
direction Syntax
direction: ltr | rtl;π Values Explained
| Value | Description |
|---|---|
| ltr (left-to-right) | Default for most languages (English, Spanish, Tamil, Hindi) |
| rtl (right-to-left) | Used for RTL languages (Arabic, Hebrew, Urdu) |
Note
π§ͺ Example 1 β Left-to-Right (Default)
LTR Example
.ltr-text {
direction: ltr;
}π§ͺ Example 2 β Right-to-Left Text
RTL Example
.rtl-text {
direction: rtl;
}Common in Arabic UI layouts:
Arabic Example
<div class="rtl-text">Ψ§ΩΨ³ΩΨ§Ω
ΨΉΩΩΩΩ
</div>π§ How direction Affects Inline Layout
| Feature | Effect |
|---|---|
| Text flow | LTR: left β right RTL: right β left |
| Inline start & end | logical properties follow writing direction |
| text-align: start/end | start = left in LTR, right in RTL |
| float: inline-start/end | Depends on direction |
| list-style-position | Bullet switches to right side in RTL |
| tables | Column ordering respects direction |
Note
π¨ Example β Reversing a UI Component for RTL
Component RTL
.card {
direction: rtl;
text-align: start;
}This makes text right-aligned automatically and flips inline items.
π± Example β Input Field with RTL Support
Input Example
input.arabic {
direction: rtl;
text-align: right;
}π― direction + unicode-bidi (Advanced)
When dealing with mixed-direction content, use unicode-bidi to control how algorithmically text flows.
unicode-bidi Example
.force-rtl {
direction: rtl;
unicode-bidi: bidi-override;
}Forces all text to behave as RTL, even mixed content.
π§© Logical Properties Work With direction
These properties change meaning depending on direction:
- margin-inline-start
- padding-inline-end
- border-inline-start-color
- inset-inline-end
Great for building UI that supports both LTR + RTL without rewriting CSS.
β οΈ Common Mistakes
- β Using direction to rotate text (use transform instead)
- β Expecting direction to affect block flow (use writing-mode)
- β Forgetting that direction flips inline alignment
- β Not testing UI in both LTR and RTL modes
Note
π₯ Summary
The direction property controls the inline text flow of an element, crucial for RTL language support and international UI layouts. When combined with writing-mode and logical properties, it creates powerful, fully responsive multilingual designs.
Learn more βMDN Docs π