ToolNimba

πŸ“ Justify Text Tool

Shihab Mia By Shihab Mia Β· Updated 2026-08-04

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. In print or in a word processor this is done by stretching the spaces, and sometimes the letters themselves, until each line reaches the margin exactly. In a plain-text or monospace setting, where every character occupies the same width, you cannot stretch a space by half a pixel, so justification instead works by inserting whole extra space characters between words until each line hits the target character count exactly.

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 gaps between words are 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 convention 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 a given number of characters always occupies the same horizontal space. It is not the line-breaking algorithm used by professional typesetting systems such as TeX, which use the Knuth-Plass algorithm to look ahead across a whole paragraph and minimise overall raggedness. For character-grid text the simpler greedy result is clean, fast, and easy to reason about line by line.

This is also a different mechanism from the text-align: justify property in CSS or the justify button in a word processor. Those tools work with proportional fonts and can stretch, or in some renderers compress, the width of spaces by fractions of a pixel, and modern browsers can add tiny amounts of letter-spacing to smooth the result further. None of that applies to plain text: a text file has no font metrics, so the only lever available is whole space characters, which is exactly what this tool manipulates.

Justified prose is also a readability trade-off worth knowing about. The Web Content Accessibility Guidelines (WCAG 1.4.8) advise against fully justifying large blocks of body text, because uneven word spacing can create vertical rivers of white space that some readers, including people with dyslexia or low vision, find harder to track across a line. That guidance is aimed at paragraphs meant to be read for content, such as articles or blog posts. It does not apply to the technical, fixed-width use case this tool targets: code comments, ASCII layouts, and monospace documents, where a uniform character grid is the point, not a stylistic choice.

Several long-standing plain-text conventions rely on exactly this kind of fixed-width formatting: RFC documents traditionally wrap at 72 or 78 characters, PEP 8 recommends a 79-character line limit for Python source, and the classic Git commit message convention wraps the body at 72 characters so it displays cleanly in any terminal. Justifying to one of these widths gives old-style plain text the same clean, flush-edged block shape you would get from a typeset column, without needing a font at all.

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 signature blocks so both margins line up.
  • Preparing ASCII or monospace layouts, such as terminal banners, 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 that uses a monospace font.
  • Wrapping and justifying Git commit message bodies or RFC-style plain text documents to the traditional 72-column convention.
  • Formatting plain-text licence notices, legal disclaimers, or typewriter-style letters that need a clean flush right margin.

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 that displays text in a fixed-width font.

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 x gaps) gaps getting one more space. The last line of a paragraph keeps single spaces.
Justify Text: Ragged Right to Flush RightBeforeAfterRight edge: raggedRight edge: flush (justified)Purple bars = gaps widened evenly to reach the marginLast line of a paragraph is left unjustified

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

Wrap and justify "Pack my box with five dozen liquor jugs" to a width of 20 characters (shows the greedy fill across multiple lines).

  1. Greedy fill line 1: Pack(4)+my(2)+box(3)+with(4) with 3 spaces = 16 chars, adding "five" would need 21 chars, so line 1 stops at "Pack my box with"
  2. Greedy fill line 2: five(4)+dozen(5)+liquor(6) with 2 spaces = 17 chars, adding "jugs" would need 22 chars, so line 2 stops at "five dozen liquor"
  3. Line 3 is just "jugs", the last line of the paragraph, so it is left unjustified
  4. Line 1: text = 13 chars, gaps = 3, extra = 20 - 13 = 7, base = 2, remainder = 1, so the first gap gets 3 spaces and the other two get 2 spaces
  5. Line 2: text = 15 chars, gaps = 2, extra = 20 - 15 = 5, base = 2, remainder = 1, so the first gap gets 3 spaces and the second gap gets 2 spaces

Result: Pack my box with five dozen liquor 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

Text alignment types compared

AlignmentWhat it doesBest for
Left (ragged right)Text starts flush at the left margin, the right edge is unevenProse, general reading, most web content
RightText ends flush at the right margin, the left edge is unevenNumbers in tables, captions, right-to-left contexts
CenterEach line is centred with equal space on both sidesHeadings, invitations, short lines of a fixed size
Justify (full)Both edges flush, extra space is distributed between wordsFixed-width code blocks, print columns, formal documents

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.
  • Justifying long prose meant to be read on screen. Fully justifying multi-paragraph body text can create uneven rivers of white space that make lines harder to track, which is why accessibility guidance such as WCAG 1.4.8 advises against it for general reading content. Save this tool for fixed-width, technical text and keep prose left-aligned.
  • Not accounting for tabs or wide Unicode characters. The tool counts characters, but a tab does not always occupy one column, and some Unicode characters, such as emoji or East Asian characters, are visually wider than one monospace column even though they count as one or two characters. Replace tabs with spaces first for predictable, aligned output.

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.
River (typography)
A distracting vertical band of white space that appears when several stretched gaps line up down a justified paragraph, most visible with wide word spacing.
CSS text-align: justify
A browser stylesheet property that stretches proportional-font spacing to flush both margins by adjusting rendered font metrics, unlike the plain character-count method this tool uses.
Knuth-Plass algorithm
The line-breaking method used by TeX and many professional typesetters, which looks ahead across a whole paragraph to minimise raggedness, unlike the greedy line-by-line approach used here.

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.

Does this tool hyphenate long words to make them fit?

No, it never splits a word. If a single word is longer than the width you set, that word is placed on its own line and the line runs longer than the target width rather than being broken with a hyphen. Lower the width or break the word yourself if it needs to fit.

Can I justify code without breaking indentation?

Leading spaces on a line are treated as part of the content, so indentation is preserved character for character, only the gaps between words on that line are widened. That said, justifying a code block still changes the internal spacing, so it suits comment text and docstrings better than executable code.

Is justified text good for accessibility and readability?

For long paragraphs meant to be read on screen, no. Full justification can create uneven rivers of white space that make lines harder to track, which is why accessibility guidance such as WCAG 1.4.8 advises against justifying large blocks of body text. This tool targets fixed-width technical text, such as code comments and plain-text files, rather than general web prose.

What is the difference between justify and center align?

Justify spreads extra space between words so both the left and right edges reach the margin, keeping the natural left-to-right reading flow. Centre align instead puts equal blank padding on both ends of each line and leaves the word spacing untouched, so both edges stay ragged.