Whitespace Cleaner

Trim, collapse and tidy messy whitespace.

Free whitespace cleaner — trim lines, collapse repeated spaces and blank lines, remove blank lines, and convert tabs to spaces. Runs entirely in your browser, nothing is uploaded. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

What can it clean up?

It trims each line, collapses repeated spaces, collapses or removes blank lines, trims the start and end of the whole text, and can convert tabs to spaces — each as a separate toggle.

Tidy up messy whitespace

This tool cleans up text littered with extra spaces, stray tabs, and too many blank lines — the kind you get after copying from a PDF, email, spreadsheet, or web page. Every cleanup step is an independent toggle, so you fix only what you want and leave the rest alone.

How it works

The cleaner processes your text line by line, applying the options you enable in a fixed order so they combine predictably:

  1. Tabs to spaces — each tab becomes two spaces.
  2. Collapse spaces — runs of spaces or tabs within a line shrink to a single space.
  3. Trim lines — leading and trailing whitespace is removed from every line.
  4. Blank lines — either remove all empty lines, or collapse consecutive blanks down to one.
  5. Trim ends — extra blank lines and spaces at the very start and end of the text are stripped.

It only touches whitespace, never the words themselves, and shows a live character count of the result.

Worked example

Input — pasted from a PDF, messy spacing preserved:

   Hello    world
		Indented   line


Last line

With line-trimming, space-collapsing, and blank-line collapsing enabled:

Hello world
  Indented line

Last line

Each line is trimmed, the repeated spaces collapse to one, the tab is converted to two spaces and then the leading spaces on that line are trimmed, and the double blank line becomes a single blank. Words and punctuation are unchanged.

Where this is useful

PDF copies. PDF text extraction often inserts extra spaces between characters or at line ends, and every table cell may arrive as a separate line with leading spaces. Line-trimming and space-collapsing together fix most of it in one pass.

Spreadsheet pastes. Tab-separated data copied from a spreadsheet into a plain-text field brings tabs as column separators. If you only want the text content and not the structure, tabs-to-spaces followed by collapse gives a human-readable result.

Email threads. Forwarded email chains often carry leading > or spaces before each line. This cleaner removes the leading whitespace; pair it with a find-and-replace tool to strip the > characters.

Code and config files. Mixed tabs and spaces cause indentation errors in Python and YAML. Converting all tabs to spaces and then checking the indentation level is the first step in fixing these.

Before importing to a CMS or database. Content pasted into a CMS field sometimes carries invisible leading or trailing whitespace that causes display bugs or search-index mismatches. A trim pass before import prevents those.

Why the order of operations matters

The cleaner applies steps in a fixed sequence so options combine cleanly:

  • If tabs convert to spaces first, the collapse-spaces step can handle them along with any other runs of spaces on the same pass.
  • If lines are trimmed before blank lines are collapsed, the blank-line step correctly identifies truly empty lines rather than lines that only contain spaces.
  • Trimming the ends last removes any artifacts left by the previous steps.

Changing this order could produce unexpected results — for example, collapsing blank lines before trimming lines would leave “empty” lines that actually contain spaces, so the collapse would miss them.

Everything happens in your browser; nothing is uploaded.