Overview
Introduction
Plain text destined for a fixed-width terminal, a monospace email, or printed output often needs hard line breaks at a specific column, not just visual soft-wrapping in an editor.
Manually inserting those breaks at the right word boundary across a long paragraph is slow and easy to get wrong.
What Is Word Wrapper?
A word wrapper that reflows text so no line exceeds a chosen maximum width, breaking only between words so no word is ever split mid-character.
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 Word Wrapper Works
For each original line, the tool splits the text into words and greedily builds up new lines, adding a word to the current line whenever it still fits within the max width, and starting a fresh line otherwise.
The transformation happens synchronously in JavaScript the moment you type, with no network round trip involved.
When To Use Word Wrapper
Use it to prepare plain text for a fixed-width terminal, format a monospace email or commit message body, or reflow a paragraph after editing.
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 Text Justifier, String Left Aligner and Line Break Adder.
Features
Advantages
- Never breaks a word mid-character, keeping words intact.
- Processes each existing line independently so paragraph breaks are preserved.
- Accounts for the joining space when deciding whether a word fits, so wrapped lines genuinely stay within the width rather than overrunning it by one.
Limitations
- A single word longer than the max width isn't broken, so it can still exceed the target line length.
- Wraps greedily rather than balancing the lines, so a paragraph's final line is often much shorter than the ones above it.
Examples
Best Practices & Notes
Best Practices
- Set the max width a few characters below your target column count to leave room for any prefix you add afterward, like a quote marker or indent.
- Wrap as the last step before publishing, since editing already-wrapped text leaves the line lengths ragged and inconsistent.
- Run the Line Unwrapper first when re-wrapping text that was previously hard-wrapped at a different width.
Developer Notes
The greedy wrap checks `current.length + 1 + word.length <= maxWidth` before appending a word (the `+ 1` accounts for the joining space), and each original line is processed independently via `input.split("\n")` so blank lines and paragraph breaks survive the transformation.
Word Wrapper Use Cases
- Formatting plain text for a fixed-width terminal display
- Reflowing a paragraph to a specific column width for a text file
- Preparing a commit message body wrapped to the conventional 72-character width
Common Mistakes
- Expecting an overly long single word to be broken automatically; it's kept whole on its own line instead.
- Wrapping text containing code or tables, where the inserted line breaks change the meaning rather than merely the layout.
Tips
- Wrap to 72 characters for git commit message bodies, a widely used convention for readable diffs and terminal output.
- A word longer than the width lands alone on its own over-long line, which makes URLs and long identifiers easy to spot in the result.