Trim Text

Paste any text and the tool removes leading and trailing whitespace from each line, collapses repeat blank lines, and strips invisible Unicode characters. Toggle individual rules to fit the cleanup you need.

Trim rules

Trim leading whitespace
Spaces and tabs at line start
Trim trailing whitespace
Spaces and tabs at line end
Collapse blank lines
Multiple blank lines → one
Strip invisible chars
Zero-width, BOM, etc.

What the trim tool does

Trim text is shorthand for a small but high-frequency cleanup job: remove the whitespace at the start and end of each line, drop the empty lines piling up between paragraphs, and strip the invisible Unicode characters that PDFs, Word, and Slack export silently include. See also: character counter. See also: find-and-replace.

The four toggles let you mix and match:

  • Trim leading whitespace. Strips spaces and tabs at the start of each line.
  • Trim trailing whitespace. Strips spaces and tabs at the end of each line.
  • Collapse blank lines. Multiple consecutive blank lines collapse to a single blank line.
  • Strip invisible characters. Removes zero-width spaces (U+200B), zero-width non-joiners (U+200C), zero-width joiners (U+200D), the byte-order mark (U+FEFF), and soft hyphens (U+00AD).

All four run client-side, and order matters: the trim happens first, then the blank-line collapse, then the invisible-char strip.

When you need to trim text

The cleanup job comes up constantly: See also: Remove Line Breaks.

  • Paste from PDF. PDFs export with leading spaces on every line, ragged line wraps, and invisible characters. A trim pass fixes 80% of the mess in one click.
  • CSV prep. Spreadsheet exports include trailing tabs and stray spaces in cells, which confuses downstream consumers.
  • Form data. User-submitted form text has whitespace from copy-paste. Strip before storage.
  • Code identifiers. Stripping invisible Unicode characters from variable names prevents the maddening "this looks identical but doesn't match" bug.
  • Email or chat exports. Slack and Gmail exports add trailing whitespace and hidden formatting markers.

For more aggressive cleanup (HTML tag stripping, smart-quote normalization, repeated punctuation cleanup), pair this with the text cleaner for a single-pass solution.

Trim vs strip vs collapse

The vocabulary around whitespace cleanup is loose, so it's worth nailing down the distinctions used on this page:

  • Trim typically means "remove leading and trailing whitespace from each line or from the whole string." It does not touch whitespace in the middle of the string.
  • Strip is often used interchangeably with trim but can also mean "remove all instances of a character anywhere in the string." Context matters.
  • Collapse means "replace a run of N whitespace characters with a single one." Used in two flavors: collapse blank lines (multi-line) and collapse spaces (in-line).

This tool defaults to trim + blank-line collapse + invisible-char strip - the combination that solves the most common PDF-paste cleanup case.

Privacy and what stays on your machine

Every cleanup operation runs in JavaScript inside your browser. No upload, no logging, no telemetry. The input, the toggles, and the output never leave your page. Verify in your browser's network tab: zero requests after the initial page load.

This matters because the texts people paste into trim tools are often pre-publication editorial drafts, scraped data they're cleaning for analysis, or proprietary code identifiers. Sending any of that to a third-party server is a category of risk none of these jobs justify.

Frequently asked questions

What does "trim text" mean?

Trim means remove the whitespace at the start and end of each line, drop the empty lines between paragraphs, and (optionally) strip the invisible Unicode characters that PDFs and Word documents silently include.

What's the difference between trim and strip?

In common usage they're synonymous. Some programming-language docs (Python, JavaScript) use trim specifically for whole-string leading/trailing whitespace and strip for character-by-character removal. This tool uses trim in the broader sense - leading/trailing line whitespace + blank-line collapse + invisible-char strip.

What invisible characters does the tool strip?

Zero-width space (U+200B), zero-width non-joiner (U+200C), zero-width joiner (U+200D), byte-order mark (U+FEFF), and soft hyphen (U+00AD). These are the most common silent characters in PDF and Word exports.

Why does my PDF copy-paste have so much extra whitespace?

PDFs preserve the visual layout, not the logical text structure. When you copy from a PDF, the extraction includes the whitespace used to render columns, indentation, and gutters. Trim eliminates most of it in one pass.

Does trim affect internal whitespace?

No. Whitespace in the middle of a line passes through untouched. The tool only modifies leading whitespace, trailing whitespace, and blank lines between paragraphs. To collapse internal multiple spaces to single spaces, use the remove whitespace tool.

Can I undo a trim?

The original text stays in the input box and the trimmed version goes to the output box. To undo, copy the original back from the input. The tool does not maintain a multi-step undo stack.

Is the trimmed text uploaded anywhere?

No. Every operation runs in your browser. The input, the toggles, and the output never leave the page.

Does it handle non-breaking spaces?

Non-breaking spaces (U+00A0) are technically whitespace and are stripped from leading/trailing positions. If you want to preserve non-breaking spaces while stripping regular spaces, the current tool does not separate them - use a custom regex in a code editor instead.

Related tools

More wordcounter.ai tools

Other tools you might find useful.

Browse the full catalog →