Read the attribute. May be null if markup never set dir.
Assign via JS. Setting document.dir typically updates the root dir.
Pick one approach. Markup for fixed locales; JS for runtime language switches.
Compatibility
Browser Support
Document.dir is Baseline Widely available (MDN: since March 2017). Safe to use for reading and setting document directionality.
✓ Baseline · Widely available
Document.dir
String property for document text direction — "ltr" or "rtl".
98%Widely available
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
Android WebViewSupported · Modern WebView
Full support
dirExcellent
Bottom line: Safe for production. Prefer
in markup when the locale is fixed at load time; use document.dir for runtime language / direction switches.
Frequently Asked Questions
A string for the document’s text directionality: "ltr" (left to right) or "rtl" (right to left). MDN documents these as the possible values.
No. MDN marks Document.dir as Baseline Widely available (since March 2017). It is not Deprecated, Experimental, or Non-standard.
Yes. Assign "ltr" or "rtl" to change the document direction. That updates the document-level direction used for layout and bidirectional text.
They work together. The HTML dir attribute (often on <html>) expresses direction in markup; document.dir is the Document API for reading and writing that document-level directionality.
No. Set document (or <html>) direction for the page default. Use the dir attribute — or HTMLElement.dir — on specific elements when only a subsection needs a different direction.
The HTML attribute supports auto for heuristic direction. Document.dir’s documented values on MDN are "ltr" and "rtl" — prefer those when setting from JavaScript unless you manage auto in markup.