Tab to Space Converter
TextReplace tabs with spaces in any code or text snippet. Choose 2, 4, or 8 spaces per tab — runs entirely in your browser with no data uploaded anywhere.
What is a Tab/Space?
The Tab to Space Converter replaces every tab character in a block of code or text with a configurable number of spaces — 2, 4, or 8 — producing output with consistent space-based indentation. It is one of the most common code-cleanup operations, needed whenever code from one project or editor needs to conform to a different indentation standard.
Tab characters are invisible but consequential. In an editor set to display tabs as 4 spaces, the code looks neatly aligned. In another editor set to 8 spaces, the same file looks wildly over-indented. When the file is displayed in a terminal, a code review tool, or a web-based editor with its own tab width setting, the alignment can look completely different from what the author intended.
Replacing tabs with spaces removes this ambiguity. A file with 4-space indentation looks the same in every tool, at every font size, in every terminal — because spaces render as exactly one character-width each. This is why most modern style guides (PEP 8 for Python, the Google style guides, Airbnb's JavaScript style) mandate spaces over tabs.
All conversion runs entirely in your browser. No code or text you paste is sent to a server or stored anywhere. Use the Line Break Remover if you also need to clean up extra blank lines or normalise line endings in the same snippet.
How to use this Tab/Space calculator
- Paste your code or text into the Input Text box — any text containing tab characters (
\t) will be converted. - Choose the number of spaces to substitute for each tab from the Spaces Per Tab dropdown: 2, 4, or 8.
- The Converted Text output updates instantly as you change either the input or the spaces setting.
- Review the output to confirm the indentation looks as expected.
- Click the Copy button to copy the result and paste it back into your editor, terminal, or file.
Formula & Methodology
The conversion is a direct string replacement: every tab character (\t) in the input is replaced with the chosen number of space characters ().output = input.split('\t').join(' '.repeat(spacesPerTab))This is a non-recursive, single-pass operation — each tab is replaced exactly once, regardless of where it appears in the string. Existing space characters are untouched. Before (4 spaces per tab):function greet(name) { →console.log('Hello, ' + name); →if (name) { →→return true; →} }(where→represents a tab character) After:function greet(name) { console.log('Hello, ' + name); if (name) { return true; } }