Utinzo

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. 1

    Paste the text that has extra spaces, tabs or blank lines into the box.

  2. 2

    Pick one mode: collapse extra spaces, remove all spaces, trim line edges, drop blank lines, replace tabs, or remove all whitespace.

  3. 3

    Read the cleaned text and compare the Original length and Result length rows to see how much changed.

  4. 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.

About remove extra spaces

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.

What each mode changes
ModeCollapses or deletesLeaves untouched
Extra spacesRuns of spaces/tabs, line-edge spacesLine breaks, blank lines
All spacesEvery ordinary spaceTabs, line breaks
Leading and trailingWhitespace at the ends of each lineSpacing inside lines
Blank linesEmpty or whitespace-only linesIndentation, spacing
TabsEach run of tabs becomes one spaceSpaces, line breaks
All whitespaceSpaces, tabs and newlinesNothing 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.

Effect of each mode on a given character
CharacterExtra spacesAll spacesLeading and trailingAll whitespace
SpaceCollapsed to oneRemovedEdges trimmedRemoved
TabCollapsed to one spaceKeptEdges trimmedRemoved
Non-breaking space U+00A0KeptKeptEdges trimmedRemoved
Em space U+2003 / U+3000KeptKeptEdges trimmedRemoved
Zero-width space U+200BKeptKeptKeptKept
Line feedKeptKeptKept (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.

Fixed samples run through four modes
SampleModeResultLength
A (52)Extra spacesHello world / blank / indented line end / 2 blanks / last37
A (52)Blank linesThree empty lines gone, spacing kept49
A (52)All spacesHelloworld, indentedline, tabs and breaks kept36
A (52)All whitespaceHelloworldindentedlineendlast29
B (17)Extra spacesa b, c, empty line, d; CRLF kept11
B (17)Leading and trailinga b, c, empty line, d; LF endings9
C (13)Extra spacesOnly the double plain space shrinks; both NBSP stay12
C (13)All whitespaceAll six spaces gone, the zero-width space stays7

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.

Remove Extra Spaces – Utinzo

Learn more from an authoritative source:

Wikipedia
Related tools

Results are estimates for informational purposes only and do not constitute professional financial, medical, legal, or technical advice. Read full disclaimer →