Text Justifier

Justifies each line of a paragraph by distributing extra spaces evenly between its words until the line reaches an exact target width, the same effect as fully justified text in a word processor, while leaving the last line of each paragraph untouched. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-23

Overview

Introduction

Fully justified text, where both the left and right edges of a paragraph line up evenly, is a common look in print and formal documents.

Achieving it in plain text by hand means carefully counting characters and inserting the right number of extra spaces between words on every line.

What Is Text Justifier?

A justifier that distributes extra spaces evenly between the words of each line so the line reaches an exact target width, leaving the last line of each paragraph untouched.

It runs entirely client-side as part of this site's String Tools collection, so nothing you paste is ever uploaded to a server.

How Text Justifier Works

For each line except the last in a paragraph, the tool splits it into words, computes how many extra spaces are needed to reach the target width, and spreads that count as evenly as possible across the gaps between words, giving any remainder to the leftmost gaps.

Paragraphs are detected by blank lines in the input, and the transformation happens synchronously in JavaScript the moment you type.

When To Use Text Justifier

Use it to prepare plain-text output that mimics a justified print layout, format monospace documentation, or create an evenly edged text block for a terminal UI.

It's a fast way to get the answer without opening a code editor, a REPL, or writing a one-off script just to check.

Often used alongside Word Wrapper, Left Aligner and Right Padder.

Features

Advantages

  • Distributes extra spacing evenly rather than dumping it all in one gap.
  • Correctly leaves the final line of each paragraph unjustified, matching conventional typography.

Limitations

  • Lines must already be broken at the desired width; this tool doesn't re-wrap text, only stretches existing lines (pair it with the Word Wrapper tool first).

Examples

Justifying a line to width 20

Input

the quick brown fox

Output

the  quick brown fox

With width=20, one extra space is needed and is added at the first gap, giving each gap between words either one or two spaces so the line reaches exactly 20 characters.

Best Practices & Notes

Best Practices

  • Run text through a word wrapper first so each line is already close to the target width before justifying, which keeps the extra spacing subtle.

Developer Notes

Paragraphs are split on blank-line boundaries (`/\n\s*\n/`); within each paragraph, every line except the last is justified by computing `baseSpaces = Math.floor(totalSpaces / gaps)` and distributing the `remainder` to the leftmost gaps so spacing differs by at most one space per gap.

Text Justifier Use Cases

  • Formatting a plain-text document to mimic a print-style justified paragraph
  • Creating an evenly edged text block for a terminal-based UI
  • Preparing monospace documentation with clean right-hand margins

Common Mistakes

  • Applying justification to lines that are much shorter than the target width, which stretches spacing so much the text becomes hard to read.

Tips

  • Choose a target width close to your longest natural line length to avoid excessive stretching on shorter lines.

References

Frequently Asked Questions