Optimal Line Break Calculator
Nearly every text box on nearly every screen wraps greedily: fit as many words as you can on this line, then start another. It is fast and it is often not the tidiest answer, because cramming one line can leave the next three ragged. Considering the paragraph as a whole gives a visibly more even block, and the arrangement found here is not merely better — for a short paragraph it is proved to be the best there is.
What this generator does
Scores each line by how far short of the measure it falls, then finds the set of breaks with the lowest total — and sets the same paragraph greedily alongside it for comparison.
How to use this tool
- Paste a paragraph.
- Set the measure, in characters, that a line may run to.
- Compare the two blocks — the tidiest arrangement against filling each line in turn.
- Narrow the measure to see the difference grow.
Understanding the controls
- The paragraph
- Up to 120 words. Runs of spaces are treated as one, and no word may be longer than the measure.
- Measure
- How many characters a line may run to. Narrow measures make the difference between the two approaches much more visible.
Common use cases
- Setting a pull quote or heading so the lines balance
- Working out where to break a caption by hand
- Comparing wrapping approaches before choosing one
- Explaining why a text block looks ragged when nothing is wrong with it
- Teaching dynamic programming with a result you can see
How this generator works
The cost of a line is the square of what it falls short by, which punishes one very short line more than two slightly short ones. The last line is free, since a paragraph is meant to end early. For paragraphs of eighteen words or fewer, every possible set of breaks is enumerated and compared, so the arrangement shown is demonstrably the best rather than the best found.
Randomness and fairness
Nothing is random. The same paragraph and measure always give the same arrangement.
For how randomness is produced across the whole site, see how Generate Random works.
Limitations and good to know
- Widths are counted in characters, so this matches a monospaced setting. Proportional type needs real character widths.
- No hyphenation: words are never split, which is a real constraint that changes what is possible.
- The cost is the square of the shortfall, which is one reasonable choice among several — cubes punish a bad line harder.
- Widows, orphans, rivers and the other things typesetters care about are not considered.
Privacy and your data
Your text stays in your browser. Nothing you paste is transmitted or stored.
Related generators
- Plus Code ConverterTurns a latitude and longitude into an Open Location Code, and shows exactly which patch of ground it names.
- Geohash ConverterTurns coordinates into a geohash, whose useful trick is that nearby places usually share a prefix.
- Colour Palette GeneratorGenerate a real colour palette — six harmony types, with hex, RGB and HSL values and the contrast each colour gives with text.
- Print Resolution CalculatorHow large an image prints at a given resolution, in inches and centimetres, with an honest verdict on quality.