To set the text direction, use the direction property with JavaScript. Set rtl for right-to-left or ltr for left-to-right text direction.
Example
You can try to run the following code to set the text direction with JavaScript −
<!DOCTYPE html> <html> <body> <h1 id="myID">Heading 1</h1> <p>Click below to set the direction of heading to Left-to-right</p> <button type="button" onclick="display()">Click to change the direction</button> <script> function display() { document.getElementById("myID").style.direction = "rtl"; } </script> </body> </html>