The HTML dirname attribute
Quick answer
The HTML dirname attribute submits the text directionality of the field alongside its value, under the given name. It is used on the <input> and <textarea> elements.
Overview
The dirname attribute submits the text directionality of the field alongside its value, under the given name. It applies to the <input> and <textarea> elements.
When the form is submitted, the server also receives comment.dir=ltr (or rtl), so it can store and re-display user text with the correct direction.
Syntax
<input name="comment" dirname="comment.dir">
Values
| Value |
|---|
A field name to submit the direction under, e.g. comment.dir. |
Best practices
- Give every control a <label> so it has an accessible name.
- Treat client-side constraints as a convenience — always validate again on the server, since they can be bypassed.
- Choose the most specific input type so users get the right on-screen keyboard and built-in checks.
- Keep the submitted name and value meaningful for whatever processes the form.
Frequently asked questions
What does the dirname attribute do?
Submits a field's text direction with the form.
Are HTML form attributes enough for validation?
They give instant feedback, but client-side checks can be bypassed, so always validate on the server too.
Do form controls still need a label?
Yes. Every control needs a <label> for an accessible name, whatever attributes you set.
Which elements use the dirname attribute?
It is an element-specific attribute, used on form controls such as <input>, <select> and <textarea>.