Set Text Justification
By Stephen Bucaro
Text justification means vertically lining up the first and/or last characters of
every line in a paragraph or on a page. Web browers left justify text by default,
but they leave ragged edges on the right side of paragraphs.
Right text justification can make your webpage look very neat, but you don't get
a free lunch. The browser lines up the ends of sentences by making some lines
longer by inserting extra background pixels between some of the words. So, although
the right edge of your text may look neatly lined up, the interior of your paragraph
will look less neat.
To set text justification, use the CSS text-align property with the value
justify. The easiest way to justify all the text on a webpage is to add the
style attribute to the <body> tag as shown below.
To set text justification for all paragraph elements on a webpage, put a style
block in the <head> section of your webpage (or in a linked style sheet)
with the paragraph selector as shown below.
Text justification looks even neater when you also set margins. To set 20 pixel
wide left and right margins with text justification use the code shown below. This
code can be used with a fluid layout.
The code shown below sets fixed 400 pixel wide paragraphs with text justification.
The code shown below sets fixed 400 pixel wide paragraphs with 20 pixel wide left
and right margins and text justification.
Web browers left justify text by default. Make your webpage look very neat by setting right text justification.
More CSS Quick Reference:
• Use Inline Style
• Set the Text Decoration
• Use an Embedded Style Sheet
• Pseudo-class Selectors
• Set List Bullets Position
• Set an Element's Visibility
• Descendant Selector
• Set the Border Color