How to use the Tab to Space Converter
Convert tab/space indentation in three steps:
1
Paste your code or text
Paste any tab-indented or space-indented code into the input area.
2
Set direction and tab width
Choose 'Tab → Space' or 'Space → Tab'. Set the tab width to 2, 4, or 8 spaces matching your project's convention.
3
Convert and copy
Click 'Convert Indentation' and copy or download the output. The language reference table shows recommended widths for common languages.
When to use this tool
Use for code formatting consistency across editors and teams:
- →Converting Python code that uses tab indentation to the PEP 8 standard 4-space indentation before submitting
- →Normalising mixed tab-and-space indentation in code before committing to a repository that enforces one style
- →Preparing code snippets for documentation, blog posts, or emails where tab rendering is inconsistent across readers
- →Converting space-indented code to tabs to match a project's tab-based indentation standard when contributing
- →Fixing indentation in code copied from a PDF or web page that converted tabs to variable numbers of spaces
- →Standardising indentation across code files from multiple contributors who use different editor settings
Frequently asked questions
Q:What tab width should I use for my programming language?
Python (PEP 8): 4 spaces — this is the official standard and enforced by most Python linters. JavaScript and TypeScript: 2 spaces — the most common convention, used by Google, Airbnb, and most major style guides. Java and C#: 4 spaces — standard in both communities. Go: 1 tab — the gofmt tool enforces tabs, not spaces. C and C++ (GNU style): 8 spaces — the traditional Unix convention. Ruby: 2 spaces. Rust: 4 spaces (rustfmt standard).
Q:Does the space-to-tab converter only affect indentation?
Yes — in 'Space → Tab' mode, only leading whitespace at the start of each line is converted to tabs. Spaces between words within a line (like 'hello world') are completely untouched. The converter identifies consecutive groups of N spaces at the start of a line (where N is the configured tab width) and replaces each group with one tab character.
Q:What happens if a line has inconsistent or partial indentation?
In 'Space → Tab' mode, the converter processes leading spaces in groups of exactly N (the tab width). If a line has a partial indent — for example, 3 spaces when the tab width is 4 — the 3 spaces are not converted and remain as spaces. Only complete groups of N leading spaces are replaced with a tab. Partial indents may occur in inconsistently formatted files, and a formatter like Prettier or Black should be used to fix those before converting.
Q:Can I use this to fix mixed tab-and-space indentation?
Yes — if your file has mixed tabs and spaces, first convert 'Tab → Space' to normalise everything to spaces, then optionally convert 'Space → Tab' if your project uses tab indentation. This two-step process ensures all indentation is consistent before you make your final choice of style.
Q:Why does tab rendering look different in different editors?
A tab character (\t, U+0009) is an instruction to advance to the next tab stop, and the tab stop width is a display setting configured per editor. VS Code defaults to 4 spaces per tab, Vim defaults to 8, GitHub renders tabs as 8 spaces, and many web browsers use 8 as well. Because of this rendering inconsistency, many teams enforce spaces over tabs to guarantee that code looks identical in every environment.
Q:Does this tool work for non-code text with tab-separated columns?
Yes — tab characters in TSV (tab-separated values) files or any tab-delimited plain text are replaced with N spaces in 'Tab → Space' mode. However, if the columns are not aligned by tab stops, the space replacement will not maintain column alignment. For aligned TSV output, use a dedicated TSV-to-CSV or table formatting tool instead.