Remove Extra Spaces From Text
Paste text with untidy spacing. Double spaces shrink to one, tabs and line-end spaces go, runs of empty lines collapse, and a tally shows what was cleaned.
This tool runs in your browser. Nothing you type is uploaded or saved, and there is nothing to install or sign up for.
Where stray spaces come from and why they matter
Extra white space sneaks into writing in ordinary ways. Someone taps the space bar twice after a full stop. A table copied from a web page brings tabs along. Text pulled out of a PDF pads its lines to make them line up. Deleting a word leaves the spaces on both sides of it behind.
Most of this is invisible until it causes trouble: a justified paragraph with odd gaps, a name that will not match in a spreadsheet lookup because of a trailing space, a sign-up form that rejects an email address with a space at the end. This cleaner strips that clutter in one pass and counts what it removed.
Cleaning text with this tool
- Paste your text into Your text.
- Choose the fixes you want. Three boxes start ticked: Shrink repeated spaces to one, Trim the start and end of each line and Change each tab to a space.
- Tick Remove spaces before , . ; : ! ? if punctuation marks have drifted away from the words in front of them.
- Use the Empty lines list to keep all blank lines, reduce each run of them to a single one, or delete them altogether.
- Press Copy cleaned text. Clear empties the box and Reset brings the sample back.
Worked example: 114 characters down to 98
The sample that loads with the page is deliberately messy. Its first line starts with two spaces and has runs of three and four spaces between words. The second line starts with a tab and ends with three spaces. Three empty lines follow, and the last line has a triple space in it. Altogether it is 6 lines and 114 characters.
With the starting options the headline reads 16 characters removed, leaving 98 characters on 4 lines. The tiles break that down: 14 spaces and tabs removed, 1 tab changed, and 2 empty lines removed, because the run of three empty lines is cut to one.
| Change to the options | Characters after | Lines after |
|---|---|---|
| Starting options | 98 | 4 |
| Also remove spaces before punctuation | 95 | 4 |
| Empty lines: remove them all | 97 | 3 |
| Empty lines: keep them all | 100 | 6 |
| Repeated spaces left alone | 106 | 4 |
The punctuation option is worth a look in this example. The sample contains a space before a full stop, before a comma and before an exclamation mark. Ticking the box closes all three gaps, which is why the count drops from 98 to 95.
The order the fixes are applied in
Each line is cleaned on its own, and the ticked steps always run in the same sequence:
- Tabs are turned into spaces.
- Any run of two or more spaces or tabs is replaced by one space.
- Spaces sitting directly before a comma, full stop, semicolon, colon, exclamation mark or question mark are deleted.
- Spaces and tabs at both ends of the line are trimmed.
- Lines that are now empty, or hold only spaces, are kept, thinned or dropped according to the Empty lines list.
The order explains a few results. Because tabs become spaces first, a tab next to a space counts as a repeated space and the pair shrinks to one. If you clear the tab option but leave repeated spaces ticked, a single tab between two words is left untouched, yet a tab that sits in a run with other spaces or tabs is still squeezed into one ordinary space.
Line breaks themselves are never joined here. Only whole empty lines can be removed.
What the cleaner leaves alone
- Non-breaking spaces. Text copied from web pages and word processors sometimes contains a special non-breaking space character. It looks like a space but is a different character, and this tool only handles ordinary spaces and tabs. If a gap survives cleaning, that is the likely cause.
- Indentation you need. Code, outlines and poetry often rely on leading spaces or tabs. Clear the trim and tab boxes for those, or the structure will be flattened.
- Aligned columns. Tables lined up with runs of spaces lose their alignment once repeated spaces are shrunk.
- Decimal points and times. The punctuation fix removes a space before a full stop or colon wherever it finds one, so a deliberate gap such as the one in the phrase version .5 would be closed.
- Missing spaces. Nothing is added. A comma with no space after it stays that way.
One run handles up to 100,000 characters. Two spaces after a full stop is a style choice some writers were taught; this tool treats it as a repeated space and reduces it to one.
Everyday uses for clean spacing
Before handing in an essay, students can paste it here to catch doubled spaces that a quick read misses, then confirm the length with the word counter. Teachers preparing a word list or a set of quiz answers can trim every line so that answers match exactly when they are checked or sorted.
Data tidying is the other big use. Names and codes copied from a spreadsheet or an email often carry trailing spaces that make two identical entries look different. Trim them here, then pass the list to the duplicate line remover or put it in order with the line sorter.
If your text also breaks in the middle of sentences, fix that separately with the line break remover, since this page keeps every line where it is. Capital letters that need straightening out are a job for the case converter.
There are more helpers of this kind among the text tools, and the whole collection of free online tools is listed on one page.
Frequently asked questions
How do I remove extra spaces between words?
Paste the text and keep Shrink repeated spaces to one ticked. Every run of two or more spaces becomes a single space, and the cleaned copy is ready to copy at once.
Does it remove spaces at the start and end of lines?
Yes, when Trim the start and end of each line is ticked, which it is to begin with. Leading and trailing spaces and tabs are deleted from every line separately.
How many characters does the sample lose?
The sample text is 114 characters long and comes out at 98 with the starting options, so 16 characters are removed. Turning on the punctuation fix as well brings it to 95.
Can I delete blank lines too?
Yes. The Empty lines list can keep them all, reduce each run of blank lines to one, or remove every blank line. Lines containing only spaces or tabs count as empty.
Will it remove line breaks?
No. Each line stays on its own line and only fully empty lines can be dropped. Joining lines into paragraphs is a different job that needs a line break remover.
Why is there still a gap after cleaning?
The gap is probably a non-breaking space or another special space character copied from a web page or document. This tool changes only ordinary spaces and tabs, so replace the special character by hand.
