Text & Writing Tools

Trim Lines Online – Remove Leading and Trailing Spaces from Each Line

Paste text with many lines and remove the extra spaces at the start and end of every line. Choose to trim both sides, only the left side or only the right side. Then copy the result or download it as a .txt file. It runs in your browser page, so there is nothing to install.

0 characters

Options

Processing runs in this page using JavaScript. Do not paste confidential information.

Why use this tool?

Why use this tool?

Text copied from emails, PDFs, spreadsheets, logs or code often carries spaces and tabs at the start or end of lines. You cannot see the ones at the end, but they can break comparisons, imports and forms. Fixing them line by line by hand is slow. A line trimmer cleans every line in one step and leaves the words themselves as they are.

How to use it

How to use it

  1. Step 1

    Add your text

    Paste or type your lines into the Input text box, or press Load example to try sample text.
  2. Step 2

    Choose the Trim mode

    Pick both to clean the start and end of each line, left for the start only, or right for the end only. Both is the default.
  3. Step 3

    Check the result

    Read the trimmed lines in the Result box.
  4. Step 4

    Copy or download

    Press Copy result, or Download .txt to save the file. Press Clear to start again.

How to remove spaces from the start and end of each line

Paste your text into the Input text box, one line per row. The tool trims every line on its own and shows the cleaned lines in the Result box, joined back with line breaks. By default it trims both sides of each line. Use the Trim mode option if you want to trim only one side.

Copyable sample text

Paste this into the input box (each line has spaces before and after the word), or press Load example: apple banana cherry With the default Trim mode (both), the result is: apple banana cherry

Trim mode: both, left or right

The Trim mode option decides which side of each line is cleaned. Both is the default and removes spaces at the start and at the end of each line. Left removes only the whitespace at the start of each line, which helps when you want to remove indentation. Right removes only the whitespace at the end of each line, which helps when you want to remove trailing spaces and keep the indentation.

What the tool changes and what it keeps

It removes whitespace such as spaces and tabs at the edges of each line. Spaces between words inside a line stay as they are. Each line is handled separately, and the order of your lines does not change.

Copy the result or download it as a .txt file

Use Copy result to put the trimmed text on your clipboard (the button shows Copied! when it works). Use Download .txt to save the result as a plain text file. Clear empties the tool so you can start again.

Features explained

Trim each line

Removes whitespace from the edges of every line, one line at a time.

Trim mode: both (default)

Removes spaces and tabs at the start and at the end of each line.

Trim mode: left

Removes whitespace only at the start of each line, such as indentation.

Trim mode: right

Removes whitespace only at the end of each line, such as invisible trailing spaces.

Copy result to clipboard

One click copies the trimmed text. The button changes to Copied! so you know it worked.

Download as .txt

Saves the result as a plain text file, useful when you want to keep it.

Load example

Fills the input with sample text so you can see how each Trim mode works before you use your own.

Clear and reset

The Clear button empties the tool so you can start with new text.

Runs in the page

Text is processed with JavaScript in the page. No request to a server was found in the tool code.

What can you use it for?

Remove trailing spaces from lines

Set Trim mode to right to clean invisible spaces at the end of lines in code, notes or logs.

Remove indentation from copied text

Set Trim mode to left to take away spaces and tabs at the start of each line, for example in text copied from a PDF or an email.

Clean lists before you use them

Trim a list of names, IDs or emails so that stray spaces do not break a comparison or an import.

Tidy pasted text from spreadsheets

Clean cells copied from a spreadsheet that carry extra spaces around the values.

Prepare text for forms and code

Remove extra edge spaces from each line before you paste the text into a form, a config file or a script.

Tool information

Tool typeLine trimmer (remove whitespace at the edges of each line)
InputPlain text, pasted or typed in the Input text box
OptionTrim mode
Trim mode valuesboth, left, right
Trim mode defaultboth
OutputTrimmed lines joined with line breaks, in the Result box
CopyCopy result button
Download format.txt (plain text)
ProcessingIn the page with JavaScript (client-side)

Benefits

  • Cleans every line in one step instead of line by line.
  • Three trim modes let you remove only the side you need.
  • Words and spaces inside a line stay as they are.
  • Copy or download the result in one click.
  • Works in the browser page, with nothing to install.

Limitations

  • It works with plain text. The code shows no file upload, so paste your text into the box.
  • It trims only the edges of each line. It does not remove extra spaces between words inside a line.
  • It does not remove empty lines or change the order of lines.
  • Trim mode is its only option.
  • The download is a .txt file only.

Privacy

This tool processes your text in the page using JavaScript, and no network request was found in the tool code. Even so, do not paste confidential information such as passwords or private data.

Tips

  • Use Load example first to see how the result looks.
  • Choose right if you want to keep indentation and only clean the end of each line.
  • Choose left if you want to remove indentation and keep the end of each line.
  • Press Clear before you paste new text so old text does not stay in the tool.

Frequently asked questions

How do I remove spaces from the start and end of each line?

Paste your text into the Input text box and keep the Trim mode on both, which is the default. Every line is trimmed and the cleaned text appears in the Result box.

How do I remove leading spaces from every line?

Set Trim mode to left. It removes the whitespace at the start of each line and leaves the end as it is.

How do I remove trailing spaces from every line?

Set Trim mode to right. It removes the whitespace at the end of each line and keeps the start, so indentation stays.

Does this remove spaces between words?

No. It trims only the edges of each line. Spaces between words inside a line stay the same.

Does the tool remove empty lines?

No. It trims each line and does not delete lines. Its only job is to remove whitespace at the edges.

Does it remove tabs too?

Yes. Trimming removes whitespace at the edges of a line, which includes spaces and tabs.

Can I download the trimmed text?

Yes. Press Download .txt to save the result as a plain text file.

Is my text uploaded to a server?

The tool processes text in the page with JavaScript, and no network request was found in the tool code. Still, avoid pasting confidential information.