Whitespace Remover
Trim text and collapse repeated spaces, tabs and blank lines.
Trim text and collapse repeated spaces, tabs and blank lines.
The Whitespace Remover cleans text by trimming line edges, collapsing repeated spaces and reducing unnecessary blank lines. It is useful for copied content, notes, lists and text exported from other applications.
Text pasted from PDFs, emails or formatted documents often carries extra spaces, tabs and inconsistent line spacing that aren't visually obvious but can cause problems when that text is used in code or data processing.
For related tasks, try Remove Empty Lines, Remove Duplicate Lines or Line Counter.
The tool processes text locally in your browser. It replaces repeated horizontal whitespace with a single space, trims each line and limits runs of blank lines.
Text with multiple spaces and several blank lines is reduced to consistent spacing while keeping paragraph breaks readable.
Text copied from a PDF with three consecutive spaces between some words and a single space between others becomes visually and functionally consistent once whitespace is collapsed down to single spaces throughout.
Trimming whitespace typically removes it only from the start and end of the text or of each line, while collapsing repeated whitespace reduces multiple consecutive spaces or blank lines down to a single one throughout the middle of the text; these are two distinct operations.
Trimming removes spaces at the start and end of the text, and collapsing reduces runs of spaces, tabs and blank lines to one. The text with extra spaces around words, such as spaces before Hello, then many spaces, then world, becomes Hello world. These are common problems in text pasted from PDFs, emails and web pages, where layout turns into spare spaces.
Some spaces look the same but are different characters. A non-breaking space, code 160, prevents line breaks and is not always matched by ordinary space handling, and zero-width characters take no visible space at all. They often come from web pages and word processors and can cause problems in data matching, passwords and file names. If cleaning does not fix a problem, inspect the characters with the Text to ASCII Converter.
Do not use whitespace removal on code, YAML, Markdown tables or any text where spacing has meaning. Python and YAML rely on indentation, and tables rely on aligned columns. Collapsing the spaces would change the meaning or break the file. For such text only trim the end of each line, or edit by hand. Keep a copy before you clean.
Clean whitespace before you compare, sort or remove duplicates, because a trailing space makes two otherwise identical lines different. In spreadsheets, a leading space can stop a lookup from matching. Trimming imported names, emails and codes avoids hard-to-find errors. After cleaning, check the line and word counts to confirm that only spacing changed.
Pasted data often has irregular spacing, such as columns separated by many spaces or a mix of tabs and spaces. Collapse the runs to a single space or a tab, and trim each line, before you split the data into columns. As a check, the text Hello followed by three spaces and world has 13 characters, and after collapsing, Hello world has 11. Count again after cleaning to confirm that only spacing changed, and compare a few lines with the original to make sure that nothing was merged by accident.
Different whitespace problems need different fixes. Spaces at the start and end of a line are fixed by trimming. Several spaces between words are fixed by collapsing to one. Tabs used for alignment may need to become single spaces. Many blank lines between paragraphs can be reduced to one. Non-breaking spaces from web pages may need a separate replacement. Decide which fix you need, apply it, and compare the character count before and after so that you know how much was removed.
Suppose the text is a line with spaces at both ends, several spaces between words and a tab in the middle, followed by three blank lines and another line. Trimming removes the spaces at the ends, collapsing turns each run of spaces and the tab into a single space, and reducing the blank lines leaves one empty line between the two lines of text. The result is clean, consistent text that is easier to read, compare and import. Checking the character count before and after shows how much extra space there was.
Not all blank-looking characters are ordinary spaces. A non-breaking space, code 160, appears on web pages and in word processors, and many tools do not treat it as a space. A zero-width space, code 8203, takes up no room at all but can break a search, a password or a lookup. A byte order mark at the start of a file is invisible but can confuse programs. Spreadsheet trimming functions usually remove only ordinary spaces, so copied web data may still contain hidden characters. If a clean-looking value does not match, check for these.
Clean spacing before you use text as data. Names with trailing spaces fail to match in lookups, product codes with leading spaces are treated as different values, and extra spaces in a file can shift columns when you split text into fields. Trim each line and collapse repeated spaces before you remove duplicates, sort or compare lists. After cleaning, check the word and character counts to confirm that only spaces changed, and compare a few lines against the original.
Some text depends on its spacing. Python and YAML use indentation to define structure, so collapsing it breaks the file. Markdown uses two trailing spaces for a line break and indentation for code blocks, and tables rely on aligned columns. Poetry and addresses may use blank lines on purpose. For these, remove only trailing spaces, or work by hand. Always keep a copy of the original so that you can restore formatting if the result is not what you wanted.
Whitespace is any character that shows as blank space, including spaces, tabs and line breaks. Trimming removes whitespace from the ends of a line or text. Collapsing reduces runs of whitespace to a single character. A non-breaking space is a space that prevents a line break. A zero-width space takes up no room and is invisible. Indentation is leading whitespace that shows structure. A byte order mark is an invisible marker at the start of some files. Normalisation prepares text for comparison.
Trim first and then collapse, and keep line breaks unless you want one line of text. Check for non-breaking and zero-width characters if clean-looking values still do not match. Do not use it on code, YAML or Markdown that depends on indentation. Compare character counts before and after to confirm that only spacing changed, and keep a copy of the original.
Whitespace includes ordinary spaces, tabs, line breaks and non-breaking spaces that web pages often add. Decide first what you want to remove. Trimming the start and end of each line is safe for most text, collapsing repeated spaces into one is useful for copied content, and removing all spaces changes the text completely. Do not use it on code or data that depends on indentation, such as Python files or YAML settings, because it can change the meaning. After cleaning, compare the character count before and after with the character counter, and read the result once to confirm that words were not joined together.
No. It keeps paragraph structure while removing excessive blank lines.
The built-in tool runs in your browser and does not need an external API.
Yes. Tabs are normalized as whitespace.
Trimming removes leading and trailing whitespace from text or lines, while collapsing reduces multiple consecutive spaces or blank lines in the middle down to a single space or line.
PDF files store text based on visual positioning rather than a clean underlying text structure, so copying text out of a PDF can introduce inconsistent or extra whitespace.