Text & wordsFree
Free text cleaner. Trim lines, collapse extra spaces, remove empty lines, or strip line breaks. Runs locally.
Last updated 14 October 2026
Whatever you tick, this tool does the same four things in the same sequence: trim each line, then collapse spaces, then drop empty lines, then optionally join everything into one line. You cannot reorder them, and almost every confusing result comes from that fixed order rather than from a bug.
The clearest case is the one people hit first. Remove empty lines does not remove a line made of spaces, unless you also tick Trim each line. Measured here, with text that is a, then a line of three spaces, then b:
So if a document still has gaps after cleaning, tick Trim as well. Pasted text from a word processor or a web page is full of lines that look empty and are not.
Collapse spaces replaces runs of ordinary spaces and tabs with one space. It does not know the difference between the gap in the middle of a sentence and the indentation at the start of a line, so it removes both. Measured: two lines of code indented with four spaces come back indented with one.
If you are tidying code, leave this option off. A tab also becomes a single space, so indentation that was tabs will not survive either.
The reverse problem is more common and harder to see. A non-breaking space is not collapsed at all. Measured: three non-breaking spaces between a and b come back as three non-breaking spaces, while three ordinary spaces in the same position come back as one. That matters because a non-breaking space is what word processors and web pages insert to stop a line wrapping, so it is exactly the kind of invisible mess you pasted here to remove.
There is an asymmetry worth knowing, and we measured both halves of it. Trim does remove a non-breaking space, because JavaScript’s trim uses the language’s own definition of whitespace, which includes it. Collapse does not, because it matches only the literal space and tab. So a stray non-breaking space at the start of a line is fixable here and the same character in the middle of a line is not.
Join is not a fifth step applied to the result of the first four. It replaces the output entirely: it takes the lines, puts a single space between them, squeezes any runs of spaces, and trims the ends. Measured, with Join as the only option ticked:
a b on one line and c on the next comes back as a b c, so the three spaces were collapsed even though Collapse spaces was unticked.a and b comes back as a b whether Remove empty lines is ticked or not, because the blank line contributes nothing but the spaces around it get squeezed anyway.So Join is a shortcut for “give me this as one tidy paragraph”, and if you need a different separator, or you want to keep your double spaces, do it somewhere else.
If you pasted a Windows file hoping to convert its line endings, that conversion has already happened and this tool had nothing to do with it. The HTML standard says a textarea’s API value is “the element’s raw value, with newlines normalized”, and that it is “normalized so that line breaks use U+000A LINE FEED (LF) characters”.
We checked what the box actually hands over: a carriage return, a carriage return plus line feed, and a plain line feed all arrive as the same single character. That happens in the browser before any code on this page runs, so no web page can show you or change your original line endings. For that you need a local editor or a command-line tool.
It is a line tidier, not a text sanitiser. Everything in this list was measured as surviving a pass with every option ticked:
Nothing is uploaded. The whole tool is a few lines of JavaScript running in your browser, and your text never leaves your device.
textarea element. html.spec.whatwg.orgtrim itself. developer.mozilla.org\s does: regular expression character classes. developer.mozilla.orgEvery behaviour described on this page was measured against this tool as it is published, in a browser, on 14 October 2026. Where the page says what the tool does not do, that is a statement about this tool, not about text cleaning in general.
Because those lines are not empty, they contain spaces or tabs. The filter only drops lines of length zero, and it runs after trimming, so tick Trim each line as well and they will go. We measured this: a line of three spaces survives with Remove empty lines alone and disappears when Trim is added.
Collapse spaces replaces every run of spaces or tabs with one space, including the run at the start of a line. Four-space indentation becomes one space, and tab indentation becomes one space. If you are tidying code, leave Collapse off and use Trim and Remove empty lines only.
Almost certainly non-breaking spaces, which word processors and web pages insert to stop lines wrapping. Collapse spaces matches only the ordinary space and the tab, so a non-breaking space in the middle of a line passes through untouched. Trim does remove them from the ends of lines, because JavaScript’s own definition of whitespace includes them.
Because Join is not a step added after the others, it replaces the output. It joins the lines with a single space, squeezes any runs of spaces and trims the ends, all as one operation. If you need the double spaces kept, do not use Join.
No, and that conversion has already happened before this page can see your text. The HTML standard requires a text box to normalise line breaks to LF in the value a script reads, so by the time the tool runs, your original line endings are gone. Use a local editor or a command-line utility.
No. We measured a zero-width space surviving a pass with every option ticked. Those are the characters most likely to be causing an unexplained problem in pasted text, and this tool does not touch them. The same goes for curly quotes and long dashes.
No. Two identical lines both survive. Sort Lines has a Unique option that does remove them, though it also sorts the result, so the original order is lost.
No. The whole tool runs in your browser and there is no request carrying your text off the page. Nothing is saved either, so refreshing loses it.