ToolNimba Browse

📐 Justify Text Tool

By ToolNimba Text Team · Updated 2026-06-19

Options
0
Words
0
Lines out
60
Width

Type some text and set a width to justify it.

This justify text tool lays your text out to a fixed character width and full-justifies it, the way old typewriters and code comments do. It packs as many words onto each line as will fit, then spreads the leftover spaces evenly between the words so both edges line up. Paste your text, set the width in characters, and copy the monospace result. Everything runs in your browser, so the text never leaves the page.

What is the Justify Text Tool?

Full justification means a block of text is flush on both the left and right edges, with no ragged right margin. On a printing press or in a word processor this is done by stretching the spaces (and sometimes the letters) until each line reaches the margin. In a plain-text or monospace setting, where every character is the same width, you cannot stretch a space by half a pixel, so justification is done by inserting whole extra space characters between words until the line is exactly the target width.

The method here has two stages. First a greedy line fill packs words onto a line one at a time, adding a word only while it still fits within the width (counting one space between neighbours). When the next word would overflow, the current line is closed and the word starts a new line. Second, for every line except the last of each paragraph, the gap between words is widened: the tool works out how many extra spaces are needed, divides them as evenly as possible across the gaps, and gives the leftmost gaps one extra space when the division is not exact. The last line is left alone, because stretching a short final line looks wrong, the same rule typesetters follow.

This greedy approach is fast and predictable, and it is exactly what fixed-width contexts expect: aligned columns in a README, comment blocks in source code, ASCII layouts, or any place a monospace font guarantees that N characters always occupy the same horizontal space. It is not the line-breaking algorithm used by professional typesetting systems, which look ahead across the whole paragraph to minimise overall raggedness, but for character-grid text the greedy result is clean and easy to reason about.

When to use it

  • Formatting code comment blocks or docstrings to a consistent 60, 72, or 80 column width.
  • Laying out plain-text README, changelog, or email signatures so both margins line up.
  • Preparing ASCII or monospace layouts where every line must reach the same character width.
  • Reflowing pasted prose into a tidy fixed-width block for a terminal, config file, or forum post.

How to use the Justify Text Tool

  1. Paste or type your text into the input box.
  2. Set the line width in characters (for example 60, 72, or 80).
  3. Optionally choose whether to stretch the last line of each paragraph and whether to keep blank lines between paragraphs.
  4. Read the justified, monospace result and click Copy to use it anywhere.

Formula & method

For each line: extra spaces = width − (sum of word lengths). gaps = words − 1. base = floor(extra ÷ gaps) spaces per gap, with the first (extra − base × gaps) gaps getting one more space. The last line of a paragraph keeps single spaces.

Worked examples

Justify the line "the quick brown fox" to a width of 20 characters.

  1. Word lengths: the=3, quick=5, brown=5, fox=3, so text characters = 16
  2. Gaps between words = 4 − 1 = 3
  3. Extra spaces needed = 20 − 16 = 4
  4. base = floor(4 ÷ 3) = 1 space per gap, remainder = 4 − 3 = 1
  5. The first gap gets 1 + 1 = 2 spaces, the other two gaps get 1 space each
  6. Result: the(2)quick(1)brown(1)fox, length = 3+2+5+1+5+1+3 = 20

Result: the quick brown fox

Justify "pack my box with jugs" to a width of 24 characters.

  1. Word lengths: pack=4, my=2, box=3, with=4, jugs=4, so text characters = 17
  2. Gaps between words = 5 − 1 = 4
  3. Extra spaces needed = 24 − 17 = 7
  4. base = floor(7 ÷ 4) = 1 space per gap, remainder = 7 − 4 = 3
  5. The first 3 gaps get 2 spaces, the last gap gets 1 space
  6. Result length = 17 + (2+2+2+1) = 24

Result: pack my box with jugs

Common fixed-width line lengths and where they are used

Width (chars)Typical use
40Narrow columns, mobile-friendly plain text
60Comfortable prose width for emails and notes
72Classic email and Git commit body wrapping
79 to 80Source code lines (PEP 8, terminal width)
100 to 120Modern wide code style guides

How "ToolNimba makes free tools" justifies at different widths

WidthOutput
25ToolNimba makes free tools
28ToolNimba makes free tools
30ToolNimba makes free tools

Common mistakes to avoid

  • Expecting it to work in a proportional font. Character-count justification only lines up visually in a monospace (fixed-width) font, where every character is the same width. Pasted into a normal proportional font, the right edge will look ragged again because spaces and letters have different widths.
  • Setting the width narrower than your longest word. If a single word is longer than the line width, it cannot be split (this tool does not hyphenate), so that word sits on its own line and overflows the target width. Raise the width or break the word yourself.
  • Wanting the last line stretched by default. Like proper typesetting, the last line of each paragraph is left with single spaces, because a stretched final line looks odd. If you genuinely need every line padded, turn on the option to justify the last line too.
  • Confusing justify with centre or right align. Justify makes both edges flush by widening the gaps between words. Centring or right-aligning instead adds padding only on one or both ends and leaves the word spacing untouched.

Glossary

Justify (full justification)
Text aligned flush to both the left and right margins, achieved by adjusting the space between words.
Monospace font
A typeface where every character occupies the same horizontal width, so character counts map directly to visual width.
Greedy line fill
A line-breaking method that puts as many words as possible on each line before moving to the next, deciding one line at a time.
Gap
The space between two adjacent words on a line. Extra spaces for justification are added into the gaps.
Ragged right
Left-aligned text where line ends do not reach a common right margin, the opposite of a justified right edge.

Frequently asked questions

What does this justify text tool actually do?

It full-justifies plain text to a fixed character width. It packs words onto each line, then adds whole space characters between the words so the line reaches the exact width you set, giving a flush right edge in a monospace font.

Why does the right edge look uneven when I paste the result elsewhere?

The alignment relies on every character being the same width, which is only true in a monospace font. In a proportional font, spaces and letters have different widths, so the carefully counted spacing no longer lines up. Display the output in a monospace font to keep it justified.

Why is the last line of each paragraph not stretched?

Stretching a short final line spreads a few words across the full width and looks wrong, so by convention the last line keeps single spaces. If you want every line padded to the width, switch on the option to justify the last line too.

What width should I choose?

It depends on the use. 72 characters is the classic width for emails and Git commit messages, 79 or 80 for source code, and 60 to 65 for comfortable prose. Pick whatever matches the place the text will live.

How are the extra spaces distributed between words?

The tool counts how many extra spaces a line needs, divides them as evenly as possible across the gaps between words, and gives the leftmost gaps one extra space when the number does not divide evenly. This keeps the spacing as balanced as a character grid allows.

Is my text uploaded anywhere?

No. The tool runs entirely in your browser using plain JavaScript. Your text is never sent to a server, so you can safely justify private or sensitive content.