Skip to main content

Clean text

Tidy up text pasted from a PDF, an email or a web page by trimming line edges, collapsing runs of spaces and tabs and removing empty lines, without changing the words themselves.

  • Clipboard
Automate

Embed this widget

Customize the result, check the live preview, then copy the code.

Preview

Embed code type

Code to copy

Responsive and automatically resized by Bethemesh.

Clean text

Was this tool useful?

How does this tool work?

Remove unwanted spaces and empty lines from text copied out of a document, an email or a web page. You choose exactly which corrections to apply: trimming spaces at the start and end of each line, collapsing repeated spaces and tabs, or deleting empty lines. The result is produced locally in your browser and can be copied or downloaded.

The tool offers three independent options, all switched on by default. The first removes spaces at the start and end of every line. The second replaces any run of ordinary spaces or tabs with a single space. The third deletes lines that are completely empty once the other options have run. Line breaks are normalised first, so text coming from Windows or another system ends up with consistent line endings. To keep the indentation of a code snippet, switch off line trimming and space collapsing: those characters can be part of the syntax. Likewise, keep empty lines when they separate paragraphs or blocks of data. This cleaner does not fix spelling or punctuation, does not change letter case and has no option for removing repeated lines; use the dedicated tool to deduplicate a list. Start with a small extract when you work with Markdown, CSV or any data whose layout carries meaning, and check the result before copying it or downloading the text file. Before cleaning structured text, choose the options one by one. A list of names usually tolerates collapsed spaces, whereas a code extract or a table aligned with tabs may depend on them. After processing, review the passages where line breaks and indentation have a particular meaning.

How to use this tool

  1. Paste the text

    Type or import the text you want to clean.

  2. Choose the corrections

    Turn the three options on or off according to the structure you need to keep.

  3. Run, then check

    Click the clean button, review the result and copy or download it.

Use cases

Text copied from a PDF

Even out the irregular spacing of a passage recovered by copy and paste.

Tidying a list

Remove the empty lines from a list of references or names.

Draft to share

Get rid of stray spaces before pasting text into an email.

Examples

Spaces and an empty line

All three options are on: the line edges are trimmed, the triple space becomes one and the empty line disappears.

Input

  alpha   beta  

 gamma  

Result

alpha beta
gamma

Spaces collapsed, empty line kept

Only space collapsing is on: tabs and repeated spaces become a single space, and the empty line stays.

Input

Name:		Smith

City:   Leeds

Result

Name: Smith

City: Leeds

Tips and best practices

  • Do not collapse spaces in a code extract where indentation matters.
  • Removing empty lines can visually merge separate paragraphs.
  • Keep the original when the text must stay strictly identical in structure.

Frequently asked questions

Do I have to use all three options?

No. You can turn each one on separately or combine them, depending on the result you want.

Are tabs removed?

When space collapsing is on, any run of spaces and tabs is replaced with a single space. With that option off, tabs are left as they are.

Does the tool remove duplicate lines?

No. None of its three options deletes repeated lines; use the dedicated tool for removing duplicate lines.

Can I keep the empty lines?

Yes. Switch off the option that removes empty lines to keep the separations.

Is my text sent to a server?

No. The cleaning runs in your browser, and you can then copy or download the result.

Related tools

Tools similar or complementary to this one.

Similar tools

Automatically remove empty lines and lines containing only spaces from a text.

Text & writingUse this tool

Convert text to lowercase, UPPERCASE, Title Case or other common case styles.

Text & writingFeaturedUse this tool

Replace a text fragment in a pasted or imported document.

Text & writingNewUse this tool