Style directionProperty
Style Object
Definition and Usage
The direction property sets or returns the text direction of an element.
Syntax
Set the direction property:
Object.style.direction="ltr|rtl|inherit"
Return the direction property:
Object.style.direction
| Value | Description |
|---|---|
| ltr | Default. The text flow goes from left to right. |
| rtl | The text flow goes from right to left. |
| inherit | The text direction is inherited from the parent element. |
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the direction property.
Note:IE7 and earlier versions do not support the "inherit" value. IE8 only supports "inherit" if a !DOCTYPE is specified. IE9 supports "inherit".
Example
Example
Set the text flow to right-to-left:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial(example.com)</title>
<script>
function displayResult(){
document.getElementById("p1").style.direction="rtl";
}
</script>
</head>
<body>
<p id="p1">This is some text.</p>
<br>
<button type="button" onclick="displayResult()">Set text direction from left to right</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial(example.com)</title>
<script>
function displayResult(){
document.getElementById("p1").style.direction="rtl";
}
</script>
</head>
<body>
<p id="p1">This is some text.</p>
<br>
<button type="button" onclick="displayResult()">Set text direction from left to right</button>
</body>
</html>
Try it Yourself »
Style Object Other Extensions