CSS direction Property

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The direction property sets the base inline direction for text, table and grid columns, and horizontal overflow. Use ltr for left-to-right languages and rtl for right-to-left languages such as Arabic or Hebrew.

It is inherited. Prefer the HTML dir attribute for document or section language direction. Use CSS direction when you need a component-level switch or cannot change markup.

Baseline · Widely available.

Not deprecated. MDN warns authors to prefer HTML dir over CSS direction for page language direction when possible.

Warning

Where possible, prefer the HTML dir attribute over CSS direction for language direction. Do not force English UI into rtl only to flip layout — use logical properties instead.

CSS Syntax

syntax.css
direction: ltr | rtl | initial | inherit;

Only two direction keywords exist. Global keywords such as initial and inherit also apply.

Property Values

ValueDescriptionTry it
ltrLeft to right. Initial value for most Western languagesTry it
rtlRight to left. Use for Arabic, Hebrew, and similar scriptsTry it
initialResets to ltrTry it
inheritTakes the parent element's directionTry it

On inline elements, pair direction with unicode-bidi: embed or override so the change applies. See tryit 4.

How to Use direction

Match the base direction to the language of the content you are styling.

  1. Prefer dir="rtl" or dir="ltr" on HTML for whole pages or major sections.
  2. Use CSS direction on a block when you need a local switch without changing markup.
  3. For flex or grid demos, set direction on the container to flip inline start.
  4. Prefer logical properties so padding and margins flip correctly in both directions.
PieceRequired?Role
ltr / rtlYes (one of them)Sets the base inline direction
Block containerTypicalBlocks show the effect clearly without extra properties
unicode-bidiFor inlineNeeded for direction to affect inline-level elements
InheritedBy designChildren inherit unless they override

Live Preview

Switch direction and watch the numbered boxes reorder along the inline axis.

Boxes use flex. Changing direction flips their inline start side.

Flex row
1234

direction: ltr

CSS Examples

Each snippet focuses on direction. Use Try It Yourself for a live editor.

Example 1 — Right-to-Left Text

Flip a paragraph to right-to-left flow.

CSS
<style>
  .rtl {
    direction: rtl;
  }
</style>

<p class="rtl">Hello from right to left.</p>
Try It Yourself

How It Works

  1. Select the block. The rule targets .rtl.
  2. Set rtl. Inline start moves to the right edge.
  3. Watch punctuation. English punctuation can look odd in forced RTL — that is expected.
  4. Prefer HTML dir for real language sections when you control the markup.

Example 2 — Flex Row Direction

Change how flex items line up on the inline axis.

CSS
<style>
  .row {
    display: flex;
    direction: rtl;
  }
</style>

<div class="row">
  <span>1</span><span>2</span><span>3</span>
</div>
Try It Yourself

How It Works

  1. Make a flex row. display: flex lays items on one line.
  2. Set direction: rtl. Item 1 starts on the right.
  3. DOM order stays the same. Only the inline start side flips.
  4. Compare with LTR. Open the editor and change the value to ltr.

Example 3 — Arabic Paragraph

Use rtl with real right-to-left script.

CSS
<style>
  .ar {
    direction: rtl;
  }
</style>

<p class="ar" lang="ar">مرحبا بالعالم</p>
Try It Yourself

How It Works

  1. Mark the language. lang="ar" helps browsers and assistive tech.
  2. Set direction: rtl. The paragraph flows right to left.
  3. Match script and direction. Arabic reads naturally in RTL.
  4. Prefer dir="rtl" on the element in production HTML when you can.

Edge Cases & Pitfalls

If direction looks wrong, check these first.

html

Prefer HTML dir for language direction

MDN recommends the dir attribute for documents and major sections. CSS direction is better as a local layout tool.

inline

Inline elements need unicode-bidi

For direction to affect inline-level elements, set unicode-bidi to embed or override.

logical

Physical left/right break in RTL

margin-left stays on the physical left. Prefer margin-inline-start so spacing follows direction.

all

direction is excluded from all

direction and unicode-bidi are not reset by the all shorthand. Reset them explicitly when needed.

tables

Table columns do not inherit into cells via CSS

Unlike HTML dir on a column, CSS inheritance follows the tree. Cells inherit from rows/ancestors, not from column elements.

Browser Support

direction is a browser CSS property for text and layout flow. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

direction

Supported in all modern browsers and older engines. Prefer HTML dir for document language direction.

99% Browser support
Google Chrome All modern versions
Full support
Mozilla Firefox All modern versions
Full support
Apple Safari All modern versions
Full support
Microsoft Edge All modern versions
Full support
Opera All modern versions
Full support
Samsung Internet Supported
Full support
Internet Explorer Supported
Full support
direction Widely supported

Bottom line: Safe to use for LTR/RTL layout demos. Prefer HTML dir for page language. It is not a runtime API.

Key Takeaways

  • Role: set base inline direction for text and layout.
  • Values: ltr (default) or rtl. Inherited.
  • Prefer HTML dir for document and section language direction.
  • Inline caveat: pair with unicode-bidi on inline elements.

One line: use direction for local LTR/RTL flow — and HTML dir for real language sections.

Frequently Asked Questions

It sets the base inline direction for text, table and grid columns, and horizontal overflow. Use ltr for left-to-right languages and rtl for right-to-left languages such as Arabic or Hebrew.
The initial value is ltr. The property is inherited, so children follow a parent unless they override it.
Prefer the HTML dir attribute on the document or a section when you can. MDN recommends avoiding CSS direction for page-level language direction. Use the CSS property for component-level layout demos or when you cannot change markup.
direction sets the base flow and inline start/end sides. text-align places lines inside the box. Prefer text-align: start so alignment follows direction automatically.
On inline-level elements, direction needs unicode-bidi set to embed or override to take effect. Block containers usually show the change without that.
It is Baseline Widely available across modern browsers and older engines. It is a browser CSS property, not a Node.js runtime feature.

Next: display

Control how an element participates in layout.

display tutorial →

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.

8 people found this page helpful