All Over Tools logo
Tool Combiner
Analyze Tools Clean Tools Compare Tools Convert Tools Data Validation Extract Tools Format Tools Generate Tools Organize Tools Transform Tools
Audio Tools Font Tools Image Tools Subtitle Tools Video Tools
Archive Tools Document Tools Ebook Tools File Management Tools PDF Tools Presentation Tools
Config Tools Database Tools Dataset Tools JSON Tools Parser Tools Spreadsheet Tools XML Tools
Business Calculators Construction Calculators Date And Time Calculators Education Calculators Financial Calculators Food Calculators Health Calculators Math Calculators Science Calculators Sports Calculators Statistics Calculators
Blog About Us Contact Us

Trim Whitespace

Removes leading and trailing spaces from every line of text.

How to trim whitespace from text

Paste multiline text into the input area or choose Upload for a text file. Trim Whitespace processes each line when the input or an option changes. It removes whitespace at each line edge according to the checked controls, then places the result in Output text.

  1. Paste text into the input area or choose Upload for a text file.
  2. Keep Trim leading spaces and Trim trailing spaces checked, or clear one to retain whitespace at that line edge.
  3. Check Collapse inner spaces when runs of spaces or tabs should become one ordinary space.
  4. Review Output text, then choose Copy or Download.

What Trim Whitespace changes

Trim leading spaces and Trim trailing spaces are checked when the page opens. They remove JavaScript whitespace at the start or end of every line. Collapse inner spaces is off when the page opens; when checked, it changes each run of ordinary spaces or tabs to one space after the edge options run.

Input:  [  hello   world  ]
Output: [hello   world]
With Collapse inner spaces: [hello world]

The brackets in the example show the line boundaries; they are not part of the text. Clear either edge option when indentation or padding at that edge belongs in the data.

How are lines and whitespace handled?

Trim Whitespace splits the input at Windows, Unix, or old-style Mac line breaks, processes each line, then joins the lines with \n. Blank lines remain in place. If the input is empty, Output text stays empty and Copy and Download remain unavailable.

The edge options remove a JavaScript whitespace run at the selected edge, including tabs there. Collapse inner spaces itself changes only spaces and tabs. Letters, numbers, punctuation, and line order stay unchanged.

Common uses for Trim Whitespace

Paste lines copied from a document when some lines have indentation or trailing padding. Keep Collapse inner spaces clear to remove the edge padding while preserving the spacing between words.

Upload a .txt, .csv, .log, or .md file when its lines need the same edge cleanup before you copy the result into another editor.

Check Collapse inner spaces for prose or pasted records with repeated spaces between words. Review Output text first when spacing within a line carries meaning.

Choose a cleanup tool for the change

Text Cleanup & Filter Tools is the parent category when you need a different kind of text change. Choose Remove Empty Lines when blank or whitespace-only lines should be deleted; Trim Whitespace leaves those lines in place.

Choose Remove Duplicate Lines when repeated lines are the problem and you want its case-sensitive comparison with optional space trimming. Choose Trim Lines to Max Length when each line must be shortened to a selected character count, with an optional ellipsis.

Frequently asked questions

How do I remove extra spaces from text?

Paste or upload the text, keep Trim leading spaces and Trim trailing spaces selected, and check Collapse inner spaces if spaces or tabs inside each line should collapse to one space.

Can Trim Whitespace process multiple lines?

Yes. It processes every line separately, keeps blank lines, and returns the lines joined with \n.

Does it remove spaces inside a line?

Only when Collapse inner spaces is checked. It replaces each run of spaces or tabs anywhere in a line with one ordinary space. If an edge option is checked, that edge run is removed first.

Can I remove blank lines with Trim Whitespace?

No. Trim Whitespace keeps blank lines, so use Remove Empty Lines when those lines should be removed.

Related Tools

82 views