The direction property sets the text flow of an element — left-to-right (ltr) or right-to-left (rtl). It is essential for multilingual websites and for creating a natural reading experience in languages like Arabic and Hebrew.
01
Text flow
LTR vs RTL basics.
02
Syntax
ltr and rtl values.
03
Default ltr
Western default flow.
04
RTL languages
Arabic, Hebrew, Urdu.
05
Inheritance
Set once on a parent.
06
Accessibility
Pair with lang and dir.
Fundamentals
Introduction
The direction property in CSS is used to set the text direction of an element. This property is particularly useful for creating web pages that support languages written from right to left (RTL), such as Arabic and Hebrew. By controlling the direction of text, you can ensure that your website provides a proper and intuitive reading experience for users of different languages.
Definition and Usage
Apply direction to block containers whose inline content should flow in a specific direction. It affects how text, punctuation, and inline elements are ordered. It also influences logical properties such as margin-inline-start and padding-inline-end because “start” and “end” follow the current direction.
💡
Beginner Tip
For an entire page in Arabic or Hebrew, set direction: rtl on html or body and add the matching dir="rtl" and lang attributes in HTML for the best accessibility.
Foundation
📝 Syntax
The syntax for the direction property is straightforward. It can be applied to any block-level element (and is inherited by descendants).
syntax.css
element{direction:ltr|rtl|initial|inherit;}
Basic Example
direction-rtl.css
p.rtl{direction:rtl;}
direction: ltr;direction: rtl;direction: inherit;
Default Value
The default value of the direction property is ltr (left-to-right).
Syntax Rules
Use ltr for languages that read left to right (English, Spanish, French, and many others).
Use rtl for right-to-left scripts (Arabic, Hebrew, Persian, Urdu).
The property is inherited — children follow the parent unless overridden.
Pair direction changes with the correct lang attribute so browsers and assistive tech pick the right voice and rules.
For mixed-direction content inside one line, you may also need unicode-bidi (advanced cases).
Cheat Sheet
⚡ Quick Reference
Question
Answer
Initial value
ltr
Applies to
All elements
Inherited
Yes
Animatable
No
Common RTL use
Arabic, Hebrew, and Persian content blocks
Reference
💎 Property Values
The direction property accepts keyword values that control inline text flow.
Value
Description
ltr
Text direction goes from left to right. This is the default value.
rtl
Text direction goes from right to left.
initial
Sets the property to its default value (ltr).
inherit
Inherits the direction property from its parent element.
Context
When to Use RTL Direction
Switch to direction: rtl when the primary content of a section is written in a right-to-left script:
Language / script
Typical direction
HTML lang example
English, Spanish, French
ltr
lang="en"
Arabic
rtl
lang="ar"
Hebrew
rtl
lang="he"
Persian (Farsi)
rtl
lang="fa"
Urdu
rtl
lang="ur"
Preview
👀 Live Preview
Compare default left-to-right flow with right-to-left flow on the same English sentence:
direction: ltr This paragraph flows from left to right.
direction: rtl This paragraph flows from right to left.
Hands-On
Examples Gallery
In this example, we’ll change the text direction of a paragraph to right-to-left — plus patterns for RTL languages, page-level direction, and mixed layouts.
📄 Basic Text Direction
Start with the reference example — one paragraph stays LTR while another uses RTL.
Example 1 — Right-to-Left Paragraph
Change the text direction of a single paragraph while leaving the rest of the page in the default LTR flow.
direction-rtl.html
<style>p.rtl{direction:rtl;}</style><h1>Paragraph with Custom Text Direction</h1><p>This paragraph is left-to-right by default.</p><pclass="rtl">This paragraph is right-to-left.</p>
Arabic script reads right to left. direction: rtl aligns the text correctly, and lang="ar" helps browsers handle fonts, hyphenation, and screen reader pronunciation.
🌐 Page & Section Layout
Apply direction at the document or section level when most content shares the same reading order.
Example 3 — Page-Level RTL Direction
Set direction on html or body so the entire page flows right to left.
direction-page.css
html{direction:rtl;}
In HTML, mirror this with <html lang="ar" dir="rtl"> for accessibility.
Because direction is inherited, one rule on html or body flips inline order for the whole document unless a child resets it to ltr.
Example 4 — Mixed LTR and RTL Sections
Keep the page LTR but switch individual sections back to RTL for localized content.
direction-mixed.html
<style>.quote-en{direction:ltr;}.quote-ar{direction:rtl;}</style><blockquoteclass="quote-en"lang="en">Welcome to our site.</blockquote><blockquoteclass="quote-ar"lang="ar">مرحبًا بكم في موقعنا.</blockquote>
Each block sets its own direction. This pattern is common on bilingual sites where English and Arabic content appear on the same page.
A11y
♿ Accessibility
Use dir in HTML — Pair CSS direction with dir="ltr" or dir="rtl" on the same element or ancestor.
Set lang correctly — Screen readers and hyphenation depend on the language, not just visual direction.
Do not flip content arbitrarily — Only use RTL when the actual language or user expectation requires it.
Test keyboard and focus order — Direction changes can affect tab order and visual alignment of icons and controls.
Prefer logical properties — Use margin-inline-start instead of hard-coded margin-left so spacing follows direction automatically.
🧠 How direction Works
1
You set ltr or rtl
Apply direction on a container using a keyword value.
CSS rule
2
Inline flow is established
Text, numbers, and inline elements follow the chosen start edge — left for LTR, right for RTL.
Layout
3
Children inherit the direction
Nested elements use the same flow unless they override it. Logical properties follow the inherited direction.
Cascade
=
🌐
Readable multilingual layout
Users see content in the natural reading order for their language.
Compatibility
🖥 Browser Compatibility
The direction property is supported in all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. It is also supported in older browsers, ensuring broad compatibility across different user environments.
✓ Baseline · Universal support
Direction everywhere
direction has been part of CSS since the earliest days of the web. Both ltr and rtl work reliably in every modern browser.
99%Universal support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions
Full support
OperaAll modern versions
Full support
direction property99% supported
Bottom line:direction is safe to use everywhere. Focus on correct lang and dir attributes rather than browser support.
Wrap Up
🎉 Conclusion
The direction property is an essential tool for web developers who need to support multiple languages, especially those written in right-to-left scripts. By controlling the direction of text, you can create a more inclusive and user-friendly web experience.
Experiment with this property to see how it can enhance the readability and accessibility of your web content. For beginners, remember: use ltr by default, switch to rtl for RTL languages, and always pair direction changes with the correct lang attribute.
Set direction: rtl for Arabic, Hebrew, and other RTL content
Add matching dir and lang attributes in HTML
Use logical properties (margin-inline-*, padding-inline-*) with RTL layouts
Test mixed LTR/RTL pages with real content in each language
Reset direction to ltr inside RTL pages when embedding English quotes
❌ Don’t
Use RTL only for visual effect on English text
Hard-code margin-left when direction may change
Forget lang on localized blocks
Assume text-align: right is the same as direction: rtl
Mix direction and unicode-bidi without understanding bidirectional text rules
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about direction
Use these points when building multilingual layouts.
5
Core concepts
↔01
Text flow
LTR or RTL order.
Purpose
⏪02
Default ltr
Left-to-right.
Default
🌎03
RTL scripts
Arabic, Hebrew.
Use case
📝04
Inherited
Flows to children.
Cascade
♿05
Pair dir + lang
Accessible i18n.
A11y
❓ Frequently Asked Questions
The direction property sets whether text and inline content flows from left to right (ltr) or right to left (rtl). It also affects the inline start and end sides used by related layout properties.
The initial value is ltr (left-to-right). Most Western languages use this default unless you explicitly set direction: rtl.
direction controls the base text flow and inline order. text-align positions text within its container (left, right, center, justify). In RTL content, text-align: start follows the direction automatically.
For whole documents or major sections, prefer the HTML dir attribute on html or a container element. CSS direction is useful when you need to switch direction for a specific component without changing markup.
Yes, direction is inherited. Setting it on body, a wrapper, or a section affects nested text unless a child overrides it.