Trim Whitespace

Paste text and take the spaces and tabs off both ends of every line, or only the start, or only the end. The count of trimmed lines is shown below.

How it works

Each line is trimmed on its own. Both ends removes the spaces and tabs before the first character and after the last. Start only removes the indentation. End only removes the trailing spaces and keeps the indentation, which is the usual cleanup for code.

Only spaces and tabs are removed. A no-break space at the start of a line is usually there on purpose, so it stays. The spaces between words are not touched either.

Line breaks are kept exactly, Windows ones included, and so is a final line break at the end of the text. No line is added or removed. Everything runs on this page.

How to use it

  1. 1 Paste your text into the Text box.
  2. 2 Choose Both ends, Start only or End only.
  3. 3 Check the count below the result to see how many lines were trimmed.
  4. 4 Copy the result, or download it as a .txt file.

Good to know

  • Trailing spaces in code show up as noise in a code review diff. End only removes them and leaves the code's shape alone.
  • A column pasted from a spreadsheet often has a space after each value. Both ends fixes the whole column at once.
  • Start only flattens indented text, such as a quoted email reply, back to the left margin.
  • To also turn double spaces between words into one, use Remove Extra Spaces.

Browser support

  • Chrome 94 and later
  • Firefox 93 and later
  • Safari 16.4 and later
  • Edge 94 and later

These are the oldest versions with everything the tool uses. They are worked out from the tool itself, so they change when it does.

Version numbers checked on 2026-09-04.

Cleaning trailing spaces out of code without losing its indentation

Open a code review and some changes are nothing but whitespace: a line marked as changed because it lost or gained a space at the end. Editors add these quietly, and they make real changes harder to see. Many projects reject trailing spaces in their style checks for this reason. When you have a file full of them and no editor setting at hand, this tool fixes it in one paste.

Choose End only. Each line loses the spaces and tabs after its last character, and nothing else changes. The indentation at the start of each line stays, so a Python function is still a Python function and a nested YAML list keeps its levels. The note under the result says how many lines were trimmed, for example "Trimmed 37 of 210 lines", which is the same number a diff will show as changed when you save it.

Both ends is for data. A column of names copied from a spreadsheet often has a space after some of the values, and a list typed by hand sometimes has a space before a few. Those spaces make "Smith" and "Smith " different values to a lookup or a deduplicate. Trimming both ends makes every line start and end with a real character. Start only does the opposite job to End only: it flattens indented text, such as a quoted email reply, back to the left margin.

Two things are kept on purpose. First, line breaks: each line keeps its own break, so a Windows file keeps its Windows line breaks and git will not see every line as changed. A final line break at the end of the file is kept as well. Second, no-break spaces: they are left alone, because someone usually typed them on purpose to keep two words together.

The tool has limits. It works on spaces and tabs only, so it will not remove a zero-width space or a no-break space at the end of a line; the Whitespace Visualizer shows those. It does not touch the spaces between words, and it does not remove empty lines. It takes up to 1 MB of text at a time, which is far more than most source files.

Frequently asked questions

What is the difference between this and Remove Extra Spaces?

Trim Whitespace touches only the two ends of each line. Remove Extra Spaces also turns double spaces between words into one and removes indentation.

Does it remove empty lines?

No. An empty line or a line of only spaces becomes an empty line, but it stays. Remove Empty Lines takes them out.

Why is a space at the start of a line still there?

It is probably a no-break space, which this tool leaves alone because it is usually deliberate. The Whitespace Visualizer shows which character it is.

Will my Windows line breaks be changed?

No. Each line keeps its own line break, so a file with Windows line breaks comes out with Windows line breaks.

Related tools

Your files are processed on your device and are not uploaded. You can verify this in your browser’s developer tools under the Network tab.