Text Justification Tricks
To justify a block of text (line up both the left edge and the right edge), use the CSS text-align:justify;
declaration. Example:
I picked a wonderful-smelling ripe peach from the bowl and meandered outside to the pool. Sitting on the edge, feet dangling in the water, I thoroughly enjoyed that tasty fruit.
Here is the format for the above example:
<p style="text-align:justify;">(your text)</p>
That is the usual way text is justified. Yet, there are a couple tricks I will reveal here.
Notice how the last line of the above example paragraph is not justified to the right edge of the block of text? Well, that can be fixed with the CSS text-align-last:justify;
declaration. Here is the example with the last line also justified:
I picked a wonderful-smelling ripe peach from the bowl and meandered outside to the pool. Sitting on the edge, feet dangling in the water, I thoroughly enjoyed that tasty fruit.
Here is the format for that second example:
<p style="text-align:justify; text-align-last:justify;">(your text)</p>
Generally, for the English language at least, line justification is accomplished by adjusting the space between words.
For some situations, justifying lines by adjusting the space between letters instead of between words may be preferred. Yes, that can be done. Use the CSS text-justify:inter-character;
declaration. Here is an example of inter-character justification:
I picked a wonderful-smelling ripe peach from the bowl and meandered outside to the pool. Sitting on the edge, feet dangling in the water, I thoroughly enjoyed that tasty fruit.
Here is the format for the inter-character justification example:
<p style="text-align:justify; text-justify:inter-character;">(your text)</p>
And, if you wish to also justify the last line, include the earlier-mentioned CSS text-align-last:justify;
property:
I picked a wonderful-smelling ripe peach from the bowl and meandered outside to the pool. Sitting on the edge, feet dangling in the water, I thoroughly enjoyed that tasty fruit.
Here is the format for the second inter-character justification example:
<p style="text-align:justify; text-justify:inter-character; text-align-last:justify;">(your text)</p>
Notice that in every example, the CSS text-align:justify;
declaration is present. The text-align-last
property and the text-justify
property modify, not replace, what the text-align:justify;
declaration does.
You now have tools to justify text content in ways a simple text-align:justify;
won't accomplish all by itself.
(This content first appeared in Possibilities newsletter.)
Will Bontrager