Remove Leading and Trailing Spaces

Paste your text, choose which side to trim and which kinds of spaces count, and press Trim spaces. The text between the first and last visible characters of each line is never changed.

Try an example

About this space trimmer

Spaces you cannot see at the start or end of a line cause real problems: a spreadsheet treats "Berlin " and "Berlin" as different values, a database import rejects a padded ID, and code review tools flag trailing whitespace. This tool removes them from every line at once. Choose the start, the end, or both, and whether to trim only spaces and tabs or every kind of whitespace, including the non-breaking and full-width spaces that often come from web pages, Word documents, and PDFs. Spaces between words are never touched.

How to trim spaces from each line

  1. Paste your text. Paste text, CSV data, or code, or press an example. An example only fills the box.
  2. Choose what to trim. Tick leading, trailing, or both, decide whether blank lines stay, and pick which kinds of spaces count.
  3. Press Trim spaces. The trimmed text appears below with how many spaces were removed from each side.
  4. Copy or download. Press Copy text, or Download to save the result.

Frequently asked questions

Are spaces between words removed?

No. Only spaces before the first visible character and after the last visible character of each line are removed. To shrink double spaces between words, use Remove Spaces.

What is a non-breaking space and why does it matter?

A non-breaking space looks like a normal space but is a different character, often pasted from web pages or Word. Many trim functions ignore it. Choose All whitespace to remove it along with full-width, em, and zero-width spaces.

Will trimming break the indentation of my code?

Removing leading spaces removes indentation, which matters in languages such as Python and YAML. Untick Remove leading spaces to clean only trailing whitespace and keep the code structure.

What happens to lines that contain only spaces?

They become empty lines. With Keep blank lines on they stay as empty lines; turn it off to delete them.

How are tabs counted in the statistics?

Each tab or space character counts as one, so a tab followed by two spaces counts as three removed characters.