Trim whitespace

Clean up line edges while keeping the spaces inside your text.

Your inputs stay on your deviceFREE · NO SIGN-UP
Trim

Removes whitespace at both edges of every line, including indentation and trailing Markdown spaces. Internal spaces, tabs, and blank lines stay. Non-breaking spaces at the chosen edges are removed; zero-width spaces stay. Up to 200,000 characters.

Result

Start typing and the result appears here. No button needed.

THE LITTLE DETAILS

Trim whitespace, without the extra steps.

Remove unwanted whitespace from the start or end of each line without squeezing the spaces between words. Paste a list, paragraph, or code snippet, choose which edges to clean, and inspect the live result. You can keep indentation by trimming line ends only, or keep intentional trailing spaces by trimming line starts only.

How to use this tool

  1. 1Paste the text you want to clean. Your original remains visible above the result.
  2. 2Choose Both ends, Line starts, or Line ends. The result updates automatically as you type or change the choice.
  3. 3Check the removed-character count and the cleaned text, then select Copy result to use it elsewhere.

When Trim whitespace is the right tool

  • A pasted contact list has stray spaces around each name, but multiword names and repeated entries must remain unchanged.
  • A code review is cluttered with trailing spaces, and you need to remove them while preserving indentation on lines with code.
  • Text copied from a web page carries non-breaking spaces at line edges that ordinary-looking spaces conceal.
  • A Markdown draft needs leading whitespace removed while retaining its intentional two-space line endings.

Choose edges before cleaning structured text

Both ends is a convenient default for a list of names or labels, but indentation can carry meaning in Python, YAML, and Markdown. Choose Line ends when leading spaces matter. Conversely, two trailing spaces can create a Markdown line break, so choose Line starts when those must survive. The tool does not recognize programming languages or Markdown syntax. It follows the selected edge consistently on every line, making the original and the result worth comparing before copying.

Invisible characters are not all the same

A non-breaking space looks like a regular space but prevents a line from wrapping. This tool treats it as whitespace at a chosen edge, alongside tabs, ordinary spaces, and other whitespace recognized by JavaScript. A zero-width space is different: it is retained rather than silently removed. Interior non-breaking spaces remain too. If a copied value still fails an exact match, an invisible character inside the value may require a separate character-inspection workflow.

Blank lines survive the cleanup

Trimming whitespace is different from deleting empty lines. A line containing only spaces becomes empty, but its line break remains, so paragraph separation and the number of lines do not collapse. The processor preserves CRLF, CR, LF, and Unicode line separators as supplied. Browser textareas can normalize pasted line endings to LF before processing; use the agent input when exact separators matter. No lines are reordered, deduplicated, or joined during this operation.

GOOD TO KNOW

A few quick answers.

No. Only whitespace at the selected line edges is removed. Two spaces between words stay as two spaces, and tabs between columns remain tabs. This is useful when alignment or a pasted table depends on the interior spacing. Whitespace-only lines become empty lines when both edges are trimmed.

Select Line ends. Leading spaces and tabs on lines containing text are preserved, while spaces and tabs after the last visible character are removed. An indented line containing no visible characters becomes empty because all its whitespace is trailing. Check code indentation in the preview before replacing your original.

The trimming operation runs locally in your browser, with no text upload. Your original remains in the input until you clear it or leave the page. Copy result writes only the cleaned output to your clipboard when you request it; the tool does not overwrite your source document.

There was no removable whitespace at the selected edges. The result is still available to copy. Try the other edge if you meant to remove indentation or trailing spaces, and remember that spaces between words are intentionally preserved.

A single line made only of spaces or tabs can become an empty result. The workspace explicitly says so. Existing line breaks remain, so multiple blank lines produce a whitespace-only result with a message explaining what survived. Copy result copies that exact output, including an empty string.

The edge choice applies independently to every line. It does not provide a whole-document-only trim or a selection of line numbers. Keep the original in your editor when only a particular region should change, and paste that region into this tool.

Back to all tools