PDFPipe

Text and typography / text-align: justify

Should PDF body text be justified

Justified text stretches the spaces on each line so both edges align. It is the default in most printed books and it needs hyphenation to look right.

What it is for

Justification without hyphenation produces very uneven word spacing in narrow measures, which reads worse than a ragged edge. The two settings belong together or not at all.

Support: Works everywhere

Supported. text-justify, which controls the algorithm, is much less consistently implemented and is usually not worth relying on.

The syntax

Written the way it would appear in a document stylesheet, using text-align: justify as intended.

css
/* Together, or neither. */
.document p {
  text-align: justify;
  hyphens: auto;   /* needs lang on html */
}

/* Not in narrow columns, where the spacing damage outweighs the tidy edge. */
.sidebar p {
  text-align: left;
  hyphens: none;
}

The mistake people make

Justifying a narrow column without hyphenation. The result has visible rivers of white running down the block, which is worse than the ragged right edge it replaced.

Frequently asked

Does text-align: justify work when generating a PDF?

Works everywhere. Supported. text-justify, which controls the algorithm, is much less consistently implemented and is usually not worth relying on.

How would I know if it were not working?

You would not, from the CSS. Unimplemented and unmatched CSS both fail silently, which is why the reliable test is to set a deliberately extreme value and see whether anything changes. If a 40mm margin looks the same as an 18mm one, the rule is not reaching the page.

Related properties

Things that come up in the same part of a document stylesheet.

Paste the CSS and see what the rendered page does with it.