Greedy vs optimal
Browsers break lines greedily — they fill each line as full as possible, then wrap. This creates uneven spacing and "rivers" of white running down paragraphs. Knuth-Plass considers the entire paragraph at once, finding the globally optimal set of breakpoints.
Typography is the craft of endowing human language with a durable visual form, and thus with an independent existence. Its heartbeat is the letterform, but typography involves far more than the shape of individual letters. It is the arrangement of those letters into words, words into lines, and lines into pages — the governing of relationships between all these elements and the space that surrounds them.
Typography is the craft of endowing human language with a durable visual form, and thus with an independent existence. Its heartbeat is the letterform, but typography involves far more than the shape of individual letters. It is the arrangement of those letters into words, words into lines, and lines into pages — the governing of relationships between all these elements and the space that surrounds them.
Narrow columns
KP shines brightest in narrow columns where greedy breaking creates wild spacing swings. The narrower the measure, the more breakpoint choices matter.
Good typography requires attention to detail that goes far beyond choosing the right typeface. The spaces between letters, words, and lines are just as important as the marks themselves.
Good typography requires attention to detail that goes far beyond choosing the right typeface. The spaces between letters, words, and lines are just as important as the marks themselves.
Good typography requires attention to detail that goes far beyond choosing the right typeface. The spaces between letters, words, and lines are just as important as the marks themselves.
Good typography requires attention to detail that goes far beyond choosing the right typeface. The spaces between letters, words, and lines are just as important as the marks themselves.
Book-quality text
Serif type at reading sizes is where justification quality is most visible. Here's what KP does with a proper book paragraph — Newsreader at 17px, 32em measure.
It is a truth universally acknowledged, that a single man in possession of a good fortune, must be in want of a wife. However little known the feelings or views of such a man may be on his first entering a neighbourhood, this truth is so well fixed in the minds of the surrounding families, that he is considered as the rightful property of some one or other of their daughters. "My dear Mr. Bennet," said his lady to him one day, "have you heard that Netherfield Park is let at last?" Mr. Bennet replied that he had not. "But it is," returned she; "for Mrs. Long has just been here, and she told me all about it."
Try it yourself
Drag the slider to change the column width. Watch how KP rebalances every line simultaneously — it's not just wrapping differently, it's re-solving the entire paragraph.
How it works
The algorithm assigns a badness score to each possible line based on how much its spacing deviates from ideal. It then uses dynamic programming to find the set of breakpoints that minimizes total badness across the entire paragraph.
slack = maxWidth - lineWidth
ratio = slack / maxWidth
badness = |ratio|3 × 100
penalty = (1 + badness)2
// Loose lines penalized heavily
if ratio > 0.5 → penalty += 10000
// Last line: minimal penalty (left-aligned)
if lastLine → penalty = 1
Cubic badness means tight lines are tolerable but loose lines are punished exponentially. The squared penalty-of-penalties means the algorithm strongly prefers consistent spacing over mixing tight and loose lines.