The dirglobal attribute sets an element’s base text direction and isolates that content from surrounding text. Valid values are ltr, rtl, and auto.
Use it for multilingual pages (Arabic, Hebrew, mixed LTR/RTL). Pair it with lang. Prefer HTML dir over CSS direction when you can — direction is part of the content’s meaning.
Baseline · Widely available.
Not deprecated and not experimental. Stable across modern browsers since about July 2015.
lang ≠ direction.
lang names the language; it does not set base direction. Set dir explicitly, especially for RTL pages.
Syntax
HTML Syntax
syntax.html
<element dir="ltr | rtl | auto">
If omitted or invalid, direction is usually inherited from the parent (default ltr). Omitting dir does not enable auto-detection.
Values
Attribute Values
Enumerated values (only these three):
Value
Description
Try it
ltr
Left-to-right base direction (English, most Western scripts)
Change dir on the sample text and watch alignment and punctuation placement.
Applies to the paragraph below. Try rtl with Arabic text selected via auto samples in the examples.
Paragraph
Hello world. مرحبا. Punctuation follows the base direction!
dir="ltr"
Code
HTML Examples
Short, copy-ready snippets. Use Try It Yourself for a live editor.
Example 1 — Explicit ltr and rtl
Set base direction on each block. Punctuation follows that base.
HTML
<p dir="ltr" lang="en">
This sentence is in English and reads left to right.
</p>
<p dir="rtl" lang="ar">
هذه الجملة باللغة العربية وتُقرأ من اليمين إلى اليسار.
</p>
dir="auto" inspects the first strongly directional character.
Latin letters → LTR base; Arabic letters → RTL base.
Heuristic, not language detection — a comment starting in English then switching to Arabic may stay LTR.
Prefer explicit dir when you already know the language.
Edge Cases & Pitfalls
Most layout bugs come from missing dir on RTL pages or confusing inheritance with auto.
inherit
Omitted ≠ auto
Without dir, the element inherits. It does not auto-detect. Use auto only when you want detection.
rtl
Set document direction for RTL sites
Default base is LTR. Arabic/Hebrew pages should set dir="rtl" on <html>.
inline
Wrap opposite-direction phrases
Isolate an English title inside Arabic with <cite dir="ltr"> (or <bdi>) so punctuation stays with the phrase.
forms
Submit direction with dirname
For inputs, dirname can send the field’s direction with the form data.
css
Prefer markup over CSS
CSS direction can override display, but HTML dir keeps meaning correct without stylesheets.
Compatibility
Browser Support
dir is an HTML global attribute in the browser. It is not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
dir
Widely available since about July 2015. All modern browsers support ltr, rtl, and auto on HTML elements.
97%Global support (approx.)
Google ChromeAll modern
Full support
Mozilla FirefoxAll modern
Full support
Apple SafariAll modern
Full support
Microsoft EdgeAll modern
Full support
OperaAll modern
Full support
Samsung InternetModern
Full support
Internet Explorer5+
Supported
dirWidely supported
Bottom line: Safe to use everywhere. Always set dir (and lang) explicitly on RTL documents rather than relying on the LTR default.
Remember
Key Takeaways
Values:ltr, rtl, or auto — a global enumerated attribute.
RTL pages: set dir="rtl" (and lang) on <html>.
auto: for unknown / user content; explicit values when known.
Prefer HTML dir over CSS for semantic direction.
One line:dir sets base text direction — use ltr/rtl when known, auto when not.
Frequently Asked Questions
It sets an element’s base text direction and isolates that content from surrounding text. Values are ltr (left to right), rtl (right to left), and auto (detect from content).
Yes. You can put dir on almost any HTML element, including html, body, p, and span. Descendants inherit the direction unless they set their own.
Use auto when the direction is unknown in advance — for example user comments or external text. Prefer an explicit ltr or rtl when you know the language.
For pages mainly in Arabic, Hebrew, or other RTL scripts, set dir="rtl" (and lang) on html so the whole document has the correct base direction.
No. lang declares the language. dir sets base direction. Use both together — lang does not imply direction by itself.
Prefer the HTML dir attribute when possible. Direction is part of the content’s meaning, so markup keeps text correct even if CSS is off.