textAlign Property - Javascript CSS Style Property

Javascript examples for CSS Style Property:textAlign

Description

The textAlign property sets or gets the horizontal alignment of text in a block level element.

Property Values

Value Description
leftAligns the text to the left. Default
right Aligns the text to the right
center Centers the text
justify The text is justified
initial Sets this property to its default value.
inherit Inherits this property from its parent element.

Technical Details

Item Value
Default Value: left?
Return Value: A String, representing the horizontal alignment of text within the element
CSS VersionCSS1

Center-align the text in a <p> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {/*from w  ww.jav a2  s . c o  m*/
    text-align: justify;
}
</style>
</head>
<body>

<div id="myDIV">
You can use the text-align-last property to align the last line of a text, if the text has the text-align property set to justify. This text is where you will see the result of the  text-align-last property. You can use the text-align-last property to align the last line of a text, if the text has the text-align property set to justify. This text is where you will see the result of the  text-align-last property.
You can use the text-align-last property to align the last line of a text, if the text has the text-align property set to justify. This text is where you will see the result of the  text-align-last property.
You can use the text-align-last property to align the last line of a text, if the text has the text-align property set to justify. This text is where you will see the result of the  text-align-last property.
You can use the text-align-last property to align the last line of a text, if the text has the text-align property set to justify. This text is where you will see the result of the  text-align-last property.
You can use the text-align-last property to align the last line of a text, if the text has the text-align property set to justify. This text is where you will see the result of the  text-align-last property.
You can use the text-align-last property to align the last line of a text, if the text has the text-align property set to justify. This text is where you will see the result of the  text-align-last property.
You can use the text-align-last property to align the last line of a text, if the text has the text-align property set to justify. This text is where you will see the result of the  text-align-last property.
</div>

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {
    document.getElementById("myDIV").style.MozTextAlignLast = "right"; // Code for Firefox
    document.getElementById("myDIV").style.textAlignLast = "right";  // Standard Syntax
}
</script>

</body>
</html>

Related Tutorials