HTML dir attribute
dir
The dir attribute of HTML sets the direction of the text within an element in HTML document.
Supported elements
HTML dir attribute supports all elements except applet, base, basefont, bdo, br, frame, frameset, iframe, param, script.
For bdo element, dir attribute is used to set bidirectional.
Syntax
<ElementName dir="value">.....</ElementName>
Where ElementName is any supported element.
Type of value
Predefined.
Value
Value | Description |
---|---|
ltr | Left to right direction. |
rtl | Right to left direction. |
Default value
There is no default value of HTML dir attribute. But in practice, unless otherwise mentioned ltr (i.e. left to right) is taken as the default value.
Supported doctypes
HTML 4.01 strict, HTML 4.01 transitional, HTML 4.01 frameset.
Example of HTML dir attribute
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example dir attribute - HTML tutorial | w3resource</title>
</head>
<body>
<p dir="ltr" >This text is in left to right direction.</p>
<p dir="rtl">טקסט זה בשטחים השמאלי בכיוון הנכון</p>
</body>
</html>
Result
This text is in left to right direction.
טקסט זה בשטחים השמאלי בכיוון הנכו
View this example in a separate browser window
Usage of dir attribute with bdo element
<bdo dir="rtl">Some left to right text</bdo>
Previous: HTML defer attribute
Next: HTML disabled attribute
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook