Free online text tool

Remove Leading and Trailing Spaces

Removing Leading And Trailing Spaces deletes the spaces at the start and end of your text or of each line. Paste your text, click the button and copy the result. It is free and runs in your browser.

Remove Leading and Trailing Space Tool

0Character Count
0Character Count (without spaces)
0Word Count
0Sentence Count
0Paragraph Count
0Line Count

Space Removal Example

Before
   The sky is clear; the stars are twinkling.   
After
The sky is clear; the stars are twinkling.

Bookmark: press Ctrl+D (Windows) or Cmd+D (Mac) to save this tool.

Suggest a New ToolProvide Feedback on This Tool

What does Removing Leading And Trailing Spaces do?

This tool removes the spaces at the start and at the end of your text. These are called leading and trailing spaces. They are easy to miss, but they cause trouble in forms, spreadsheets, code and file names.

You can trim the whole text at once, or trim each line separately, which is the default. Spaces between words are never touched, so only the edges are cleaned. Tabs and non-breaking spaces can be removed too, and you can also delete empty lines at the start and end.

Use it to clean pasted text, lists, email addresses, CSV data and anything copied from a web page or a PDF.

Remove leading and trailing spaces examples

Unless an option is named, each line is trimmed, tabs and non-breaking spaces count as spaces and empty lines are kept.

SettingBeforeAfter
Text with spaces around it
   The sky is clear; the stars are twinkling.   
The sky is clear; the stars are twinkling.
Each line, on
  one  
   two
three   
one
two
three
Each line, off (whole text only)
  one  
   two
three   
one  
   two
three
Spaces inside are kept
  a   b  
a   b
Tabs, on
		indented	
indented
Tabs, off (only spaces)
  	x	  
	x	
Empty lines at the end, kept
  a  

  b  

a

b

Empty lines at the end, removed
  a  

  b  

a

b

How to remove leading and trailing spaces

  1. 1
    Add your text
    Type or paste your text into the box, or import a text file.
  2. 2
    Choose your options
    Keep Trim each line separately ticked to clean every line, or untick it to trim only the start and end of the whole text.
  3. 3
    Click Trim Spaces
    The spaces at the edges are removed. Use Undo if you change your mind.
  4. 4
    Copy it
    Click Copy and paste the result where you need it.

When to remove leading and trailing spaces

Good for

Cleaning pasted text, lists, email addresses and CSV data, and fixing text copied from web pages, PDFs and spreadsheets before you use it.

Check first

Indentation counts as leading spaces, so code or lists with indents lose them when each line is trimmed. Untick Trim each line separately to keep the indent of the lines in the middle. The result replaces your text, so use Undo if you need the original.

Other tools

To shrink spaces between words, try Remove Extra Spaces. To delete every space, try Remove Spaces. To clean tabs, try Remove Tabs From Text.

Remove leading and trailing spaces FAQ

What does the Removing Leading And Trailing Spaces tool do?

It removes the spaces at the start and at the end of your text, or of each line, and leaves the spaces between words as they are.

What are leading and trailing spaces?

Leading spaces come before the first character of a text or line. Trailing spaces come after the last character. They are hard to see but can break forms, searches and data.

How do I remove leading and trailing spaces?

Paste or type your text, then click Trim Spaces. Copy the result with the Copy button.

Does it remove the spaces between words?

No. Only the spaces at the edges are removed. To change spaces between words, use Remove Extra Spaces.

What is the difference between trimming each line and the whole text?

With Trim each line separately ticked, every line is cleaned at both ends. Unticked, only the very start and the very end of the whole text are cleaned, and the lines in between keep their spaces.

Does it remove tabs and non-breaking spaces?

Yes, by default, because they look like spaces but are different characters. Untick that option to remove normal spaces only.

Can it remove empty lines at the start and end?

Yes. Tick Also remove empty lines at the start and end. Empty lines in the middle of the text are not touched.

What if there is nothing to remove?

The tool shows a message and leaves your text as it is.

Is this tool free and is my text private?

Yes. It is free, needs no account and runs in your browser, so your text is not uploaded to a server.

Looking for more text tools?

Browse Remove Tools

Last updated: 14 November 2026