How trimming works
JavaScript's built-in String.prototype.trim() strips every Unicode whitespace character from both ends of a string. That covers ASCII space, tab, line feed, carriage return, the non-breaking space (U+00A0), em space, en space, and the rest of the Unicode White_Space property. The internal whitespace of each line is left alone, only the runs at the very start or end disappear.
The Side dropdown swaps the regex used. Both calls trim() directly. Left Only uses /^\s+/ to delete only leading whitespace. Right Only uses /\s+$/ to delete only trailing whitespace. So you can clean up trailing spaces in code without touching indentation, or vice versa.
The Per Line toggle is on by default: each line is trimmed independently, so a multi-line block has every line cleaned. Turn it off and the trim runs once on the whole string, which only strips the very first and very last runs of whitespace in the document. Both modes preserve the line endings between lines exactly as they came in.
How to use trim whitespace from text
- 1Paste your text into the input panel on the left.
- 2Pick a Side: Both, Left Only, or Right Only.
- 3Leave Per Line on to clean every line, or turn it off to trim the document's ends only.
- 4Read the trimmed result on the right as you type.
- 5Click Copy to grab the cleaned text.
Keyboard shortcuts
Drive TextResult without touching the mouse.
| Shortcut | Action |
|---|---|
| Ctrl F | Open the find & replace panel inside the input Plus |
| Ctrl Z | Undo the last input change |
| Ctrl Shift Z | Redo |
| Ctrl Shift Enter | Toggle fullscreen focus on the editor Plus |
| Esc | Close find & replace, or exit fullscreen |
| Ctrl K | Open the command palette to jump to any tool Plus |
| Ctrl S | Save current workflow draft Plus |
| Ctrl P | Run a saved workflow Plus |
What this tool actually does
Trims every Unicode whitespace character
Built on String.prototype.trim() and the \s regex class, which match every codepoint with the Unicode White_Space property. ASCII space and tab, non-breaking space, em space, line tabulator, and others are all caught.
Choose left, right, or both ends
The Side dropdown selects the regex. Left Only deletes leading whitespace only, useful for stripping outdented code. Right Only deletes trailing whitespace only, useful for cleaning up source files before commit. Both does the standard double-sided trim.
Per-line versus whole-text mode
With Per Line on (default), the input is split on \n or \r\n, each line is trimmed, then the result is rejoined with \n. With it off, the trim runs once on the whole string, which only touches the very first and very last whitespace runs.
Internal whitespace is untouched
Spaces and tabs inside each line stay in place. The trim only matches at the edges of each line (or each whole document, if per-line is off). Use remove extra spaces if you also want to collapse runs in the middle.
Blank lines pass through
A line containing only whitespace becomes an empty line, but the line itself is still in the output. To also drop those rows, follow with remove blank lines, which can be set to treat whitespace-only lines as empty.
Worked example
Side: Both, Per Line on. Leading and trailing whitespace on every line is stripped, including the leading tab on row two.
indented line one line with tab spaced both sides
indented line one line with tab spaced both sides
Settings reference
| Setting or behaviour | Effect on output |
|---|---|
| Side: Both (default) | Trims leading and trailing whitespace on each line. |
| Side: Left Only | Trims leading whitespace only. Trailing spaces and tabs survive. |
| Side: Right Only | Trims trailing whitespace only. Indentation survives. |
| Per Line on (default) | Splits on newline, trims each line, rejoins. Cleans every row. |
| Per Line off | Trims the whole text once. Only the first and last whitespace runs in the document are removed. |
| Internal whitespace | Always preserved. Use remove extra spaces to collapse runs in the middle. |
| Blank lines | Stay in the output (as empty rows). Use remove blank lines to drop them. |
FAQ
Will it remove tabs too, or just spaces?
\s, which matches every Unicode whitespace character including ASCII space, tab, line feed, carriage return, non-breaking space, and em space. Anything the language considers whitespace is removed at the line edges.How is per-line different from one-shot trim?
Does it remove empty lines?
Will internal spaces collapse too?
Does it modify line endings?
\n or \r\n, but the rejoin uses \n. So a CRLF input comes out as LF after a per-line trim. Run find and replace afterwards if you need to restore CRLF.