HTML / HTML Attributes

HTML Dirname Attribute

Dec 12, 2022
2 min read
HTML dirname Attribute

Definition

The dirname Attribute on a form control element allows the submission of the element’s directionality along with the form data.

Applicable Elements

The dirname Attribute can be used with the following elements:

HTML <input> dirname Attribute

The dirname attribute, when used with the <input> element, allows the element’s directionality to be submitted along with the form.

The directionality value will be either rtl or ltr.

This is particularly useful when the direction of the form field is unknown but would be helpful to know when processing the field data later.

For example, when collecting the people’s names, you may want to know the direction of the name field to ensure the name is not spelled backward when used at a later date.

Syntax

<input type="text" name="name" dirname="name.dir">

Usage

  • The dirname attribute takes the name of the control element, followed by .dir.

Values

Values can include:

  • The name of the control element that contains this attribute.

Examples

In the following example, when the user submits the form, it includes three fields, including the field examplename.dir with the value of either ltr or rtl.

<form action="/action.php">
  Name: <input type="text" name="examplename" dirname="examplename.dir">
  <button name="submit" type="submit" value="Submit">Submit</button>
</form>

HTML <textarea> dirname Attribute

The dirname attribute, when used with the <textarea> element, allows the element’s directionality to be submitted along with the form.

The directionality value will be either rtl or ltr.

This is useful when you do not know the text’s language, for example, a review or blog comments written in Arabic.

Syntax

<textarea name="name" dirname="name.dir"></textarea>

Usage

  • The dirname attribute takes the name of the control element, followed by .dir.

Values

Values can include:

  • The name of the control element that contains this attribute.

Examples

In the following example, when the user submits the form, it includes three fields, including the field reviewname.dir with the value of either ltr or rtl.

<form action="/action.php">
  Review: <textarea name="reviewname" dirname="reviewname.dir"></textarea>
  <button name="submit" type="submit" value="Submit">Submit</button>
</form>

Specification

The dirname HTML specification for the <input> and <textarea> elements is as follows:

Browser Support

The dirname has the following browser support:

Desktop

ChromeEdgeFirefoxIEOperaSafari
<input>YesYesNoNoYesYes
<textarea>YesYesNoNoYesYes

Mobile

Android WebviewChrome AndroidFirefox AndroidOpera AndroidiOS SafariSamsung Internet
<input>YesYesNoYesYesYes
<textarea>YesYesNoYesYesYes