HTML dirname Attribute

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

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.

HTML Syntax

syntax.html
<textarea name="comment" dirname=" field-name"></textarea>

Same idea on supported inputs: <input type="text" name="…" dirname="…">. Submitted shape: {dirname_value}={ltr|rtl}.

Attribute Values

One string: the name of the direction field to submit.

ValueDescriptionTry it
dirname="comment-direction"Creates a submitted field named comment-direction with value ltr or rtlTry it
Submitted ltrUser text is left-to-right orientedTry it
Submitted rtlUser text is right-to-left orientedTry it
Inherited directionIf the control has no dir, direction may come from a parent (or the UA default)Try it

Live Preview

Type English or Arabic, then submit. The preview shows the pairs that would be sent (no network request).

Uses dir="auto" and dirname="comment-direction".

Form

Submit to see name/value pairs.

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Textarea with dirname

Arabic sample text submits as comment plus comment-direction=rtl.

HTML
<form method="get" action="/submit">
  <label for="comment">Comment</label>
  <textarea
    id="comment"
    name="comment"
    dir="auto"
    dirname="comment-direction">سيب</textarea>
  <button type="submit">Send</button>
</form>
Try It Yourself

How It Works

  1. name="comment" submits the typed text.
  2. dirname="comment-direction" adds a second field for direction.
  3. dir="auto" lets the browser detect LTR vs RTL from the text.
  4. Result: comment=سيب&comment-direction=rtl (URL-encoded in real GET requests).

Example 2 — Text Input with dirname

Same pattern on <input type="text">.

HTML
<form method="get" action="/submit">
  <label for="greeting">Greeting</label>
  <input
    id="greeting"
    type="text"
    name="comment-input"
    dir="auto"
    dirname="comment-direction"
    value="Hello">
  <button type="submit">Send</button>
</form>
Try It Yourself

How It Works

  1. type="text" is a supported control for dirname.
  2. dirname again names the direction field.
  3. English "Hello" typically submits comment-direction=ltr.
  4. Server can store or render the value with the correct direction.

Example 3 — Direction Inherited from a Parent

Without dir on the control, direction can come from an ancestor.

HTML
<div dir="rtl">
  <form method="get" action="/submit">
    <label for="user">User</label>
    <input id="user" type="text" name="user"
      dirname="user-direction" value="LTR Username">
    <label for="note">Note</label>
    <textarea id="note" name="comment"
      dirname="comment-direction">LTR Comment</textarea>
    <button type="submit">Post</button>
  </form>
</div>
Try It Yourself

How It Works

  1. Parent dir="rtl" sets the context direction.
  2. Controls omit dir, so they inherit that base.
  3. dirname still sends ltr or rtl based on the control’s directionality.
  4. 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.

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 Chrome 17+
Full support
Mozilla Firefox 116+
Full support
Apple Safari 6+
Full support
Microsoft Edge 79+
Full support
Opera 15+
Full support
Samsung Internet Modern
Full support
Internet Explorer No
Not supported
dirname Widely supported

Bottom line: Safe for modern multilingual forms. Always verify the extra direction field arrives on your server in target browsers.

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".

Next: disabled

Disable form controls so they cannot be edited or submitted.

disabled tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful