The dirname attribute on <textarea> and some <input> types tells the browser to submit the text direction (ltr or rtl) together with the field value.
Its value is a form field name (e.g. comment-direction), not a direction token. On submit you get two pairs: the normal name/value, plus {dirname}={ltr|rtl}. Pair it with dir (often dir="auto") so direction can be detected from what the user types.
Baseline · Widely available.
Not deprecated. Marked widely available across modern browsers (MDN: since about August 2023 for full baseline coverage).
Not the same as dir.
dir controls display. dirname only names the extra submitted direction field.
Parent dir="rtl" may yield …-direction=rtl even for Latin text.
How It Works
Parent dir="rtl" sets the context direction.
Controls omit dir, so they inherit that base.
dirname still sendsltr or rtl based on the control’s directionality.
Use dir="auto" on the field when you want detection from the typed characters instead.
Edge Cases & Pitfalls
Most confusion comes from treating dirname as if it stored ltr/rtl in the attribute itself.
name
Attribute value = field name
Write dirname="comment-direction", not dirname="rtl". The direction is the submitted value.
scope
Not on every input type
Use it on textarea and supported text-like inputs. It is not a global attribute.
server
Read both fields on the server
Persist or echo the text with the matching direction so RTL content is not shown as LTR.
js
Property is dirName
In the DOM API the property is camelCase with a capital N: element.dirName.
compare
Still set dir for display
dirname alone does not fix on-screen layout. Use dir (often auto) for the UI.
Compatibility
Browser Support
dirname is an HTML attribute for form controls in the browser. It is not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
dirname
Baseline widely available (MDN notes broad support from about August 2023). Modern Chrome, Firefox, Safari, and Edge include the direction field on submit.
95%Global support (approx.)
Google Chrome17+
Full support
Mozilla Firefox116+
Full support
Apple Safari6+
Full support
Microsoft Edge79+
Full support
Opera15+
Full support
Samsung InternetModern
Full support
Internet ExplorerNo
Not supported
dirnameWidely supported
Bottom line: Safe for modern multilingual forms. Always verify the extra direction field arrives on your server in target browsers.
Remember
Key Takeaways
Role: submit ltr/rtl alongside a text field’s value.
Value: a field name — the direction is the submitted value.
Elements:textarea and supported text-like input types.
Pair with dir (often auto) for display and detection.
One line:dirname names an extra form field that carries ltr or rtl with the user’s text.
Frequently Asked Questions
It names an extra form field that submits the control’s text direction (ltr or rtl) along with the field value, so the server knows how the user typed the text.
A form field name such as comment-direction — not ltr or rtl. The browser sends ltr or rtl as that field’s value on submit.
textarea, and input types including text, search, url, tel, email, password, hidden, submit, reset, and button (per the HTML living standard / MDN).
dir controls display direction (ltr, rtl, auto). dirname only names the extra submitted field that carries direction to the server.
Often yes for user-typed text. dir="auto" helps the browser detect direction; dirname sends that result with the form.
Use the dirName property (capital N) on HTMLInputElement or HTMLTextAreaElement, for example field.dirName = "comment-direction".