CSS direction Property

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 4 Examples
Text & i18n

What You’ll Learn

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.

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.

📝 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).

⚡ Quick Reference

QuestionAnswer
Initial valueltr
Applies toAll elements
InheritedYes
AnimatableNo
Common RTL useArabic, Hebrew, and Persian content blocks

💎 Property Values

The direction property accepts keyword values that control inline text flow.

ValueDescription
ltrText direction goes from left to right. This is the default value.
rtlText direction goes from right to left.
initialSets the property to its default value (ltr).
inheritInherits the direction property from its parent element.

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 / scriptTypical directionHTML lang example
English, Spanish, Frenchltrlang="en"
Arabicrtllang="ar"
Hebrewrtllang="he"
Persian (Farsi)rtllang="fa"
Urdurtllang="ur"

👀 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.

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>
<p class="rtl">This paragraph is right-to-left.</p>
Try It Yourself

How It Works

direction: rtl on .rtl reverses the inline flow so text starts from the right edge of the paragraph box.

Example 2 — Arabic Content Block

Use RTL direction with the correct lang attribute for natural Arabic typography.

direction-arabic.html
<style>
  .arabic {
    direction: rtl;
    font-family: "Segoe UI", Tahoma, sans-serif;
  }
</style>

<p class="arabic" lang="ar">
  مرحبًا بكم في موقعنا!
</p>
Try It Yourself

How It Works

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.

Try It Yourself

How It Works

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>

<blockquote class="quote-en" lang="en">Welcome to our site.</blockquote>
<blockquote class="quote-ar" lang="ar">مرحبًا بكم في موقعنا.</blockquote>
Try It Yourself

How It Works

Each block sets its own direction. This pattern is common on bilingual sites where English and Arabic content appear on the same page.

♿ 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.

🖥 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 Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions
Full support
Opera All modern versions
Full support
direction property 99% supported

Bottom line: direction is safe to use everywhere. Focus on correct lang and dir attributes rather than browser support.

🎉 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.

💡 Best Practices

✅ Do

  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about direction

Use these points when building multilingual layouts.

5
Core concepts
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.

Practice in the Live Editor

Open the HTML editor, add direction: rtl to a paragraph, and compare LTR and RTL text flow side by side.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful