Whitespace & Line Break Trimmer
Remove trailing whitespace, normalise line breaks, and clean up invisible characters in text.
Whitespace & Line Break Trimmer
Strip, collapse, and flatten β real-time as you type
How to Use the Whitespace Trimmer
Paste or type text into the input pane and watch the cleaned output appear in real time. Toggle the operation switches on the board to choose exactly which whitespace issues to fix.
Enter any text with unwanted whitespace into the left input pane. You can also click Load sample to try the tool with example content.
Choose which operations to apply: strip leading or trailing spaces, collapse double spaces, remove empty lines, flatten to a single line, convert tabs to spaces, or trim the entire block start-to-end.
Configure additional behaviour such as tab width when converting tabs to spaces. The stats bar updates instantly to show how many characters, lines, and spaces were affected.
Click Copy to grab the trimmed result, or use Use as input to pipe the output back for a second pass of cleaning.
Related tools
How the Whitespace Trimmer Works
The trimmer applies a sequence of regular-expression passes to your text, each targeting a specific class of unwanted whitespace. Operations run in a fixed order so that later steps correctly catch whitespace exposed by earlier ones.
Whitespace Detection
Each line is scanned with the regex /[ \t]+$/ for trailing spaces and /^[ \t]+/ for leading spaces. Tab characters (U+0009) are matched separately and converted to a configurable number of spaces before line-level detection runs, ensuring tab-only lines are correctly identified as blank.
Trimming Modes
Trim start & end calls String.trim() on the whole document to strip leading and trailing newlines. Collapse multiple blank lines replaces three or more consecutive newlines with exactly two, preserving one blank line between paragraphs. Double spaces to single matches runs of two or more space or tab characters within a line and reduces them to one. Flatten to single line joins every newline-separated segment with a space, producing one continuous string.
Line Ending Normalization
The tool operates on the line breaks your browser already normalised. Windows-style CRLF, classic Mac CR, and Unix LF endings are all handled transparently because the processing splits on /\n/ after the platform converts them. No manual line-ending conversion is needed.
Frequently Asked Questions
What is the difference between trim-all and collapse-blanks?
Trim all (trim start & end) removes leading and trailing whitespace from the entire document as a whole. Collapse multiple blank lines works line-by-line, reducing any sequence of two or more consecutive blank lines down to exactly one while preserving paragraph separation. Use trim-all for data pipelines, collapse-blanks for prose.
How does the tool handle tabs versus spaces?
Tabs and spaces are treated independently. The Tabs to spaces operation replaces each U+0009 tab character with 2, 4, or 8 spaces (you choose the width). After conversion, the space-specific operations β trailing stripping, double-space collapsing β operate on the resulting spaces as normal.
Does it support Unicode whitespace characters?
Yes. The double-space collapsing pass uses a /s+/ style match that covers all Unicode whitespace, including non-breaking spaces (U+00A0), en spaces, em spaces, and ideographic spaces. These are common in text copied from web pages or word processors.
Can I use this to minify SQL or JSON strings?
Absolutely. Enable strip trailing spaces, remove empty lines, double spaces to single, and flatten to single line, then copy the output. This produces a minified single-line string ready to embed in code or use as a query.
Does real-time processing affect performance with large texts?
The processing is synchronous O(n) JavaScript that handles texts up to several hundred kilobytes without noticeable delay. For files over approximately 1 MB, consider pasting in sections or using a local editor plugin for the best experience.
Will flattening collapse paragraph breaks?
Yes. The flatten to single line operation joins every line with a space, removing all newlines and paragraph breaks. If you want to keep paragraph groupings, use collapse multiple blank lines instead β it normalises excessive vertical spacing while preserving one blank line between paragraphs.