How To Trim Whitespace From Text
Learn what trimming does, why trailing spaces cause bugs, and how to clean the start and end of every line at once.
What Is Trim Text?
Trim Text will trim whitespace from every line. It will remove leading spaces, remove trailing spaces, and strip whitespace from the start and end of each line: " hello world " becomes "hello world". Use it to trim lines in bulk. The words and the spacing between them stay exactly as they were.
Try Trim Text →Why Trailing Whitespace Causes Bugs
Whitespace at the ends of a line is invisible but consequential. It breaks exact comparisons, causes coupon codes and passwords to fail validation, misaligns data in spreadsheet columns, and trips linters in source code. Trimming is one of the most common normalisation steps before storing or comparing text.
How It Works
The tool processes each line independently, stripping leading and trailing whitespace and leaving the interior of the line alone. For example, " hello world " becomes "hello world": the interior spacing is preserved, only the ends are cleaned.
This tool is free and runs online entirely in your browser. Your text stays on your device, protecting your privacy: nothing is uploaded to a server, and results appear instantly.
Common Mistakes
Trim Text vs Other Whitespace Tools
Trim Text is the most targeted of the whitespace cleanup alternatives: it only touches the edges of each line and preserves everything else. Remove Extra Spaces is more thorough: it also collapses runs of spaces inside each line. Normalize Whitespace is the most aggressive alternative: it removes all whitespace runs and line breaks, collapsing the entire text to a single space-separated line. Remove Blank Lines deletes empty rows but leaves line content alone. A common pattern is to run Trim Text first to clean the edges, then Remove Extra Spaces to clean the interior.