HTML dirname Attribute

HTML dirname Attribute: This attribute helps to enable the text direction of the given input and textarea field by submission of the form. It also comes with the extension of “.dir“. The dirname attribute is not supported in HTML 4. It was added newly to HTML 5.

HTML dirname Attribute

The HTML dirname attribute can applied to the <input> and <textarea> elements.

Syntax: <input name=”myname” dirname=”myname.dir”>

Browser Support

The HTML dirname attribute is supported by the following browsers:

  • Chrome
  • Safari
  • Firefox
  • Opera
  • Internet Explorer

Example: for <input> element

<!DOCTYPE html> 
<html> 

<head> 
  <style> 
    h1 { 
      color: green; 
    } 
  </style> 
</head> 

<body> 

  <form action="/action_page.php"> 
    <h1> 
    Freshersnow
  </h1> 
    <h2> 
    HTML | dirname attribute 
  </h2> 
  First name: 
    <input type="text"
      name="fname"
      dirname="fname.dir"> 
    
    <input type="submit"
      value="Submit"> 
  </form> 

  <p>After the Submission of the form, 
  the text direction of the input field 
  will also be submitted. 
</p> 

</body> 

</html> 


Output:

HTML dirname attribute

Example: for <textarea> element

<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
  Text:<br>
  <textarea name="explanation"dirname="explanation.dir"></textarea>
  <input type="submit" value="Submit">
</form>
<p>When the form is being submitted, the text direction of the textarea will also be submitted.</p>
</body>
</html>

Output

HTML dirname textarea element