Tabs to Spaces Converter
Convert tabs to spaces or spaces to tabs with configurable tab width — instant, private, client-side
Paste code with mixed indentation, pick a tab width (2, 4, or 8), and convert every tab to spaces — or flip it the other way — in one click. No regex, no editor plugins, no multi-file find-and-replace headaches. And everything runs in your browser. Nothing gets uploaded.
How It Works
The tool walks through every line of your text. In tabs-to-spaces mode, each tab character gets replaced with your chosen number of space characters. In spaces-to-tabs mode, it looks at the leading whitespace on each line and converts groups of spaces that match your tab width into a single tab. Inline spacing stays untouched — only the indentation changes when going from spaces to tabs.
Examples
Python function with tab indentation
A colleague wrote this in Vim with tabs. Your project uses 4-space indentation per PEP 8.
def greet(name):
if name:
print(f"Hi {name}")
else:
print("Hello")
def greet(name):
if name:
print(f"Hi {name}")
else:
print("Hello")
JavaScript with 2-space conversion
Switching a React component from tabs to 2-space indentation to match the project's .editorconfig.
function App() {
return (
<div>
<h1>Hello</h1>
</div>
);
}
function App() {
return (
<div>
<h1>Hello</h1>
</div>
);
}
Converting spaces back to tabs for a Makefile
Makefiles require actual tab characters for recipe lines. Someone accidentally converted everything to spaces and now make throws "missing separator" errors.
build:
gcc -o main main.c
echo "Done"
clean:
rm -f main
build:
gcc -o main main.c
echo "Done"
clean:
rm -f main
Who Uses This
Standardizing indentation before a pull request so the diff doesn't show every line as changed.
Cleaning up code snippets pasted from different editors before publishing documentation.
Fixing indentation on assignments before submission — some grading systems reject tabs.
Converting YAML and config files that break when tabs sneak in where only spaces are allowed.
Common Mistakes
Setting the width to 4 when your project uses 2 (or vice versa) doubles or halves your indentation depth. Check your .editorconfig or linter settings first.
Running a blanket tabs-to-spaces conversion on an entire project can break Makefiles. The make command requires tab characters for recipe lines — spaces won't work. Convert those files back separately.
Tabs-to-spaces mode replaces every tab in the text, including ones used for column alignment inside comments or ASCII tables. If you only want to fix indentation, review the output to make sure mid-line formatting still looks right.
Technical Details
- Processing: 100% client-side — your code never leaves the browser
- Browser Support: Chrome, Firefox, Safari, Edge
- Tab Widths: 2, 4, or 8 spaces
- Max Input: No hard limit — handles large files smoothly
Frequently Asked Questions
Why do some projects require spaces instead of tabs?
Spaces render at the exact same width in every editor, terminal, and code review tool. Tabs can show up as 2, 4, or 8 characters wide depending on the app, which means alignment breaks when someone else opens your file. That's why style guides for Python (PEP 8), most JavaScript projects, and many other languages default to spaces.
Should I use 2 or 4 spaces for indentation?
It depends on the language and your team's rules. JavaScript, HTML, and Ruby communities tend to favor 2 spaces. Python, Java, and C# lean toward 4. If your project already has an .editorconfig or a linter config, match whatever is in there. Starting fresh? Two spaces saves horizontal space; four makes nesting levels easier to see.
Can I convert spaces back to tabs?
Yes. Switch to "Spaces → Tabs" mode and set your tab width. The tool converts leading spaces on each line into tab characters. Spaces inside the line (like between words or in string literals) stay exactly as they are.
Does this work with YAML files?
It does, and it's actually one of the most common use cases. YAML does not allow tabs for indentation at all — the parser will throw an error. If you've pasted YAML that has tabs mixed in, run it through this tool with 2-space width and the problem goes away instantly.
Is my code safe? Does it get sent to a server?
No server involved at all. The conversion happens entirely in your browser using JavaScript. Nothing is uploaded, nothing is stored, and nothing leaves your machine. You can even disconnect from the internet and it will still work.