Remove Extra Spaces
Remove extra spaces, tabs, and blank lines from text — clean and reformat in one click.
Did this tool work for you?
How to use this calculator
- 1
Paste the text that has extra spaces, tabs or blank lines into the box.
- 2
Pick one mode: collapse extra spaces, remove all spaces, trim line edges, drop blank lines, replace tabs, or remove all whitespace.
- 3
Read the cleaned text and compare the Original length and Result length rows to see how much changed.
- 4
For a second kind of cleanup, paste the result back in and choose another mode.
Frequently asked questions
What is the difference between "extra spaces" and "trim per line"?
Extra spaces collapses every run of spaces and tabs inside a line to a single space and also strips the space at the start and end of each line. Trim per line only removes whitespace at the two ends of each line and leaves the gaps between words alone, so "a b" stays as it is.
Will it keep my code indentation?
Not in the extra-spaces mode, which removes leading spaces and tabs from every line and flattens indentation. If you only want to delete empty lines from code, use Blank lines: it keeps the indentation of the lines that remain. Use Trim per line only if you also want indentation gone.
Does it remove non-breaking spaces and zero-width spaces?
Mostly no. Collapse mode matches only ordinary spaces and tabs, so a non-breaking space (U+00A0) pasted from a web page survives. Trim per line and All whitespace do strip it, because JavaScript counts it as whitespace. Zero-width spaces (U+200B) are not treated as whitespace by any mode and need a different tool, such as the text cleaner with its non-ASCII option.
What exactly does "all spaces" remove?
Only the ordinary space character. Tabs and line breaks stay in place, so "Hello world" becomes "Helloworld" but a tab between two words is left alone. Use All whitespace to remove tabs and newlines as well, which joins everything into one unbroken string.
Does the Blank lines mode treat lines containing only spaces as blank?
Yes. A line is dropped if nothing but whitespace is on it. Both Windows (CRLF) and Unix (LF) line endings are recognised, and the output uses plain line feeds. Leading and trailing blank lines are removed as well.
How is "Characters removed" calculated?
It is the original length minus the result length, counted in UTF-16 code units. A Windows line ending counts as 2, so converting CRLF text in Blank lines mode can show a higher number than the count of lines you deleted.
Does it join lines together?
Only the All whitespace mode joins lines, because it deletes newlines. Every other mode keeps your line structure. To join lines while keeping single spaces between words, the Line breaks option in the text cleaner does that.
Cleaning whitespace: six modes compared
Pick the mode by what you want to keep
Each mode removes one kind of whitespace and leaves the rest alone, so the choice decides what survives. Extra spaces keeps line breaks and blank lines but flattens the spacing inside lines and strips indentation. Blank lines deletes empty rows and keeps indentation. All spaces deletes only the ordinary space character. The table lists what each mode touches.
| Mode | Collapses or deletes | Leaves untouched |
|---|---|---|
| Extra spaces | Runs of spaces/tabs, line-edge spaces | Line breaks, blank lines |
| All spaces | Every ordinary space | Tabs, line breaks |
| Leading and trailing | Whitespace at the ends of each line | Spacing inside lines |
| Blank lines | Empty or whitespace-only lines | Indentation, spacing |
| Tabs | Each run of tabs becomes one space | Spaces, line breaks |
| All whitespace | Spaces, tabs and newlines | Nothing between characters |
Which characters count as whitespace
The modes use two definitions. Extra spaces, All spaces and Tabs look only for the plain space (U+0020) and the tab. Leading and trailing, Blank lines and All whitespace use the wider set built into JavaScript, which also covers the non-breaking space, the em space, the ideographic space U+3000, the byte order mark U+FEFF and the carriage return. The zero-width space U+200B belongs to neither set, so no mode removes it. The matrix was produced by feeding each character through the tool.
| Character | Extra spaces | All spaces | Leading and trailing | All whitespace |
|---|---|---|---|---|
| Space | Collapsed to one | Removed | Edges trimmed | Removed |
| Tab | Collapsed to one space | Kept | Edges trimmed | Removed |
| Non-breaking space U+00A0 | Kept | Kept | Edges trimmed | Removed |
| Em space U+2003 / U+3000 | Kept | Kept | Edges trimmed | Removed |
| Zero-width space U+200B | Kept | Kept | Kept | Kept |
| Line feed | Kept | Kept | Kept (splits lines) | Removed |
Windows and Unix line endings
Windows text ends a line with a carriage return plus a line feed, Unix text with a line feed alone. Extra spaces leaves both styles as they were and still cleans the spaces in front of each break. Leading and trailing and Blank lines rebuild the text with plain line feeds, so a CRLF file comes back with LF endings. They split only on line feeds, which means lines separated by a lone carriage return are handled as one line. If the destination needs a specific ending, convert it in your editor afterwards.
Worked examples from the tool
Sample A is 52 characters: a line of Hello and world with four spaces between them and two spaces at each end, a blank line, an indented line with two tabs, then two more blank lines and the word last. Sample B is 17 characters with Windows endings: a, two spaces, b, two trailing spaces, a break, two spaces, c, a tab, a break, an empty line, d. Sample C is 13 characters of mixed Unicode spaces. Every output below was copied from a run.
| Sample | Mode | Result | Length |
|---|---|---|---|
| A (52) | Extra spaces | Hello world / blank / indented line end / 2 blanks / last | 37 |
| A (52) | Blank lines | Three empty lines gone, spacing kept | 49 |
| A (52) | All spaces | Helloworld, indentedline, tabs and breaks kept | 36 |
| A (52) | All whitespace | Helloworldindentedlineendlast | 29 |
| B (17) | Extra spaces | a b, c, empty line, d; CRLF kept | 11 |
| B (17) | Leading and trailing | a b, c, empty line, d; LF endings | 9 |
| C (13) | Extra spaces | Only the double plain space shrinks; both NBSP stay | 12 |
| C (13) | All whitespace | All six spaces gone, the zero-width space stays | 7 |
Chaining passes and checking the result
One run applies one mode, so feed the output back in for a second pass. Blank lines first removes empty rows while the indentation is still visible, and Extra spaces afterwards tidies what is left. The reverse order flattens indentation before the blank rows go, which is harmless for prose but destroys the structure of code and nested lists. Characters removed is the original length minus the result length in UTF-16 units, so each CRLF pair counts as 2. If an equality test still fails after cleaning, suspect a zero-width space; the text cleaner’s Non-ASCII filter deletes it.
Learn more from an authoritative source:
WikipediaText Repeater
Repeat any text or phrase a set number of times with a custom separator.
Lorem Ipsum Generator
Generate placeholder Lorem Ipsum text by words, sentences, or paragraphs.
Text Cleaner
Remove special characters, HTML tags, punctuation, numbers, or any custom characters from text.
Readability Score Calculator
Calculate the Flesch Reading Ease score, Flesch-Kincaid grade level, and key text statistics for any piece of writing.
Headline Analyzer
Score your blog post, email, or article headline for emotional impact, power words, word balance, and SEO potential.
Blog Title Generator
Generate 10 click-worthy blog post titles for any topic using proven headline formulas — listicles, how-tos, questions, and more.
Results are estimates for informational purposes only and do not constitute professional financial, medical, legal, or technical advice. Read full disclaimer →