Free Text Word Wrapper
World's Advanced browser utility for wrapping words to a fixed line length. Paste text on the left, choose your maximum line length,
enable optional word breaking or leading-space behavior, and instantly get wrapped output on the right. Fast, private (runs in your browser),
and ideal for formatting text, email content, articles, code comments, or printed text blocks.
Paste or type multi-line text here. Paragraphs separated by blank lines are preserved.
Wrapped result appears here. Use copy or download buttons below.
Wrap Words in Text (Nile River) — Width = 60
Classic wrapping of long paragraph to a 60-character width. Does not break words by default.
Before (input):
The Nile River is the longest river in Africa and one of the longest rivers in the world. It begins its movement north of Central Africa and flows into the Mediterranean Sea. However, if you measure the amount of water in the river in cubic meters, then it will be one of the smallest rivers in the world.
⇨ After (wrapped to 60 chars) ⇨
The Nile River is the longest river in Africa and one of the
longest rivers in the world. It begins its movement north of
Central Africa and flows into the Mediterranean Sea. However,
if you measure the amount of water in the river in cubic
meters, then it will be one of the smallest rivers in the world.
Required options: Line Length = 60 • Break Words = Off • Allow Leading Spaces = Off
Step 1: Paste the paragraph in the input box.
Step 2: Set Line Length to 60.
Step 3: Click Wrap Words → copy or download result.
Step 2: Set Line Length to 60.
Step 3: Click Wrap Words → copy or download result.
Limit Text to 30 Symbols Per Line (Hawaii) — Width = 30
Compact paragraph formatting to 30 characters per line for narrow columns.
Before (input):
Hawaii is getting 7.5cm closer to Alaska every year. As you know, the upper rigid shell of the globe is divided into large plates, which are called tectonic plates.
⇨ After (wrapped to 30 chars) ⇨
Hawaii is getting 7.5cm closer
to Alaska every year. As you
know, the upper rigid shell of
the globe is divided into
large plates, which are called
tectonic plates.
Required options: Line Length = 30 • Break Words = Off
Step 1: Paste the text.
Step 2: Set Line Length to 30.
Step 3: Click Wrap Words → get compact block.
Step 2: Set Line Length to 30.
Step 3: Click Wrap Words → get compact block.
Wrap Words in Text (Mount Everest) — Width = 50
Demonstration of wrapping descriptive text about Mount Everest to a 50-character line width. Words remain intact without splitting.
Before (input):
Mount Everest is the highest mountain in the world, standing at 8,849 meters above sea level. It is located in the Himalayas on the border of Nepal and China, and it attracts thousands of climbers and adventurers every year who attempt to reach its summit.
⇨ After (wrapped to 50 chars) ⇨
Mount Everest is the highest mountain in the
world, standing at 8,849 meters above sea level.
It is located in the Himalayas on the border of
Nepal and China, and it attracts thousands of
climbers and adventurers every year who attempt
to reach its summit.
Required options: Line Length = 50 • Break Words = Off • Allow Leading Spaces = Off
Step 1: Paste the mountain description in the input box.
Step 2: Set Line Length to 50.
Step 3: Click Wrap Words → copy or download result.
Step 2: Set Line Length to 50.
Step 3: Click Wrap Words → copy or download result.
Dense Line Wrapping — Break Words On, Leading Spaces Off
Force-filling lines (break long words) to create a dense block — useful for fixed-width display.
Before (input):
"Try to imagine a life without timekeeping. You probably can't. You know the month, the year, the day of the week. There is a clock on your wall or the dashboard of your car."
⇨ After (wrap width = 50, break words ON) ⇨
"Try to imagine a life without timekeep
ing. You probably can't. You know the mo
nth, the year, the day of the week. Ther
e is a clock on your wall or the dashboar
d of your car."
Required options: Line Length = 50 • Break Words = On • Allow Leading Spaces = Off
Step 1: Paste the passage.
Step 2: Set Line Length to 50, enable Break Words and disable Allow Leading Spaces.
Step 3: Click Wrap Words → copy/download.
Step 2: Set Line Length to 50, enable Break Words and disable Allow Leading Spaces.
Step 3: Click Wrap Words → copy/download.
What Is a Text Word Wrapper?
A Text Word Wrapper automatically inserts line breaks so each line does not exceed a specified line length.
It supports both word-safe wrapping (move whole words to the next line) and hard breaks (split words if necessary).
This tool is invaluable for email formatting, code comments, plain-text newsletters, SEO-friendly content snippets, and fixed-width layouts.
How to Use
- Paste or type your text into the left input area (multi-paragraph supported).
- Enter desired Line Length (number of symbols per line).
- Enable Break Words if you want to split long words to tightly fill lines.
- Enable Allow Leading Spaces only if you want lines that begin with a space when the previous line ended exactly at the limit (rare).
- Click Wrap Words or toggle live mode to process automatically as you type.
Pro Tips
- Use 60–80 characters per line for readable paragraphs; use 30–40 for narrow columns and mobile-friendly snippets.
- Enable Break Words for fixed-width devices where exact line fill is critical (e.g., printers, certain displays).
- Turn off Allow Leading Spaces
- Save results with Download as TXT
FAQs
Q: Will this remove my paragraph separation?
A: No — blank lines are preserved so paragraphs remain separated.
Q: Can I wrap very long words?
A: Yes — enable Break Words
Q: Is processing local?
A: Yes — the tool runs client-side in your browser; nothing leaves your device.
copyright>// /* ======= Word wrapper logic ======= */
const inputEl = document.getElementById('inputText');
const outputEl = document.getElementById('outputText');
const lineLenEl = document.getElementById('lineLen');
const breakWordsEl = document.getElementById('breakWords');
const leadingSpacesEl = document.getElementById('leadingSpaces');
const liveModeEl = document.getElementById('liveMode');
const fileInput = document.getElementById('fileInput');
fileInput.addEventListener('change', e => {
const f = e.target.files && e.target.files[0];
if (!f) return;
const reader = new FileReader();
reader.onload = evt => {
inputEl.value = evt.target.result;
if (liveModeEl.checked) wrapWords();
};
reader.readAsText(f, 'utf-8');
});
// clear input shortcut
function clearInput(){
inputEl.value = '';
outputEl.value = '';
}
/**
* Wrap a single paragraph (array of tokens) to width without breaking words,
* or with breaking words when allowed.
*/
function wrapParagraph(text, width, breakWords, allowLeadingSpaces) {
if (width <= 0) return text; // nothing to do
const outLines = [];
// treat text as sequence of characters and spaces preserving original spaces between words
// But for standard wrapping we'll collapse runs of whitespace to single space for word boundaries
// First handle word-safe mode
if (!breakWords) {
const words = text.split(/s+/).filter(Boolean);
let cur = '';
for (let i = 0; i < words.length; i++) {
const w = words[i];
if (cur.length === 0) {
// start new line
if (w.length <= width) { cur = w; } else { // long single word longer than width -> place on its own line (no break)
outLines.push(w);
cur = '';
}
} else {
// check if adding +1 space + w fits
if (cur.length + 1 + w.length <= width) {
cur = cur + ' ' + w;
} else {
outLines.push(cur);
cur = w.length <= width ? w : ''; if (w.length > width) {
outLines.push(w);
cur = '';
}
}
}
}
if (cur.length > 0) outLines.push(cur);
return outLines.join('n');
}
// breakWords = true: fill as many characters as possible per line,
// splitting words across boundary if needed.
// We'll iterate through chars, building lines of exact <= width.
let i = 0;
const s = text.replace(/rn/g, 'n'); // normalize
const n = s.length;
let buffer = '';
while (i < n) {
// build a line up to width characters
let line = '';
while (line.length < width && i < n) {
line += s[i++];
}
// If we stopped because line is full
if (line.length === width) {
// edge-case: if next char is space and allowLeadingSpaces true, keep it at next line.
// else if next char is space and allowLeadingSpaces false, skip it.
// We'll push this line as-is.
outLines.push(line);
// If the next char is a space, handle according to allowLeadingSpaces
if (i < n && s[i] === ' ') {
if (allowLeadingSpaces) {
// We want the next line to start with a space; keep it (do not consume)
// Do nothing here — the next loop will include it.
} else {
// skip leading spaces
while (i < n && s[i] === ' ') i++;
}
}
continue;
} else {
// reached end of input, add remainder
outLines.push(line);
break;
}
}
// The above method could introduce mid-line newlines from original text; to make behavior friendlier,
// we should split original text by whitespace blocks and treat newline as 'space' boundary.
// But the simple char-filling approach above produces correct "dense" wrap similar to example.
// combine preserving existing paragraph boundaries
return outLines.join('n');
}
/**
* Main wrapper: split into paragraphs by blank lines, wrap each paragraph separately,
* preserve blank paragraph separation
*/
function wrapWords() {
const raw = inputEl.value.replace(/rn/g, 'n'); // normalize CRLF
let width = parseInt(lineLenEl.value, 10);
if (isNaN(width) || width <= 0) { // default to 60 if empty/invalid width = 60; } const breakWords = breakWordsEl.checked; const allowLeading = leadingSpacesEl.checked; // paragraphs split by one or more blank lines const paragraphs = raw.split(/n{2,}/g); const processed = paragraphs.map(par => {
// For each paragraph, treat its internal newlines as spaces (we preserve words),
// but maintain line breaks only as result of wrapping.
// collapse existing newlines/spaces into single spaces for wrap (except we keep existing explicit line breaks?).
const normalized = par.replace(/n/g, ' ').replace(/s+/g, ' ').trim();
if (normalized === '') return '';
if (!breakWords) {
// word-safe wrapping: use wrapParagraph with whole words
return wrapParagraph(normalized, width, false, allowLeading);
} else {
// break-words mode: use a chunking algorithm that fills lines with characters.
// We'll construct by taking as many characters as possible from the normalized string,
// but preserve spaces except possibly skipping leading spaces per allowLeading.
const chars = normalized; // single-line string
const out = [];
let idx = 0;
while (idx < chars.length) {
// take up to width characters
let chunk = chars.slice(idx, idx + width);
// if chunk length < width => remainder
if (chunk.length < width) {
out.push(chunk);
break;
}
// chunk is exactly width
out.push(chunk);
idx += width;
}
// Now handle leading spaces on lines after full-fill:
if (!allowLeading) {
for (let j = 1; j < out.length; j++) { if (out[j].startsWith(' ')) { // remove leading spaces out[j] = out[j].replace(/^s+/, ''); } } } return out.join('n'); } }); // re-join paragraphs with double newline outputEl.value = processed.join('nn'); // scroll to output smoothly outputEl.scrollIntoView({ behavior: 'smooth' }); } /* Small improvement: offer a smarter char-break algorithm that tries to avoid breaking in the middle of word just before width if next char is space. But above implementation matches requested behavior: break words to fill lines if enabled. */ /* live processing */ inputEl.addEventListener('input', () => { if (liveModeEl.checked) wrapWords(); });
lineLenEl.addEventListener('input', () => { if (liveModeEl.checked) wrapWords(); });
breakWordsEl.addEventListener('change', () => { if (liveModeEl.checked) wrapWords(); });
leadingSpacesEl.addEventListener('change', () => { if (liveModeEl.checked) wrapWords(); });
liveModeEl.addEventListener('change', () => { if (liveModeEl.checked) wrapWords(); });
/* Examples helper */
function applyExample(name) {
if (name === 'nile') {
inputEl.value = `The Nile River is the longest river in Africa and one of the longest rivers in the world. It begins its movement north of Central Africa and flows into the Mediterranean Sea. However, if you measure the amount of water in the river in cubic meters, then it will be one of the smallest rivers in the world.`;
lineLenEl.value = 60;
breakWordsEl.checked = false;
leadingSpacesEl.checked = false;
} else if (name === 'hawaii') {
inputEl.value = `Hawaii is getting 7.5cm closer to Alaska every year. As you know, the upper rigid shell of the globe is divided into large plates, which are called tectonic plates. They constantly move in a horizontal direction, following the movement of the mantle current. The Hawaiian Islands are located in the middle of the Pacific Plate, slowly moving northwest towards the North American Plate, to Alaska.`;
lineLenEl.value = 30;
breakWordsEl.checked = false;
leadingSpacesEl.checked = false;
} else if (name === 'dense') {
inputEl.value = `"Try to imagine a life without timekeeping. You probably can't. You know the month, the year, the day of the week. There is a clock on your wall or the dashboard of your car. You have a schedule, a calendar, a time for dinner or a movie."`;
lineLenEl.value = 50;
breakWordsEl.checked = true;
leadingSpacesEl.checked = false;
}
wrapWords();
}
/* copy & download */
function copyResult() {
outputEl.select();
try {
document.execCommand('copy');
alert('Wrapped text copied to clipboard!');
} catch (e) {
alert('Copy failed — please select the text and copy manually.');
}
}
function downloadResult() {
const txt = outputEl.value;
const blob = new Blob([txt], { type: 'text/plain' });
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = 'wrapped-text.txt';
a.click();
}
// ]]>