Tabs to Spaces Converter
Convert tabs to spaces or spaces to tabs in code and text, with a configurable tab width. Fixes indentation for consistent formatting.
Last reviewed by the Radiatus Cloud team
Convert tabs to spaces or spaces to tabs with a configurable tab width.
Need this built for your product?
We design, build & host secure software & APIs.
Convert tabs to spaces and back
Indentation style is a perennial debate, and mixed tabs and spaces cause misaligned code and noisy version-control diffs. This converter switches your code between tab and space indentation with a tab width you choose. Converting tabs to spaces replaces each tab with the chosen number of spaces, while converting spaces to tabs collapses groups of that many spaces back into tabs. By default it touches only the leading whitespace on each line, so spaces inside strings and alignment are preserved.
This makes it easy to bring a file in line with a project's style guide or your editor's settings.
Consistent indentation
Many style guides mandate one approach: a lot of projects prefer spaces for predictable alignment across editors, while others use tabs so each developer can set their own display width. Whatever the rule, consistency matters, and converting a stray file to the correct style avoids the frustrating diffs and review comments that mixed indentation produces.
Keeping the conversion to leading whitespace is the safe default, since replacing every tab or run of spaces in the body of the code could corrupt strings and comments. All conversion happens locally in your browser.
Related tools
- JSON Formatter — Format and beautify JSON in your browser. Pinpoints syntax errors by line and column, flags unsafe integers, and never uploads your data to a server.
- JSON Validator — Validate JSON syntax with precise line and column errors, and check documents against a JSON Schema. Runs locally in your browser, nothing uploaded.
- Regex Tester — Test regular expressions against sample text with live match highlighting, capture groups and flag control. Runs entirely in your browser.
- HTML Minifier — Minify HTML by removing comments and redundant whitespace, without breaking inline elements or pre blocks. Runs entirely in your browser.
Frequently Asked Questions
How many spaces replace a tab?
Whatever tab width you set, commonly two or four. Each tab becomes that many spaces, and that many spaces collapse back into one tab when converting the other way.
Does it change spaces inside my code?
By default no. With "leading whitespace only" on, it converts only the indentation at the start of each line, leaving strings and inline spacing intact.
Should I use tabs or spaces?
It depends on your project\'s style guide. Spaces give consistent alignment everywhere, while tabs let each developer choose their display width. Consistency is what matters most.
Can it fix a file with mixed indentation?
Yes. Converting in one direction normalises the leading whitespace so the whole file uses a single consistent style.
Will it affect my line endings?
No. It only changes tab and space characters. Line endings are left exactly as they are.
Privacy & Security
Everything runs in your browser; nothing is uploaded.
How to Use
Paste code, choose the direction and tab width, and copy the result.
Disclaimer: This tool is provided "as is" without warranty of any kind. Results are for educational and utility purposes.
Related Tools
JSON Formatter
DeveloperFormat and beautify JSON in your browser. Pinpoints syntax errors by line and column, flags unsafe integers, and never uploads your data to a server.
JSON Validator
DeveloperValidate JSON syntax with precise line and column errors, and check documents against a JSON Schema. Runs locally in your browser, nothing uploaded.
Regex Tester
DeveloperTest regular expressions against sample text with live match highlighting, capture groups and flag control. Runs entirely in your browser.