TextToolboxTextToolbox
Home/Text Cleaners & Modifiers/Convert Tabs/Spaces

Convert Tabs/Spaces

Convert code indentation between tabs and spaces in both directions. Choose 2, 4, 6, or 8 spaces per tab — great for Python, JavaScript, and any language style guide.

Conversion Options

Direction

Spaces Per Tab

Each \t will become 4 spaces

Input Code / Text

|

Converted Output

What Is the Convert Tabs/Spaces Tool?

The Convert Tabs/Spaces tool solves the classic developer indentation debate by converting between tab characters and spaces in any direction. Paste code that uses tabs and convert to 2, 4, 6, or 8 spaces — or go the other way and consolidate leading spaces back into tabs. Works with code in any language and runs entirely in your browser with zero setup.

How to Convert Tabs to Spaces

  1. Choose direction — Tabs → Spaces or Spaces → Tabs.
  2. Set spaces per tab — 2 (popular in JavaScript/TypeScript), 4 (Python, Java, C#), or match your editor settings.
  3. Paste your code into the input box or click Sample to load an example.
  4. Copy or Download the converted code.

Where Can You Use Tab/Space Conversion?

Python Compatibility

Python raises IndentationError on mixed tabs and spaces. Convert all indentation to spaces before running or submitting Python code.

Team Style Guides

Match your project's .editorconfig or ESLint/Prettier settings — convert code before committing to a repo that enforces a specific indentation style.

Code Reviews on GitHub

GitHub renders tabs as 8 spaces, making tab-indented code look unwieldy in PR diffs. Convert to 2 or 4 spaces before sharing a review link.

IDE Migration

Moving from a tab-based editor (Vim default) to a space-based one (VS Code default)? Convert your existing files to match the new environment.

Tabs vs Spaces — When to Use Each

  • Use tabs when collaborating with teams whose editors use different visual indent widths. Tabs let each developer see their preferred width without changing the file.
  • Use spaces when working with Python (which raises errors on mixed indentation), or contributing to open-source projects that enforce spaces in their style guide.
  • 2 spaces — Standard in JavaScript, TypeScript, JSON, Ruby, and most modern web projects.
  • 4 spaces — Standard in Python (PEP 8), Java, C#, and most backend languages.
  • 8 spaces / 1 tab — Traditional Unix/Linux kernel style; rarely used in modern projects.

Best Practices and Limitations

Always check your project's .editorconfig, .eslintrc, or Prettier config before converting — using the wrong space count will still fail linting even after conversion. If a file has mixed tabs and spaces, convert to spaces first to normalize everything, then convert to tabs if needed — never run Spaces → Tabs on a mixed file.

Limitations: The Spaces → Tabs direction only replaces leading indentation spaces — mid-line spaces (alignment in multi-line objects, table formatting) are intentionally left as spaces. This is correct behavior: only indentation should be tabs, never alignment. Tab characters appearing mid-line in the Tabs → Spaces direction are also converted, which may affect intentional tab-separated data — use a dedicated CSV tool for tabular data.

Share This Tool

End the tabs vs spaces debate — share this free indentation converter with your dev team!

Frequently Asked Questions

Which languages use spaces and which use tabs?+

Python's style guide (PEP 8) requires spaces. JavaScript and TypeScript projects usually use 2 spaces. Go's gofmt tool mandates tabs. Always check your project's .editorconfig or linter config.

What space width should I use?+

2 spaces is standard in JavaScript, TypeScript, JSON, and Ruby. 4 spaces is common in Python, Java, C#, and PHP. Use the setting that matches your project style guide.

Does Spaces to Tabs convert all spaces or just leading indentation?+

Only leading indentation is converted. Mid-line spaces used for alignment are intentionally preserved as spaces to prevent corrupting code that relies on space alignment.

What happens with mixed indentation (some tabs, some spaces)?+

To fix mixed indentation: first run Tabs to Spaces to normalize everything, then convert to tabs if desired. Never do a single Spaces to Tabs pass on a mixed file.

Will this change tabs inside strings or comments?+

The Tabs to Spaces mode replaces ALL tab characters including those inside strings and comments. Be careful with code where literal tab characters inside strings are intentional.