Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Typography

The direction property

Reference for the CSS direction property: ltr and rtl, how it flips text, flex and table order, why the HTML dir attribute is usually better, with a live demo.

The direction property sets the base direction of text and of the inline layout inside an element: ltr for left-to-right scripts such as English, or rtl for right-to-left scripts such as Arabic and Hebrew. It decides where lines start, which side text-align: start means, the order of inline boxes and flex items in a row, and the column order of tables.

For content in a document, you should normally set the direction with the HTML dir attribute, not with CSS. The attribute is part of the markup, so it keeps working when styles fail to load. Use the CSS property for cases where direction is purely a presentation choice.

CSS
.arabic {
  direction: rtl;
}

Try it

ltr and rtl side by side

In the second panel, the lines start at the right edge, the exclamation mark moves to the left end of the English phrase (the base direction decides where neutral characters go), and the numbered flex items run from right to left.

Syntax

CSS
direction: ltr | rtl;
Initial value ltr
Applies to all elements
Inherited yes
Animatable no
Computed value as specified

Values

Value Description
ltr Left-to-right text and inline direction. Lines start at the left; the initial value.
rtl Right-to-left text and inline direction. Lines start at the right.

Usage notes

  • Prefer dir in HTML. <html dir="rtl" lang="ar"> or dir on a single element describes the content's direction. The CSS property is for presentation. Browsers map dir to direction through their default style sheet.
  • The browser still reorders text. Even in an ltr block, Arabic or Hebrew words display right-to-left, thanks to the Unicode bidirectional algorithm. direction sets the base direction that algorithm starts from. See unicode-bidi for overriding it.
  • What flips. Inline content, text-align: start and end, flex rows, grid column order, table column order, horizontal scrollbar start position, and the default position of overflowing content.
  • What does not flip. Physical properties such as margin-left and left keep their meaning. Use logical properties (margin-inline-start, inset-inline-start) so spacing follows the direction; see Writing Modes and Logical Properties.
  • Direction versus writing mode. direction controls the inline direction within the current writing-mode. In vertical writing it flows top-to-bottom or bottom-to-top.
  • Matching in selectors. The :dir() pseudo-class selects elements by their direction; see :dir().
  • Accessibility. Always set the language and direction of the real content; assistive technologies and spell checkers depend on both.

Browser support

Supported in every browser.