Free Remove Spaces Online

Remove double spaces, trailing spaces and blank lines as you type. Finds non-breaking and zero-width spaces, rejoins PDF line breaks. Runs in your browser.

No login. Files processed for your request and discarded. Free to use. Files processed & discarded →

Compress PDF — it's free or choose from 130+ tools

130+ Free Tools
— Files Processed
— Happy Visitors
— Pages Explored
0 Files Stored

Remove Extra Spaces from Text

Part of Text tools: See all Text tools.

What is Remove Spaces?

A whitespace cleaner that works as you type. It turns double spaces into single spaces, trims each line, changes tabs to spaces (or keeps them), keeps, collapses or removes blank lines, and finds hidden characters such as non-breaking spaces, zero-width spaces and byte order marks. It can also rejoin lines broken by a PDF or put everything on one line. It runs in your browser.

How to use Remove Spaces

  1. Paste your text in the top box. The cleaned text appears straight away.
  2. Choose what happens to line breaks: keep every line, collapse blank lines to one, remove all blank lines, rejoin lines into paragraphs or put everything on one line.
  3. Choose how lines are trimmed and whether tabs become spaces or are kept.
  4. Tick extra options if you need them: fix special spaces, remove invisible characters, remove spaces before punctuation or remove every space.
  5. Copy the result or download it as a .txt file.

Why use this tool?

Text copied from PDFs, emails and web pages carries double spaces, trailing spaces, extra blank lines and invisible characters that look fine but break spreadsheet lookups, searches and code. This tool shows you which hidden characters were in your text, keeps your line breaks unless you ask otherwise, and never uploads anything.

FAQ

How do I remove double spaces from text?
Paste the text. Every run of two or more spaces becomes one space straight away, and spaces at the start and end of each line are removed. Copy the result when you are done.
Will it remove my line breaks?
Not by default. Every line stays where it was. Choose Remove all blank lines to delete empty lines, Rejoin lines into paragraphs for PDF text, or Put everything on one line to join it all.
How do I remove blank lines but keep paragraphs?
Choose Collapse blank lines to one. Runs of empty lines become a single empty line, so paragraphs stay separate. Lines that contain only spaces or tabs count as blank.
Does it remove non-breaking and zero-width spaces?
Yes. Non-breaking spaces and other Unicode spaces become normal spaces, and zero-width spaces, word joiners, byte order marks and soft hyphens are deleted. The tool lists what it found. Zero-width joiners are kept because emoji and some scripts need them.
Can I fix line breaks in text copied from a PDF?
Yes. Choose Rejoin lines into paragraphs. Lines in the same paragraph are joined with a space and blank lines still separate paragraphs. A word split with a hyphen at a line end is joined, keeping the hyphen.
Can I keep tabs for TSV data or code?
Yes. Set Tabs to Keep tabs. Tabs stay as they are and spaces next to them are removed. For code, also set Trim to End only so indentation is kept.
Is my text uploaded?
No. Cleaning happens in your browser. The text is not sent to our server, stored or logged.

What this space remover does

Paste any text and the cleaned version appears straight away in the result box. There is no button to press. By default the tool turns every run of two or more spaces into a single space, removes spaces and tabs at the start and end of each line, changes tabs to spaces, swaps non-breaking and other special spaces for normal ones and deletes invisible characters such as zero-width spaces and byte order marks. Your line breaks stay exactly where they were unless you choose otherwise.

Under the options, a short line tells you which hidden characters were found in your text, with their Unicode code points, for example "3 no-break spaces (U+00A0), 1 zero-width space (U+200B)". Under the result, a summary says how many characters and lines went in, how many came out, and what was changed. That makes it easy to see why two strings that look identical refuse to match in a spreadsheet or a search.

How to remove extra spaces

  1. Paste or type your text in the top box. The result updates as you type.
  2. Choose what happens to line breaks: keep every line, collapse runs of blank lines to one, remove all blank lines, rejoin lines into paragraphs, or put everything on one line.
  3. Choose how each line is trimmed (start and end, start only, end only, or not at all) and whether tabs become spaces or are kept.
  4. Tick or untick the extra options: collapse double spaces, fix special spaces, remove invisible characters, tidy spaces before punctuation, or remove every space.
  5. Copy the result or download it as a .txt file. Use result as input lets you run a second pass with different settings.

The line break options explained

Keep every line as it is only cleans the spaces inside lines. Blank lines stay, so paragraph spacing and the layout of lists are not touched. This is the safest choice when you only want to fix double spaces.

Collapse blank lines to one turns any run of empty lines into a single empty line and removes blank lines at the very start and end. Text pasted from emails and web pages often has three or four empty lines between paragraphs; this brings it back to normal paragraph spacing. A line that contains only spaces or tabs counts as blank.

Remove all blank lines deletes every empty or whitespace-only line, which is what you want for lists, CSV rows, log files and code where empty lines get in the way. Lines with any visible content are kept in their original order.

Rejoin lines into paragraphs is meant for text copied from a PDF, where every line ends where the page column ended instead of where the sentence ended. Lines that belong to the same paragraph are joined with a single space, and a blank line still marks the start of a new paragraph. If a line ends with a letter and a hyphen and the next line starts with a lowercase letter, the two are joined without a space, so "mid-" and "dle" become "mid-dle". The hyphen is kept, because the tool cannot know whether it was a real hyphen as in "well-known" or one the PDF added to split a word, so check hyphenated words afterwards.

Put everything on one line joins all lines with single spaces. It is handy for turning a wrapped address, a list of keywords or a multi-line sentence into one line for a form field, a spreadsheet cell or a URL.

Hidden spaces and invisible characters

Not every space is the ordinary space character. Web pages and word processors use the non-breaking space (U+00A0) to stop a line from breaking between a number and its unit, and copy-paste carries it into your text. It looks the same as a normal space, but a formula such as MATCH or VLOOKUP, a database query or a search will treat "100 kg" and "100 kg" as different. The tool also recognises the narrow no-break space (U+202F), thin and hair spaces, en and em spaces, the figure space, the ideographic space used in Chinese and Japanese text (U+3000) and the other Unicode space separators, and changes them to a normal space when that option is ticked.

Some characters take up no space at all. The zero-width space (U+200B), the word joiner (U+2060), the byte order mark (U+FEFF) that some programs put at the start of a file, and the soft hyphen (U+00AD) are invisible on screen but still break comparisons, word counts and code. With the invisible characters option ticked they are deleted. The zero-width joiner (U+200D) and zero-width non-joiner (U+200C) are deliberately kept, because they hold emoji sequences such as family and flag emoji together and control how letters join in scripts such as Hindi, Persian and Arabic. Removing them would change what your text says.

Windows line endings (a carriage return followed by a line feed) and old Mac line endings are changed to plain line feeds. Line and paragraph separators (U+2028, U+2029), vertical tabs and form feeds are treated as line breaks.

The other options

Trim each line controls the spaces and tabs at the edges of lines. Trimming the start removes indentation, so choose End only if you want to keep indented code or nested lists but still remove trailing spaces, which are invisible and often flagged by code editors and version control.

Tabs are changed to spaces by default and then collapsed with the rest. If your text is tab-separated data or code that relies on tabs, choose Keep tabs. Tabs then stay as they are, and any spaces sitting right next to a tab are removed so that columns line up cleanly.

Remove spaces before punctuation is off by default. When ticked, it removes spaces in front of a comma, full stop, semicolon, colon, exclamation mark, question mark or percent sign, as well as spaces just inside round, square and curly brackets. "Hello , world ." becomes "Hello, world." It only does this when the punctuation mark is followed by a space, a quote, a bracket or the end of the line, so a decimal such as ".5" in "costs .5" is left alone. Leave it off for French text, which uses a space before some punctuation on purpose, and for code.

Remove every space deletes all spaces (and tabs, unless you chose to keep them) while keeping line breaks, so the words on each line run together. Use it for phone numbers, card or account numbers pasted with spaces, product codes, or building identifiers. Combined with one line mode it removes every bit of whitespace.

Common uses

  • Cleaning text copied from PDFs, emails, chat apps and web pages before pasting it into a document or a CMS.
  • Fixing spreadsheet lookups and duplicate checks that fail because one cell has a non-breaking space or a trailing space.
  • Tidying lists of names, emails or keywords before you remove duplicate lines or sort them.
  • Removing the trailing spaces and invisible byte order mark that make code, CSV files or configuration files behave strangely.
  • Turning a wrapped block of text into a single line for a form field, or stripping spaces from a number you copied.

Limits

The tool works on plain text. If you paste from a rich editor, formatting such as bold or links is not carried into the box, only the characters. It does not understand code: collapsing spaces inside a string literal or Python indentation will change the code, so use End only trimming and keep tabs if you clean source files, or use our find and replace for targeted changes. Paragraph rejoining relies on blank lines between paragraphs; if your PDF text has none, the whole text becomes one paragraph. Text up to 5,000,000 characters is supported so your browser stays responsive.

Privacy

All cleaning happens in your browser with JavaScript. The text you paste is not uploaded to our server, stored or logged, and the tool keeps working if you lose your connection after the page has loaded. Related tools: change text case, remove duplicate lines, sort lines and find and replace.

Also try

Related tools that work well with this one: