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.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/html/attributes/html-dir-attribute.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics