Tabs to Spaces Converter
Convert indentation between tabs and spaces, in either direction.
Converted live as you type. Nothing leaves your browser.
Options
0 of 0 lines changed
How to convert tabs to spaces
Paste your code
Paste the code or text whose indentation you want to change.
Pick a direction and width
Choose tabs to spaces or spaces to tabs, then set the tab width to 2, 4, or 8.
Choose how far it reaches
Keep it to the indentation, which is the safe default, or convert whitespace across the whole line.
Copy the result
Copy the converted code straight back into your editor.
Why use this tool
Works in both directions
Convert tabs to spaces or spaces back to tabs without switching tools, which matters when a project changes its house style.
Respects tab stops
A tab advances to the next tab stop rather than becoming a fixed run of spaces, so a converted file lines up exactly as it did in an editor set to the same width.
Indentation only by default
Only the leading whitespace is touched unless you ask for more, so spacing inside strings and aligned comments survives the conversion.
Fixes mixed indentation
A file that mixes both is normalized to one or the other, which is usually the real reason a diff looks broken.
Nothing leaves your browser
The conversion runs locally, so proprietary source code is never uploaded.
About this tool
Tabs and spaces are the oldest argument in programming, and most of the time you do not get to pick: the project has a style, the linter enforces it, and a file that arrived from somewhere else has the wrong one. This converter changes the indentation of pasted code from tabs to spaces or from spaces to tabs, at a tab width of 2, 4, or 8.
The conversion treats a tab the way an editor does. A tab moves to the next tab stop rather than expanding into a fixed number of spaces, so a tab sitting in column 3 at a width of 4 becomes two spaces, not four. That is what keeps a converted file looking identical to the original instead of drifting a few columns to the right on every nested line. Going the other way, the indentation is measured first and then rebuilt out of tabs, so a file that mixes both ends up consistent rather than stacking tabs on top of the spaces that were already there.
By default only the leading whitespace on each line is converted. That is the setting you want almost always, because rewriting whitespace across the whole line will also rewrite the spacing inside string literals and any comment that was aligned by hand. The wider option is there when you genuinely want it, with a warning attached. There is also a toggle to strip trailing whitespace, which is the other change most linters ask for. For broader cleanup, see the whitespace remover and the text cleaner, or use the JSON formatter when the file is JSON and you want it reindented properly.
Frequently asked questions
- Does it change anything other than whitespace?
- No. Only tabs and spaces are added or removed. Your code, comments, and line breaks are otherwise untouched.
- Why is my tab not exactly four spaces?
- Because a tab moves to the next tab stop. A tab that starts partway through a column adds only enough spaces to reach the stop, which is what keeps the alignment identical to your editor.
- Will it break strings in my code?
- Not with the default setting, which only converts the indentation at the start of each line. Converting everywhere in the line can change spacing inside strings, so use that option deliberately.
- Is my code uploaded anywhere?
- No. The conversion happens in your browser, so private or proprietary source never leaves your device.
- What tab widths are supported?
- Two, four, and eight spaces, which covers the widths used by nearly every language style guide and editor default.
Related tools
Whitespace Remover
Clean up messy text by trimming lines, collapsing extra spaces, removing blank lines, and stripping line breaks.
Text Cleaner
Fix text copied from PDFs, emails, and word processors: straight quotes, single spaces, no hidden characters.
Add Line Numbers
Prefix every line of your text with a number. Set where the count starts, choose a separator, pad with leading zeros, and skip blank lines.
Alternating Case Generator
Turn text into aLtErNaTiNg caps, the mocking SpongeBob style.
Bionic Reading Converter
Bold the leading part of every word to guide your eyes across the page, with an adjustable emphasis strength and a light or dark preview.
Case Converter
Switch text between UPPERCASE, lowercase, Title Case, camelCase, snake_case, kebab-case, and more.