direction Property - Javascript CSS Style Property

Javascript examples for CSS Style Property:direction

Description

The direction property sets or gets the text direction.

Property Values

Value Description
ltr Text displays from left to right. This is default
rtl Text displays from right to left
initial Sets this property to its default value.
inherit Inherits this property from its parent element.

Technical Details

Item Value
Default Value: ltr?
Return Value: A String, representing the text direction of an element
CSS VersionCSS2

Set the text direction of a <p> element to "right-to-left":

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p id="myP" style="direction:rtl;">This is an example paragraph.</p>

<button type="button" onclick="myFunction()">Return text direction</button>

<script>
function myFunction() {/*from w ww .j  a  va 2  s . c om*/
    document.getElementById("myP").style.direction = 'rtl';
}
</script>

</body>
</html>

Related Tutorials