The dirname attribute lets a form submit the text direction of user input alongside the field value. Use it on <textarea> and certain <input> types so your server receives both the text and whether it was typed left-to-right (ltr) or right-to-left (rtl). It is not the same as the dir attribute.
01
Form Submit
Extra direction field.
02
Field Name
Not ltr or rtl.
03
textarea
Common use case.
04
text Inputs
Search, email, etc.
05
Pair with dir
Display + submit.
06
dirName JS
Set dynamically.
Fundamentals
Purpose of dirname
When users type in multilingual forms, the server often needs to know whether the input is LTR or RTL so it can store, display, or process the text correctly. The dirname attribute solves this by adding a second name/value pair to the form submission.
If you write dirname="comment-dir" on a textarea named comment, the browser submits both comment=… and comment-dir=ltr (or rtl). The browser determines direction from the element’s dir attribute and the text content.
⚠️
Not a direction keyword
dirname="ltr" is incorrect. The attribute value is the name of the direction field (e.g. comment-dir), not the direction itself.
Foundation
📝 Syntax
Add dirname with a field name on a supported control, and pair it with dir:
dir sets how text appears. dirname names the extra field the server reads to learn that direction on submit.
A11y
♿ Accessibility & UX
Use dir="auto" with dirname — Lets users type in their natural direction while the server still receives direction metadata.
Store direction server-side — Preserve ltr / rtl when re-displaying user comments in multilingual apps.
Do not replace lang — dirname reports direction, not language; still use lang where appropriate.
RTL layout still matters — Submitting direction does not mirror your page layout; use CSS logical properties for RTL UI.
🧠 How dirname Works
1
Author adds dirname
Set a field name like comment-dir on the control.
Markup
2
User types text
Browser detects LTR or RTL from dir and content.
Input
3
Form is submitted
Two pairs sent: value + direction field.
Submit
=
🌐
Server knows direction
Backend can store and render multilingual input correctly.
Compatibility
Browser Support
The dirname attribute is supported in modern browsers. It is a newer HTML feature; test form submission in your target browsers.
✓ HTML5 · Modern browsers
Form direction submission
Chrome, Firefox, Safari, and Edge support dirname on textarea and supported input types.
95%Browser support
Google ChromeSupported
Full support
Mozilla FirefoxSupported
Full support
Apple SafariSupported
Full support
Microsoft EdgeSupported
Full support
dirname attribute95% supported
Bottom line: Use dirname in modern apps; provide a hidden-field fallback for very old browsers if needed.
Pro Tips
💡 Best Practices
✅ Do
Use a clear dirname field name (e.g. comment-dir)
Pair dirname with dir="auto" on the same control
Store submitted direction on the server
Use on textarea for multilingual comments
Test GET/POST query strings in devtools
❌ Don’t
Set dirname to ltr or rtl (that is dir's job)
Use dirname on unsupported input types
Confuse dirname with the dir attribute
Assume dirname changes visual direction alone
Skip server-side validation of submitted text
Wrap Up
Conclusion
The dirname attribute is a practical tool for multilingual forms. It submits the text direction of user input as a separate form field so your server can process LTR and RTL content correctly.
Remember: the attribute value is a field name, not a direction keyword. Combine dirname with dir for display and submission together.