HTML dirname Attribute

The dirname attribute on an input element submits the element‘s text direction, ltr (left-to-right) or rtl (right-to-left), together with the input value.

Elements that accept this attribute include <input>, and <textarea>.



An <input> element with a dirname attribute.
Submitting this form will send the text input value and its direction.

<form action="/tutorial/action.html">
  <label for="firstname">First name</label><br />
  <input type="text" id="firstname" 
         name="firstname" dirname="firstname.dir">
  <br /><br />

  <input type="submit" value="Submit">

For additional details see our HTML input dirname Reference.

Using dirname

The name of this attribute must be the input field name followed by .dir.

This attribute helps in identifying the correct direction for an input value.

Here is a list of the languages that are written from right-to-left (rtl):

  • Arabic
  • Aramaic
  • Azeri
  • Dhivehi/Maldivian
  • Hebrew
  • Kurdish (Sorani)
  • Persian/Farsi
  • Urdu


<tagname name="input-name" dirname="input-name.dir" >



Value Description
input-name.dir Submits the text direction of the input value.
Possible values are ltr (left-to-right) or rtl (right-to-left).

Elements that accept dirname

The following input elements accept the dirname attribute.

Elements Description
<input> Specifies an input field -- see example above
<textarea> Specifies a multi-line text field.

<textarea> with dirname

A <textarea> tag with a dirname attribute.

<form action="/tutorial/action.html">
  <label for="message">Message:</label><br />
  <textarea id="message" name="message" 
            dirname="message.dir" cols="50"></textarea><br/>

  <input type="submit" value="Submit">

For additional details see our HTML textarea dirname Reference.

Browser support

Here is when dirname support started for each browser:

1.0 Sep 2008
Not Supported
79.0 Jan 2020
1.0 Jan 2006
1.0 Jan 2003

You may also like

Author: Jack Poorte
Published: Jun 20 2021
Last Reviewed: Sep 30 2023

What's your favorite/least favorite part of Dofactory?