Remove Extra Spaces

Clean up text by collapsing extra whitespace, removing line breaks, or trimming.

Why pasted text is full of stray whitespace

Text copied from a PDF, an email client or a web page almost never arrives clean. It carries double spaces, tab characters, line breaks in the middle of sentences, trailing spaces at the end of every line, and invisible characters that survive a visual inspection.

This tool strips all of it in one pass, leaving text you can paste into a document or a CMS without spending ten minutes tidying by hand.

Key takeaways

  • PDF copying is the worst offender - it preserves layout line breaks as real ones.
  • Double spaces after full stops are a typewriter convention that modern typography does not need.
  • Trailing whitespace is invisible but breaks diffs, YAML and Markdown.
  • Non-breaking spaces look identical to normal ones but behave differently.
  • Zero-width characters can survive copy-paste and silently break searches.

What it cleans

OperationBeforeAfter
Collapse multiple spacesHello    worldHello world
Remove tabsName[tab][tab]ValueName Value
Trim line ends"text   ""text"
Remove blank linesLine 1, then blank lines, then Line 2Line 1 ⏎ Line 2
Join broken linesa sentence bro[newline]ken upa sentence broken up
Space before punctuationHello , world !Hello, world!

The one space or two debate

Double spacing after a full stop is a habit inherited from mechanical typewriters, which used monospaced type where every character occupied the same width. The extra space helped mark sentence boundaries visually.

Proportional fonts - everything you read on a screen or in a printed book - already space sentences correctly. Every current style guide, including Chicago, APA and MLA, specifies a single space. HTML collapses consecutive spaces anyway, so double spaces on the web achieve nothing except inflating your character count.

If you learned to type on a typewriter, this is a genuinely hard habit to break. Rather than retraining your thumbs, just run the text through this tool before publishing. The result is identical and considerably less irritating.

Invisible characters worth knowing about

CharacterCodeWhy it causes trouble
Non-breaking spaceU+00A0Looks like a space but does not wrap or match a normal space in search
Zero-width spaceU+200BCompletely invisible; breaks string matching
Zero-width joinerU+200DUsed in composed emoji; can appear unexpectedly
Byte order markU+FEFFOften prefixes files exported from Windows tools
Line separatorU+2028Breaks JavaScript string literals
Ideographic spaceU+3000A full-width space common in CJK text

These survive copy-paste and are invisible on screen, which makes them a common cause of "but it looks identical" bugs in spreadsheets, config files and search queries.

A recurring spreadsheet mystery. A VLOOKUP fails even though two cells look identical, because one contains a trailing space or a non-breaking space. Running both columns through a whitespace cleaner resolves it more often than any other fix.

Where line breaks matter

  • Markdown treats a single line break as a space within a paragraph, and a blank line as a paragraph break. Two trailing spaces force a hard break - which is why removing trailing whitespace can change Markdown output.
  • YAML is whitespace-significant and will fail to parse if indentation is altered. Do not run YAML through a generic space cleaner.
  • Python uses indentation as syntax, so the same warning applies.
  • CSV fields containing line breaks must stay quoted, or the file structure breaks.
  • Windows and Unix line endings differ - CRLF versus LF - and mixing them causes spurious changes in version control.
Everything happens in your browser. Your text is processed entirely on your own device using JavaScript. Nothing is uploaded, stored or logged, which means you can safely paste confidential drafts, client work or personal notes. Closing the tab discards everything.

Frequently Asked Questions

How do I remove double spaces from text?

Paste the text into the tool above and it collapses every run of consecutive spaces into a single space in one pass. This is considerably faster and more reliable than a manual find-and-replace, which has to be run repeatedly to catch triple and quadruple spaces.

Why does text copied from a PDF look broken?

Because PDFs store text positioned on a page rather than as flowing paragraphs. Copying preserves the layout line breaks as real line breaks, so sentences arrive chopped up mid-word. Joining broken lines while preserving genuine paragraph breaks fixes it.

Should I use one space or two after a full stop?

One. Double spacing came from monospaced typewriters where every character had the same width. Proportional fonts space sentences correctly on their own, and every current style guide specifies a single space. HTML collapses double spaces anyway.

What is a non-breaking space?

A space character that prevents a line break at that point, written as   in HTML. It looks identical to a normal space but is a different character, so text searches and spreadsheet lookups treat the two as non-matching - a very common source of confusion.

Why does my spreadsheet lookup fail on identical-looking text?

Almost always a trailing space or a non-breaking space in one of the cells. The values look the same on screen but are different strings. Cleaning whitespace in both columns resolves this more often than any other fix.

Does removing trailing whitespace affect Markdown?

Yes, in one specific way. Two trailing spaces at the end of a Markdown line force a hard line break. Removing them turns that into a normal soft wrap. If you rely on that syntax, use explicit line-break markup instead.

Is it safe to clean whitespace in code?

Not blindly. YAML and Python treat indentation as syntax, so a generic space cleaner will break them. Trailing whitespace removal is generally safe and often desirable in code, but leading indentation must be preserved.

Is my text uploaded anywhere?

No. Cleaning happens entirely in your browser, so nothing is transmitted or stored. You can safely paste confidential content, and closing the tab discards it.

Related Calculators