Tabs to Spaces Converter
Convert tabs to spaces or spaces to tabs with a custom tab width.
Characters: 0Lines: 0
Converting between tabs and spaces
Indentation style is one of the oldest debates in programming. This tool flips a file either way: Tabs → Spaces replaces each tab with your chosen number of spaces, and Spaces → Tabs collapses leading indentation back into tab characters. Many style guides (and tools like Go and Make) expect one or the other, so this is handy for normalizing a file before committing.
Need other whitespace fixes? See remove extra spaces and remove empty lines. It all runs locally in your browser.
Built and maintained by Meet Shah · Last updated
What this tool is used for
- Normalising indentation to match a project's convention before committing.
- Converting tabs to spaces for a format that forbids tabs, such as YAML.
- Converting spaces back to tabs for a codebase that requires them.
- Fixing a file that has picked up a mixture of both.
- Aligning indentation width across files from different editors.
Frequently Asked Questions
- Why does spaces-to-tabs only touch the indentation?
- Because converting interior runs of spaces would corrupt your code. Spaces inside a string literal, inside a comment or used to line up an ASCII table are meaningful; only leading whitespace is indentation. The reverse direction converts every tab, since a tab is never alignment.
- How is a partial indent handled?
- Leading whitespace is expanded to its true column, then rebuilt as whole tabs plus leftover spaces. With a width of 4, six columns become one tab and two spaces — which is what preserves alignment that does not fall on a tab stop.
- Which should a project use?
- Whichever your language's ecosystem uses — Python's PEP 8 and Go's gofmt disagree deliberately, and the cost of mixing is far higher than either choice. Python 3 makes it an outright error: mixing tabs and spaces for indentation raises a TabError.
- Is there an accessibility argument?
- Yes, and it favours tabs: a tab is one character whose displayed width the *reader* controls, so a developer who needs eight columns and one who wants two can read the same file comfortably. Spaces freeze that decision for everyone.
- How do I stop this recurring?
- Commit an `.editorconfig` with `indent_style` and `indent_size`; every major editor honours it without a plugin. Add a formatter to the pre-commit hook so the question is settled by a tool rather than in review.
- How does a tab inside a string literal get handled?
- It must not be converted — a tab in a string is data, and replacing it changes the program's output. Converting only leading whitespace is what makes the operation safe on source code.
Common errors and gotchas
- Converting tabs inside string literals, which changes data rather than indentation.
- Choosing a tab width that does not match the project's, which shifts every nested line.
- Converting a file where tabs were required, such as a Makefile recipe line.
- Leaving a mixture behind by converting only leading whitespace or only some lines.
- Producing a whole-file diff that hides the one real change in the same commit.
Related Text Tools tools
Case Converter
Convert between Sentence, Title, camelCase, snake_case, and more.
Word Counter
Count words, characters, and analyze keyword density.
Text to Binary
Convert text into its 8-bit binary representation.
Binary to Text
Decode 8-bit binary back into readable text.
Text Reverser
Reverse text by characters, words, or lines.
Remove Duplicate Lines
Delete repeated lines and keep your list unique.
Remove Empty Lines
Strip blank and whitespace-only lines from text.
Sort Lines Alphabetically
Sort lines A–Z or Z–A, case-sensitive or not.