Home Text Tools Tab to Space Converter
↔️
Text

Tab to Space Converter

Convert tab characters to spaces for consistent indentation across all editors and platforms. Set tab width (2, 4, or 8 spaces), convert only leading indentation or all tabs, and preview a live diff showing exactly what changed.

🔒 Browser-based2 / 4 / 8 spaces👁 Live diff view⚡ Instant
Switch Tool:
🔒 100% Private — All processing runs in your browser. Your text is never sent to any server.

📖How to Use the Tab to Space Converter

  1. 1
    Paste your tab-indented text

    Paste code, config files, or any text that uses tab characters for indentation. The tab count and affected line count are displayed immediately so you can see the scope of the conversion before processing.

  2. 2
    Set spaces per tab

    Choose 2 spaces (modern JavaScript, TypeScript, Ruby), 4 spaces (Python PEP 8, PHP, Java), or 8 spaces (traditional Unix, C legacy). You can also type a custom value. The output updates instantly as you change the setting.

  3. 3
    Review the diff and copy

    The live diff view highlights every changed line — original (with tab markers ¬) shown in red, converted (with space dots ·) shown in green. Copy or download the converted text when satisfied.

💡Quick Reference

LanguageConvention
Python (PEP 8)4 spaces
JavaScript / TS2 spaces
Go (gofmt)Tabs (required)
PHP / Java4 spaces
MakefileTabs (required)

Frequently Asked Questions

Why should I convert tabs to spaces?

Tabs render at different widths depending on the editor, terminal, or viewer. Your IDE may show a tab as 4 spaces wide, GitHub renders it as 8, a terminal may use 4 or 8 depending on system settings. Spaces are always exactly one character wide everywhere, guaranteeing consistent visual alignment across all tools, platforms, and collaborators.

How many spaces should I use per tab?

Follow your project or language convention. Python (PEP 8) requires 4 spaces. Modern JavaScript and TypeScript typically use 2 spaces (enforced by Prettier). Ruby uses 2 spaces. Java and PHP commonly use 4. Traditional C and Unix code used 8-space tabs. When in doubt, 4 spaces is the most widely compatible choice.

What is the difference between leading tabs only and all tabs?

Leading tabs only converts only the tab characters at the start of each line — the indentation. Tabs within the line content are left untouched. This is the correct mode for reformatting code. All tabs converts every tab character in the entire text, including those within content — useful for converting TSV data to space-separated format.

Will converting tabs to spaces break my Python code?

No — if you convert consistently with the correct number of spaces, Python code remains valid. Python 3 requires consistent indentation within a block but does not care whether you use spaces or tabs as long as you do not mix them. The tool converts all tabs to spaces throughout the file, eliminating the mixed-indentation problem.

My code uses tabs for alignment inside lines. Will conversion break that alignment?

If you use leading tabs only mode, tabs used for alignment within lines are left unchanged. If you use all tabs mode, those alignment tabs will be converted to a fixed number of spaces, which may break the visual alignment. For column alignment inside lines, consider a code formatter that understands your language semantics.

How does this compare to using IDE auto-formatting?

Most IDEs have built-in tab-to-space conversion. In VS Code, open the Command Palette and run Convert Indentation to Spaces. This tool is useful when you cannot open the code in an IDE, when working with plain text files, or when you want a visual diff to verify exactly what changed before committing.