Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I automatically set text direction based on input text language?

In Google plus (and a lot of other places), when I want to post something, when I type it in Persian, which is a right-to-left language, text direction is automatically set to rtl and text-alignment:right, and when I start to type in English it changes automatically to ltr and text-alignment:left. How can I have such functionality? Is this anything with HTML5 or Javascript? What clues should I follow?

Thanks in advance

like image 988
Mostafa Shahverdy Avatar asked Mar 15 '13 20:03

Mostafa Shahverdy


1 Answers

Add dir=auto to your input elements:

Use dir="auto" on forms and inserted text in order to automatically detect the direction of content supplied at run-time.

https://www.w3.org/International/questions/qa-html-dir#quickanswer

like image 94
Amir Nissim Avatar answered Oct 03 '22 02:10

Amir Nissim