About this tool
Clean stray whitespace: trim line edges, convert tabs, collapse repeated spaces, squeeze blank lines and choose LF or CRLF endings. Change counts are shown for each rule.
Typical uses
- Tidy messy text copied from a web page or PDF
- Normalize line endings in code or config files
- Remove extra blank lines and spaces from exported data
How to use
Paste text or import UTF-8 and choose edge trimming, tab, repeated-space and blank-line rules.
Select LF/CRLF and final-newline handling, process and inspect change counts, then copy or download the complete text.
Up to 1 million characters, 20,000 lines and 4 MB per file. Defaults to trimming line edges, keeping one consecutive blank line and preserving the final-newline presence. NBSP and zero-width space/BOM cleanup are opt-in; ZWJ/ZWNJ used in writing and emoji are retained.
Every option on the Example text
“Example” fills in four lines: ␣␣First␣paragraph.␣␣␍␊␍␊␣␣⇥␍␊⇥Second␣␣␣paragraph.⇥␍␊. On this page ␣ is a space, ⇥ a tab, ␍␊ a Windows line break (CRLF) and ␊ an LF. The defaults trim both line edges, “Keep at most one consecutive blank line”, write LF and keep a final line break only if the input had one. Each row below changes one option; the output is what the tool’s cleaning function returns:
| Settings | Output | Output lines / Changed line contents / Removed blank lines | Characters |
|---|---|---|---|
| Defaults | First␣paragraph.␊␊Second␣␣␣paragraph.␊ | 3 / 3 / 1 | 52 → 38 |
| Also tick “Collapse consecutive regular spaces” | First␣paragraph.␊␊Second␣paragraph.␊ | 3 / 3 / 1 | 52 → 36 |
| “Line endings”: CRLF | First␣paragraph.␍␊␍␊Second␣␣␣paragraph.␍␊ | 3 / 3 / 1 | 52 → 41 |
| “Blank lines”: “Remove all” | First␣paragraph.␊Second␣␣␣paragraph.␊ | 2 / 3 / 2 | 52 → 37 |
| “Final newline”: “Do not append a final line terminator” | First␣paragraph.␊␊Second␣␣␣paragraph. | 3 / 3 / 1 | 52 → 37 |
| Untick both trim options | ␣␣First␣paragraph.␣␣␊␊⇥Second␣␣␣paragraph.⇥␊ | 3 / 0 / 1 | 52 → 44 |
- With the defaults, “Changed line contents” is 3: lines 1, 3 and 4 lose edge whitespace. Line 3 (“␣␣⇥”) becomes empty, follows another empty line and is dropped, so “Removed blank lines” is 1.
- The three spaces inside “Second␣␣␣paragraph.” are not at an edge; only “Collapse consecutive regular spaces” turns them into one.
- Characters are counted as JavaScript string length, and CRLF is two characters, which is why CRLF output grows from 38 to 41.
- With trimming switched off, no line content changes, yet line 3 (“␣␣⇥”) is still removed as a blank line: blank-line detection always ignores whitespace, whatever the trim settings.
Which characters count as whitespace
Edge trimming uses JavaScript’s trimStart() and trimEnd(). They remove what the language defines as white space and line terminators: tab, VT, FF, the ordinary space, U+00A0, U+FEFF and every Unicode space separator (category Zs), such as the ideographic space U+3000 and the narrow no-break space U+202F. The zero-width space U+200B is a format character and is not included. Each yes/no below comes from running the tool on text containing that character:
| Character | Code point | Trimmed at a line edge | A line of only this counts as blank | Option that handles it mid-line |
|---|---|---|---|---|
| Space | U+0020 | yes | yes | “Collapse consecutive regular spaces” |
| Tab | U+0009 | yes | yes | Tabs |
| No-break space (common in web copy) | U+00A0 | yes | yes | “Convert non-breaking spaces” |
| Narrow no-break space | U+202F | yes | yes | no option touches it |
| Ideographic (full-width) space | U+3000 | yes | yes | no option touches it |
| En space | U+2002 | yes | yes | no option touches it |
| Thin space | U+2009 | yes | yes | no option touches it |
| Zero-width space | U+200B | no | no | “Remove zero-width spaces / BOM” |
| BOM / zero-width no-break space | U+FEFF | yes | yes | “Remove zero-width spaces / BOM” |
| Zero-width joiner | U+200D | no | no | no option touches it |
| Word joiner | U+2060 | no | no | no option touches it |
| Next line (NEL) | U+0085 | no | no | no option touches it |
| Line separator | U+2028 | yes | yes | no option touches it |
- “Convert non-breaking spaces” handles U+00A0 only. Other wide or narrow spaces in the middle of a line are left as they are, and “Collapse consecutive regular spaces” merges runs of the ordinary space U+0020 only, not tabs or U+3000.
- “Remove zero-width spaces / BOM” deletes U+200B and U+FEFF and nothing else. The joiners U+200D and U+200C and the word joiner stay, so an emoji sequence such as 👨👩👧 survives intact. A U+FEFF at a line edge is already removed by the default trimming.
- A line holding only a zero-width space is not blank, so blank-line rules keep it. Tick the zero-width option as well and it becomes a real blank line.
- U+0085 (NEL) is not JavaScript white space and no option removes it. U+2028 is trimmed at an edge, but the tool does not start a new line there.
Order of steps, tabs, blank lines and line endings
Each line goes through the same steps in a fixed order: no-break spaces, zero-width characters, tabs, edge trimming, then collapsing spaces. After that the blank-line rule runs over all lines, leading and trailing blank lines are removed if requested, and the lines are joined with the chosen line ending. The order matters:
- Each tab becomes a fixed number of spaces; there are no tab stops. With 4 spaces, “ab⇥c⇥d” becomes “ab␣␣␣␣c␣␣␣␣d”, not text aligned to columns 4 and 8.
- Tabs are expanded before spaces are collapsed: “a⇥⇥b” with 2 spaces per tab and collapsing on gives “a␣b”.
- To tidy code without losing indentation, untick “Trim leading whitespace”: ⇥if␣(x)␣{␊⇥⇥return␣1;␣␣␊⇥}␊ with 2 spaces per tab becomes ␣␣if␣(x)␣{␊␣␣␣␣return␣1;␊␣␣}␊, and the trailing spaces still go.
- CRLF, a lone CR (classic Mac) and LF all end a line on input; the output uses one style only. “a␍b␍␊c␊” gives a␊b␊c␊ with the defaults.
- “Remove leading/trailing blank lines” runs after the blank-line rule: ␊␊␣␣Title␊␊ gives ␊Title␊␊ by default and Title␊ with this option.
The three “Final newline” choices for input with and without a final line break:
| Input | “Match input” | “Do not append a final line terminator” | “Append final newline” |
|---|---|---|---|
| a␊b | a␊b | a␊b | a␊b␊ |
| a␊b␊ | a␊b␊ | a␊b | a␊b␊ |
If no line is left after cleaning, the result is empty (∅) even with “Append final newline”.
Limits and messages
| Message | When it appears |
|---|---|
| Use at most 1 million characters across the inputs. | The input exceeds 1,000,000 characters (JavaScript string length; an emoji usually counts as 2). |
| Each input is limited to 20,000 lines. | The input has more than 20,000 lines. A final line break does not count as a line. |
| Import a UTF-8 text file. Binary content is not supported. | The imported file is not valid UTF-8 (for example Windows-1252 with accented letters) or contains NUL bytes (UTF-16 without a BOM). Save it as UTF-8 first. |
| Could not read the file, or it exceeds 4 MB. | The file exceeds 4,000,000 bytes or the browser could not read it. |
| Processing stopped after 8 seconds. Use smaller inputs. | Background processing ran longer than 8 seconds and was stopped. |
- The result preview shows the first 20,000 characters; copying and “Download TXT” always give the complete result, saved as UTF-8 cleaned-text.txt.
- Cleaning runs in a background thread in your browser and the text is not uploaded. Options can be saved as a local preset; the text itself is never stored.
Sources
Frequently asked questions
Will it break emoji?
No. Joiners used in scripts and emoji are kept; cleaning non-breaking and zero-width spaces is opt-in.
What happens by default?
Line edges are trimmed, consecutive blank lines are reduced to one and the presence of a final newline is preserved.
How much text can it handle?
Up to 1 million characters, 20,000 lines and 4 MB per file.
Suggest an improvement to this tool
Missing an option, something awkward to use, or a wrong result? Let us know.