How to remove line breaks from text (and why pasted text breaks in the first place)
Why copied text arrives full of hard line breaks, the difference between a newline and a carriage return, and how to flatten or rejoin lines cleanly without mangling paragraphs.
You copy a paragraph out of a PDF or an email, paste it into a document, and it arrives shattered — a line break after every line, right in the middle of sentences. Removing those breaks by hand is miserable. The good news is it's a one-click fix once you understand what a "line break" actually is and which kind you're dealing with.
If you just need it done, paste your text into the Remove Line Breaks tool and pick how the breaks should be handled. The rest of this explains what's happening so you choose the right option.
What a line break really is
A line break isn't a visible character — it's one or two invisible control characters sitting between your words. There are two of them, and the distinction matters:
- Line feed (
\n) — the newline character, ASCII 10. This is what Unix, Linux, and macOS use to end a line. - Carriage return (
\r) — ASCII 13, a holdover from typewriters and teletypes.
The catch is that Windows ends lines with both, in sequence: \r\n (carriage return then line feed), while Unix-family systems use just \n, and very old Mac files used just \r. So a "line break" might be one character or two, depending on where the text came from. This is why text that looks fine on one system shows up with doubled blank lines or stray boxes (^M) on another — the line endings don't match what the program expects.
A robust line-break remover handles all three forms — \r\n, \n, and \r — so you don't have to know or care which one is hiding in your text.
Why pasted text is full of hard breaks
The breaks you're fighting usually come from one of these sources, and the cause explains the cure:
- PDFs. A PDF stores text positioned line by line on the page, not as flowing paragraphs. When you copy from it, you often get a hard break at the end of every visual line — exactly where the words wrapped on the page, not where the sentence ends. That's the classic "every line is broken" paste.
- Email and plain-text files. Older email and plain-text formats used "hard wrapping" — inserting a real line break around column 72 so the text fit fixed-width terminals. Paste it into a modern editor that wraps automatically and you get breaks fighting the wrap.
- Code and terminal output. Logs, config files, and console dumps are line-oriented by nature, so copying them brings every newline along.
In all of these, the line breaks are an artifact of how the text was displayed or stored, not part of its meaning. Removing them restores the flowing text underneath.
Flatten vs. rejoin: pick the right operation
"Remove line breaks" can mean two genuinely different things, and choosing wrong is what mangles your text:
- Replace each break with a space. This is what you usually want for prose.
the quick\nbrown foxbecomesthe quick brown fox— a single readable paragraph. If you instead delete the breaks with nothing in their place, you getthe quickbrown fox, with words fused together. So for sentences, replace breaks with a space, not with nothing. - Delete breaks entirely (join with nothing). This is right when the breaks fell inside tokens that should never have been split — a long URL, a base64 string, or a serial number that wrapped across lines. Here you want the pieces stuck back together with no space.
A third common need is collapsing rather than removing: turning runs of multiple blank lines into a single break to tidy up spacing while keeping paragraph separation. The Remove Line Breaks tool offers each of these — replace with a space, replace with a custom separator, or collapse extra whitespace — because the "right" answer depends entirely on whether your breaks are between sentences or inside a token.
Preserving paragraphs
The hardest case: you want to remove the within-paragraph breaks (the ones chopping sentences) but keep the between-paragraph breaks (the blank line separating one paragraph from the next). The trick is that a paragraph boundary is usually a double break (a blank line — \n\n), while a wrap is a single break.
So the careful approach is: protect the double breaks, replace the remaining single breaks with a space, then restore the doubles. Done by hand with find-and-replace that's fiddly; the point is to know it's possible, so you don't flatten a whole document into one giant paragraph when you only meant to fix the wrapping.
A note on doing it with regex
If you're scripting this, the building blocks are simple. To replace every line break (in any of the three forms) with a space, match \r\n?|\n and substitute a space. To collapse multiple blank lines to one, match two-or-more consecutive breaks and replace with a single one. To strip trailing spaces left behind, match spaces before a line end. You can prototype these patterns in the Regex Tester before dropping them into your editor or script — it shows matches live so you can confirm the pattern does what you expect before running it on real text.
The short version
A line break is an invisible \n, \r, or \r\n left over from how the text was stored or displayed — most painfully when copied out of a PDF that broke every visual line. To fix prose, replace each break with a space (not with nothing, or you'll fuse words); to repair a wrapped URL or token, join with nothing; to tidy spacing, collapse repeated blank lines. The Remove Line Breaks tool does all three in the browser, so even sensitive text never leaves your device.