You are here: Reference > JavaScript > client-side > style handling > properties > textJustify

textJustify style property

Browser support:
Specifies or returns how justified text should be aligned and spaced.
This property has effect only if the value of the textAlign property is set to 'justify'.

Syntax:

object.textJustify;
You can find the related objects in the Supported by objects section below.
This property is read/write.
CSS page for this property: text-justify

Possible values:

The type of this property is string.
 One of the following values: 
auto
The browser determines the appropriate justification algorithm.
distribute
Like the newspaper value, except that in East Asian languages (such as Thai) the last line is not justified.
distribute-all-lines
Like the newspaper value, except that the last line is also justified.
inter-cluster
Only content that does not contain any inter-word spacing (such as Asian languages) is justified.
inter-ideograph
Justifies content with ideographic text.
inter-word
Increases the spacing between words.
kashida
Justifies content by elongating characters.
newspaper
Spacing between letters and words are increased or decreased.
Default: auto.

Example HTML code 1:

This example illustrates the use of the text-justify property:
<head>
    <style>
        .lastLeft {
            text-justify: distribute;
            text-align: justify;
        }
        .lastJustify {
            text-justify: distribute-all-lines;
            text-align: justify;
        }
    </style>
</head>
<body>
    <div class="lastLeft">
        The text of the first line is justified alonglonglonglonglonglonglonglonglongword.
        Next line is justified too alonglonglonglongword.
        The last line is aligned to left.
    </div>
    <br />
    <div class="lastJustify">
        The text of the first line is justified alonglonglonglonglonglonglonglonglongword.
        Next line is justified too alonglonglonglongword.
        The last line is justified too.
    </div>
</body>
Did you find this example helpful? yes no

Example HTML code 2:

This example illustrates the use of the textJustify property in JavaScript:
<head>
    <script type="text/javascript">
        function ChangeTextJustify (selectTag) {
            // Returns the index of the selected option
            var whichSelected = selectTag.selectedIndex;

            // Returns the text of the selected option
            var justifyValue = selectTag.options[whichSelected].text;

            var div = document.getElementById ("myDiv");
 
            if ('textJustify' in div.style) {
                div.style.textJustify = justifyValue;
            } else {
                alert ("Your browser doesn't support this example!");
            }
        }
    </script>
</head>
<body>
    <div id="myDiv" style="text-align: justify;">
        Pellentesque metus. Sed rhoncus sem quis augue. Phasellus rutrum dui vitae justo tincidunt sollicitudin. Maecenas magna. Mauris nec orci. Nunc laoreet convallis arcu. Aenean diam urna, condimentum et, facilisis luctus, accumsan et, pede. Praesent quam orci, elementum nec, laoreet at, tristique ac, sem. Sed eu tortor vel dolor laoreet vulputate. Pellentesque faucibus diam et libero. Mauris tristique malesu.
        align last line within the object
    </div>

    <br />
    Change text-justify value:
    <br />
    <select size="8" onchange="ChangeTextJustify (this);">
        <option selected="selected" />auto
        <option />distribute
        <option />distribute-all-lines
        <option />inter-cluster
        <option />inter-ideograph
        <option />inter-word
        <option />kashida
        <option />newspaper
    </select>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content