Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
How do we include the direction of text display in HTML?
Use the dir attribute in HTML to specify the text direction. This attribute controls whether text flows left-to-right (LTR) or right-to-left (RTL).
Syntax
<element dir="value">content</element>
Attribute Values
| Value | Description | Use Case |
|---|---|---|
ltr |
Left-to-right | English, French, German |
rtl |
Right-to-left | Arabic, Hebrew, Urdu |
auto |
Browser determines direction | Mixed language content |
Example
Here's how to use the dir attribute for different text directions:
<!DOCTYPE html>
<html>
<head>
<title>Text Direction Example</title>
</head>
<body>
<p>This is default left-to-right text.</p>
<p dir="rtl">This text flows from right-to-left.</p>
<p dir="ltr">This explicitly sets left-to-right direction.</p>
<p dir="auto">Browser will determine: ????? Hello</p>
</body>
</html>
Output
This is default left-to-right text.
.tfel-ot-thgir morf swolf txet sihT
This explicitly sets left-to-right direction.
Browser will determine: ????? Hello
Common Use Cases
The dir attribute is essential for:
- Multilingual websites - Supporting RTL languages like Arabic or Hebrew
- User-generated content - When users input text in different languages
- International applications - Adapting layout for global audiences
Best Practices
Set the direction at the document level for consistency:
<!DOCTYPE html>
<html dir="rtl">
<head>
<title>RTL Document</title>
</head>
<body>
<p>All content flows right-to-left by default.</p>
<p dir="ltr">This paragraph overrides to left-to-right.</p>
</body>
</html>
Conclusion
The dir attribute provides essential text direction control for multilingual websites. Use rtl for right-to-left languages and auto for mixed content where the browser should determine direction automatically.
Advertisements
