Codectionary / Developer documentation / HTML

Text Direction with dir

The dir attribute declares left-to-right, right-to-left, or automatically detected text direction. It affects text layout and remains meaningful without CSS. dir="auto" is useful for user-entered text whose first strong directional character should choose the base direction.

Syntax

<p dir="rtl">مرحبا</p>
<p dir="auto">User-provided text</p>

Examples

Text Direction with dir: working example

Save as an HTML file and open it in a browser. Expected result: The English paragraph uses left-to-right direction; the Arabic and Hebrew paragraphs use right-to-left direction.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Working example</title>
</head>
<body>
<p dir="ltr">Order: 123</p>
<p dir="rtl" lang="ar">مرحبا بالعالم</p>
<p dir="auto">שלום עולם</p>
</body>
</html>
  1. Expected result: The English paragraph uses left-to-right direction; the Arabic and Hebrew paragraphs use right-to-left direction.
  2. Direction is independent of language: declare both when both are known.
  3. auto examines text direction rather than translating or reordering the underlying string.

Best practices

  • Use semantic dir for content direction and logical CSS properties for spacing.
  • Test punctuation and mixed-direction identifiers with real content.

Browser compatibility

Support applies to the named feature, not every attribute or behaviour in this article. Versions refer to browsers, not operating systems.

dir

Desktop

Chrome
Supported
From 1
Firefox
Supported
From 1
Safari
Supported
By 4 (possibly earlier)
Edge
Supported
By 15 (possibly earlier)
Opera
Supported
From 15

Mobile

Safari on iOS
Supported
By 3.2 (possibly earlier)
Chrome for Android
Supported
From 18
Firefox for Android
Supported
From 4
Samsung Internet
Supported
From 1.0

MDN BCD record for this feature · MDN reference

Support history and limitations

Chrome

  • From 1

Firefox

  • From 1

Safari

  • By 4 (possibly earlier)

Edge

  • By 15 (possibly earlier)

Opera

  • From 15

Safari on iOS

  • By 3.2 (possibly earlier)

Chrome for Android

  • From 18

Firefox for Android

  • From 4

Samsung Internet

  • From 1.0
dir auto value — no separate BCD record

Desktop

Chrome
Unknown
Firefox
Unknown
Safari
Unknown
Edge
Unknown
Opera
Unknown

Mobile

Safari on iOS
Unknown
Chrome for Android
Unknown
Firefox for Android
Unknown
Samsung Internet
Unknown

No single verified compatibility record for this topic. Use the feature-specific articles; no browser support is inferred.

MDN BCD 8.1.5 · Dataset built 2026-10-08 · Mapping reviewed 2026-10-21. These dates are not individual browser-test or claim-verification dates. Unknown means the data does not establish support.

HTML Living Standard

Specifications & further reading