How to work with the dirname attribute in HTML?


The HTML dirname Attribute is utilised to enable the text direction of the input and the Textarea Field after submitting the form. The name of the input field and textarea followed by ".dir" must be the value of the dirname property.

Following are the examples…

dirname attribute in <input> Element:

Syntax

<input name="myname" dirname="myname.dir">

Example

In the following example we are using the dirname attribute in input element.

<!DOCTYPE html> <html> <body> <form action="https://www.tutorialspoint.com/index.htm"> First name: <input type="text" name="varma" dirname="varma.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

On executing the above script it will generate the input type field of firstname along with a submit button. After clicking the submit button, the form along with the text direction of the inputfield gets submitted.

dirname attribute in <textarea> Element:

Syntax

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

Example

In the following example we are using dirname attribute in textarea element.

<!DOCTYPE html> <html> <body> <form action="https://www.tutorialspoint.com/index.htm"> <textarea name="varma" dirname="varma.dir" placeholder="write something here"> </textarea> <input type="submit" value="Submit"> </form> <p> After the Submission of the form, the text direction of the Textarea field will also, be submitted. </p> </body> </html>

Output

When the script is executed, it will provide a textarea field along with the submit button. After clicking the submit button, the form gets submitted along with the text direction of the textarea field.

Updated on: 05-Sep-2022

130 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements