How to use the Space to Tab Converter
Convert space indentation to tabs in three steps:
1
Paste your space-indented code
Paste any code or text with space-based indentation into the input area.
2
Set the space width
Set how many spaces equal one tab (2, 4, or 8). This must match the indentation width used in your source code.
3
Convert and copy
Click 'Convert Indentation' and copy or download the tab-indented output.
When to use this tool
Use to convert space-indented code to tab indentation:
- →Converting space-indented code to tab indentation to match a project's tab-based coding standard when contributing
- →Normalising code from multiple contributors who use spaces to the repository's enforced tab indentation style
- →Reducing file size slightly in large codebases by replacing N space characters per indent level with a single tab character
- →Preparing code for editors configured to display tabs so indentation renders at the editor's configured tab width
- →Converting Python or JavaScript code from space to tab indentation when switching to a tab-standard project
- →Restoring tab indentation to code that was incorrectly converted to spaces by an editor or paste operation
Frequently asked questions
Q:Does it only convert leading spaces (indentation) or all spaces?
Only leading whitespace (indentation at the start of each line) is converted to tabs. Spaces between words and tokens within a line — like the spaces in 'const x = 5' or 'print(hello world)' — are completely untouched. This is the correct behaviour for indentation conversion and prevents the destruction of in-line spacing.
Q:How do I know what space width to set?
The space width must match the indentation unit used in your source code. If your code uses 4 spaces per indentation level, set the width to 4. If it uses 2 spaces, set to 2. If you are unsure, look at the leading spaces on any indented line and count how many spaces make up the first indent level. Setting the wrong width produces incorrect tab stops.
Q:What happens with partial or inconsistent indentation?
The converter replaces leading spaces in complete groups of N. A line indented with 7 spaces when the tab width is 4 would have one complete group (4 spaces → 1 tab) converted and 3 remaining spaces left as-is. Inconsistent indentation may produce mixed tab-and-space results. Run a code formatter like Prettier, Black, or gofmt to normalise indentation before converting.
Q:Is space-to-tab conversion reversible?
Yes — converting the tab-indented output back using the Tab → Space mode with the same tab width restores the original space indentation exactly. The two conversions are inverses of each other when applied consistently with the same tab width setting.
Q:Which editors and languages enforce tab indentation?
Go is the most prominent language that mandates tab indentation — the official gofmt formatter uses tabs and this is non-negotiable. Makefile syntax requires tab indentation for recipe lines (spaces cause syntax errors). Some teams using Vim, Emacs, or older Unix editors also prefer tabs. Most modern editors (VS Code, JetBrains IDEs) can display either style at any visual width.
Q:Should I use tabs or spaces?
The tabs-vs-spaces debate has no universal answer — what matters is consistency within a project. Follow your project's .editorconfig, ESLint, Prettier, or style guide settings. Python's PEP 8 explicitly requires spaces (4 per level). Go's gofmt explicitly requires tabs. For JavaScript and TypeScript, Prettier defaults to 2 spaces but can be configured. Use this tool to convert whichever way your project requires.