Text Tools
How to Remove Line Breaks and Clean Up Messy Whitespace in Text
Strip unwanted line breaks, join wrapped paragraphs, and collapse extra whitespace fast. Learn the difference between CR, LF, and CRLF and when to keep them.
Try the toolRemove Line Breaks →The problem: text that arrives pre-broken
You copy a paragraph out of a PDF and every line ends with a hard break, so pasting it into a form produces a jagged column instead of flowing text. You paste a code comment that was wrapped at 80 characters and now you have to rejoin it. Or you export data and each record is split across lines that should be one. In every case the fix is the same idea: remove or collapse line breaks so the text becomes a single clean block again.
A Remove Line Breaks tool does this in your browser, with control over whether breaks vanish entirely, get replaced by spaces, or only the extra blank lines get collapsed.
Background: not all line breaks are the same
A "line break" is one or two invisible control characters, and which ones depend on the operating system that produced the text:
- LF (
\n, line feed) — Unix, Linux, macOS. - CRLF (
\r\n, carriage return + line feed) — Windows. - CR (
\r) — classic Mac OS, now rare.
This matters because a naive "remove \n" leaves stray \r characters behind on Windows text, which show up as invisible gremlins or a phantom character at the end of each line. A proper tool normalizes all three forms before stripping.
Remove vs. collapse
There are two distinct operations people lump together:
- Remove: delete the break so lines join. You usually want to join them with a space, not glue words together — otherwise
the endacross two lines becomestheend. - Collapse: keep single breaks but squash runs of blank lines (and runs of spaces) down to one, tidying spacing without flattening structure.
A practical walkthrough
Say a copied paragraph looks like this, with a hard break mid-sentence:
Our deployment pipeline runs every
night and publishes a signed
artifact to the registry.Choosing "replace breaks with a space" gives you a single flowing line:
Our deployment pipeline runs every night and publishes a signed artifact to the registry.Now consider text with too much vertical space:
Section one.
Section two.Collapsing multiple blank lines to a single one yields:
Section one.
Section two.Conceptually, the join-with-space transform is what this regex does — replacing any run of whitespace that includes a newline with one space:
text.replace(/\s*\r?\n\s*/g, " ").trim();Common pitfalls and tips
- Joining without a separator. Removing breaks with nothing in between fuses the last and first words of adjacent lines. Default to a single space unless you specifically want them concatenated (for example, rejoining a base64 string that was wrapped).
- Losing paragraph structure. If you flatten everything, you lose the double-newline boundaries between paragraphs. Use collapse mode when you want to preserve paragraph breaks but kill the noise.
- Invisible trailing spaces. Removing breaks can leave double spaces where a line already ended in a space. Collapsing multiple spaces to one cleans that up.
- Wrong direction of edit. If you instead need to add structure or swap specific substrings, reach for Find and Replace. To drop repeated rows entirely, use Remove Duplicate Lines.
Conclusion
Messy line breaks come from the friction of moving text between PDFs, editors, and operating systems. Knowing whether you want to fully remove breaks (joining with a space) or just collapse the extra ones — and letting the tool normalize CR, LF, and CRLF — gets you clean, portable text in one paste. It all happens locally, so even sensitive copy stays on your machine.