A tabs to spaces converter standardizes code indentation by converting tab characters to spaces or vice versa. Set your preferred tab width (2, 4, or 8 spaces) and convert entire files in one step without a code editor.
Settings
Input
Output
Whitespace Preview (· = space, → = tab)
How to Convert Tabs to Spaces
Inconsistent indentation is one of the most common code formatting issues. This tool converts your code's tab characters to spaces (or spaces to tabs) in one step, without needing a code editor or linter setup.
Step 1: Choose direction and width
Select "Tabs to Spaces" or "Spaces to Tabs" using the toggle. Set the tab width using the slider — 2 is common for web development (JavaScript, CSS, HTML), 4 is standard for Python and Java, and 8 is traditional in older C code. The width determines how many space characters replace each tab, or how many spaces are grouped into one tab.
Step 2: Paste your code and convert
Paste the code or text with the original indentation and click Convert. The output area shows the converted version ready to copy. Tabs to Spaces converts every tab character in the text. Spaces to Tabs only converts leading whitespace (indentation) to preserve alignment in the middle of lines.
Step 3: Verify with whitespace preview
Enable "Show whitespace preview" to see a visual representation of the output. Spaces appear as middle dots (·) and tabs appear as blue arrows (→). This makes it easy to confirm the conversion was correct before copying.
Why standardize indentation
Python throws IndentationError when tabs and spaces are mixed. ESLint and Prettier enforce one style and fail builds when violated. Git diffs become harder to read with mixed indentation. Running this converter before committing catches these issues and keeps your diff clean.
FAQ
What tab width should I use?
The most common settings are 2 spaces (JavaScript, YAML, Ruby), 4 spaces (Python, PHP, Java), or 8 spaces (legacy C code). Match the convention used in your project's linting config or style guide.
Can I convert spaces back to tabs?
Yes. Toggle to 'Spaces to Tabs' mode and set the number of spaces per tab. The tool replaces leading spaces at the start of each line (indentation) with tab characters.
Does it only convert leading indentation or all tabs/spaces?
In 'Tabs to Spaces' mode, all tab characters in the text are replaced — not just leading ones. In 'Spaces to Tabs' mode, only leading whitespace (indentation) is converted to preserve alignment in the middle of lines.
What is the visual whitespace toggle?
The 'Show whitespace' toggle displays dots for spaces and arrows (→) for tab characters in a preview panel. This helps you verify the conversion worked correctly when the characters look similar.
Is this tool free?
Yes, completely free. All processing is done in your browser — no code is sent to any server.
Can it handle mixed tabs and spaces?
Yes. In 'Tabs to Spaces' mode, it converts every tab regardless of surrounding context. This standardizes files that mix both styles.
Why does indentation style matter?
Python is sensitive to consistent indentation — mixing tabs and spaces causes syntax errors. Most linters enforce one style. GitHub diffs display mixed files inconsistently. Standardizing indentation before committing prevents these issues.