Tools

Home
Case ConverterWord CounterCharacter CounterFind & ReplaceSort ListRemove Empty Lines

Tabs to Spaces Converter

Convert tabs to spaces or spaces to tabs with configurable tab width — instant, private, client-side

Your files never leave your browser
Tab width:
Input0 chars, 0 lines
Output0 chars, 0 lines
Ready·

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

Paste Text
→
Scan & Replace Characters
→
Clean Output

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.

INPUT
def greet(name): if name: print(f"Hi {name}") else: print("Hello")
OUTPUT
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.

INPUT
function App() { return ( <div> <h1>Hello</h1> </div> ); }
OUTPUT
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.

INPUT
build: gcc -o main main.c echo "Done" clean: rm -f main
OUTPUT
build: gcc -o main main.c echo "Done" clean: rm -f main

Who Uses This

👨‍💻 Developers

Standardizing indentation before a pull request so the diff doesn't show every line as changed.

📝 Technical Writers

Cleaning up code snippets pasted from different editors before publishing documentation.

🎓 Students

Fixing indentation on assignments before submission — some grading systems reject tabs.

🛠️ DevOps Engineers

Converting YAML and config files that break when tabs sneak in where only spaces are allowed.

Common Mistakes

Using the wrong tab width

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.

Forgetting that Makefiles need real tabs

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.

Converting inline alignment, not just indentation

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

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.

Share: