Skip to content

Whitespace Remover and Trimmer

Remove extra whitespace, trim leading and trailing spaces, collapse multiple spaces, and clean up messy text formatting.

Whitespace Remover and Trimmer tool

Loading...

Example

Input: Hello world, how are you? typed with 3 leading spaces, 2 to 5 spaces between words and 3 trailing spaces

Result: Hello world, how are you?

Leading and trailing spaces are trimmed and every run of spaces or tabs inside a line is collapsed to a single space.

  1. Paste the text with unwanted spaces into the input area.
  2. Choose the cleaning options: Trim Lines, Collapse Spaces and Remove Blank Lines.
  3. Turn each option on or off to get the cleanup you need.
  4. Compare the cleaned text in the output with your original.
  5. Click the copy button to copy the cleaned text.

Cleaning Up Extra Spaces, Tabs and Blank Lines

The Whitespace Remover cleans up messy spacing in text. By default it trims spaces from the start and end of every line, and it squeezes runs of spaces and tabs into a single space, so "Hello world" becomes "Hello world". A third option deletes blank lines.

Each option is a switch you can turn on or off. Trim Lines removes indents and trailing spaces. Collapse Spaces shrinks gaps inside a line. It also turns tabs into single spaces, so switch it off if you need to keep tab-separated columns. Remove Blank Lines deletes empty lines, including lines that hold only spaces. The breaks between lines of text are always kept, so paragraphs and lists keep their shape.

Hidden spaces are often the real problem. Text copied from a PDF, web page or email can contain non-breaking spaces and other special spaces. They look normal but break searches, formulas and code. This tool handles them too: Trim Lines removes them from the ends of lines, and Collapse Spaces turns them into ordinary spaces. Zero-width characters do not count as spaces here, so they are left alone. After cleaning, you can drop repeated lines with Remove Duplicate Lines. To strip zero-width characters, search for them with Find and Replace in regex mode.

Frequently Asked Questions

This tool always leaves one space between words. To remove every space, use a find and replace tool: search for a single space and leave the replacement empty. In regex mode, searching for \s removes every kind of whitespace, including tabs and line breaks, so use that only when you want one unbroken string.
No. It never removes the line break between two lines of text, so your structure stays the same. To join lines, use a find and replace tool in regex mode, search for \n and replace it with a space. That is useful for text copied from a PDF, where every line ends with a hard break.
The gap may not be a space. Zero-width characters are invisible and are not treated as whitespace here, and some PDFs use tabs or line breaks inside sentences. Paste a sample into a Unicode converter to see which characters are there, then remove them with find and replace.

Related Tools

Remove Duplicate Lines

Remove duplicate lines from text while keeping the original order. Supports case-sensitive and case-insensitive modes.

Text and Writing

Find and Replace

Find and replace text with regular expressions, capture groups, case-sensitive matching, and a live match count.

Text and Writing

Case Converter

Convert text between UPPER, lower, Title, Sentence, camelCase, snake_case, kebab-case, CONSTANT_CASE, and PascalCase.

Text and Writing

Word Counter and Character Counter

Count words, characters, sentences, and paragraphs in your text. Includes reading time and speaking time estimates.

Text and Writing

Sort Lines

Sort lines of text alphabetically (A-Z or Z-A) with natural number order, by line length, or shuffle and reverse them.

Text and Writing

Text to Slug and URL Generator

Convert any text into a clean, URL-friendly slug. Handles special characters and accented Latin letters automatically.

Text and Writing