Computer >> Computer tutorials >  >> Programming >> HTML

How to set text direction in HTML?


To set text direction in HTML, use the style attribute. The style attribute specifies an inline style for an element. The style attribute is used with the CSS property direction to set direction. Just keep in mind, the usage of style attribute overrides any style set globally. It will override any style set in the HTML <style> tag or external style sheet.

You can use the following property values to set direction −

Sr.NoValue & Description
1ltr
Writing direction from left to right
2rtl
Writing direction from right to left
3initial
Default value

 

How to set text direction in HTML?

Example

You can try to run the following code to set text direction in HTML

<!DOCTYPE html>
<html>
<head>
<title>HTML Text Direction</title>
</head>
<body>
   <p style = "direction: rtl;">
      This text will get displayed from right to left
   </p>
   <p>This is normal text.</p>
</body>
</html>