Two-column layouts, justified text and hyphenation in HTML to PDF

CSS columns flow across pages cleanly; hyphenation works only with a lang attribute. Tested examples and copy-paste CSS.

Updated · 4 min read

Newsletters, academic papers and reports often use two columns and justified text. CSS can do both, and the converter handles them well, with one catch: automatic hyphenation only works when the page declares its language.

Columns that flow across pages

.article { columns: 2; column-gap: 8mm; column-rule: 1px solid #ccc; }
.article h1 { column-span: all; }   /* title across both columns */

We converted a three-page article with these rules. Text filled the left column, then the right, then continued at the top of the next page. On the last page the two columns were balanced to the same height, and the title spanned both columns.

Two PDF pages in two columns. Page one has a title spanning both columns above full columns of text. The last page has two shorter columns of equal height.
Page one and the last page of a two-column article: full columns, then balanced columns at the end.

Justified text needs hyphenation

Justified text in narrow columns leaves wide gaps between words. Hyphenation fills them:

<html lang="en">
…
.article { text-align: justify; hyphens: auto; }
Two versions of the same justified two-column text. Without hyphenation, some lines have very wide gaps between words. With hyphenation, words such as be-fore and intro-duced are split and the spacing is more even.
The same justified text without hyphenation (left) and with hyphens: auto (right).

Hyphenation only works with lang

The converter hyphenates using a dictionary for the page’s language. In our test, the same narrow paragraph got 6 hyphens with lang="en", 15 with lang="de" (German has longer words), and none at all without a lang attribute. Set it on <html>, and on any passage in another language.

Tips for columns

  • Keep figures in one column with break-inside: avoid, or make them span both columns with column-span: all.
  • Keep headings with their text with break-after: avoid.
  • Mind the width. Two columns on A4 portrait are about 90 mm each, roughly 55 to 60 characters at 10pt. Three columns usually need landscape.
  • Use columns for flowing text only. For dashboards and card layouts use grid or flexbox; see responsive layouts in PDF.