Tabs to spaces converter
Paste code or text and switch its indentation between tabs and spaces. Choose the tab width and whether to change only the leading indentation or every tab in the line; tab stops are respected, so columns stay aligned.
Runs in your browser: nothing you enter is sent anywhere.
How to use it
- Paste the text.
- Choose spaces or tabs and the tab width your project uses.
- Keep “Only indentation” for code; untick it for tables aligned with tabs.
- Copy the result. The line under it says how many lines changed.
How it works
The converter measures each line in columns. A tab advances to the next multiple of the width; every other character takes one column. To make spaces, each tab is replaced by the spaces up to that stop. To make tabs, indentation is measured and written as whole tabs plus leftover spaces, or, on whole lines, each run of two or more spaces is split at the tab stops it crosses.
Example
With width 4, a line starting with two tabs, \t\treturn 1, becomes eight spaces and return 1. Back the other way, b (six spaces) becomes one tab and two spaces. Across whole lines with width 8, ab\tc becomes ab + six spaces + c, because the tab stop is at column 8.
Tips
- Python forbids mixing tabs and spaces inconsistently in one block; converting the whole file fixes such errors.
- Makefiles need tabs at the start of recipe lines: convert to tabs or leave those files alone.
- Use the whitespace visualizer to see which characters a file contains before and after.
Frequently asked questions
What is the difference between indentation only and whole lines?
With indentation only, just the whitespace at the start of each line is converted, so tabs or spaces inside the line - for example before a comment - stay as they are. Untick it to convert every tab, or every run of spaces that reaches a tab stop, anywhere in the line.
Why is a tab sometimes fewer spaces than the width?
A tab moves to the next tab stop, a multiple of the width, not a fixed distance. With width 4, a tab after two characters adds two spaces. The converter counts columns the same way, so text aligned with tabs stays aligned.
What happens to indentation that is not a multiple of the width?
When converting to tabs, the indentation becomes as many tabs as fit, plus the remaining spaces. Six spaces at width 4 become one tab and two spaces.
Are single spaces between words turned into tabs?
No. When converting whole lines to tabs, only runs of two or more spaces that reach a tab stop become tabs, the same rule as the Unix unexpand -a command. Single spaces between words stay.