Document.dir is an instance property (string) for the text directionality of the document: "ltr" (left to right) or "rtl" (right to left). Learn how to read and set it, how it relates to the HTML dir attribute, and five examples with try-it labs.
01
Kind
Read / write
02
Type
string
03
Values
ltr / rtl
04
Default
Often ltr
05
Related
html dir
06
Status
Baseline widely
Fundamentals
Introduction
Languages are not only different words—they also flow in different directions. English and many others read left to right (ltr). Arabic, Hebrew, and others often use right to left (rtl).
MDN: Document.dir is a string representing that directionality for the document. Possible values are "rtl" and "ltr". Setting it updates how the page lays out text and many UI directions (start/end edges, scrollbars in some cases, and bidirectional text).
💡
Markup first when you can
Prefer declaring direction in HTML: <html lang="ar" dir="rtl">. Use document.dir when the user switches language/layout at runtime. See also the dir global attribute on MDN.
Document.dir is marked Baseline Widely available on MDN (since March 2017). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
Document.dir
Read/write string for document text directionality — "ltr" or "rtl".
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerSupported (legacy)
Full support
Document.dirExcellent
Bottom line: Use document.dir to read or set page direction. Prefer
for the default, and logical CSS for mirrored layouts.
Wrap Up
Conclusion
Document.dir is the Document API for page text direction (ltr / rtl). Set it in markup when possible, and use the property when users switch languages or you need to mirror a layout at runtime.
Override direction only where a subsection needs it
Test both LTR and RTL early in design
❌ Don’t
Hard-code left/right margins for multilingual layouts
Assume every browser reports "ltr" when unset (may be "")
Forget nested dir for mixed-language snippets
Treat direction as a substitute for translation
Ignore keyboard and focus order after flipping RTL
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about document.dir
Document text direction — ltr or rtl.
5
Core concepts
🔀01
Values
ltr / rtl
API
✓02
Status
baseline
Standard
🔒03
Access
get + set
DOM
🌐04
Pair with
lang
i18n
📄05
Also
html dir
Markup
❓ Frequently Asked Questions
A string for the document's text directionality: "ltr" (left to right, default for many languages) or "rtl" (right to left, e.g. Arabic or Hebrew).
No. MDN marks Document.dir as Baseline Widely available (since March 2017). It is a standard Document instance property.
Yes. Assign "ltr" or "rtl" to change the document direction. That typically updates the underlying html dir used for layout and bidirectional text.
They work together. The HTML dir global attribute (often on <html>) expresses direction in markup; document.dir is the Document API for reading and writing that document-level directionality (see also MDN dir attribute).
No. Set document (or <html>) direction for the page default. Use the dir attribute on specific elements when only a subsection needs a different direction.
The HTML attribute supports auto for heuristic direction. document.dir's documented API values on MDN are "ltr" and "rtl" — prefer those when setting from JavaScript unless you intentionally manage auto in markup.
Did you know?
CSS logical properties such as margin-inline-start and padding-inline-end automatically flip when document.dir is rtl. That is why modern responsive designs prefer logical sides over hard-coded left / right.