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.
Reviewed by the thecalcu.com team · Last updated June 23, 2026
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.
Why Use a Tab to Space Converter?
The most common scenario is contributing to a project with a different indentation style than the one you normally use. If your editor inserts hard tabs and the project enforces spaces via a linter or .editorconfig, every file you submit will fail the style check. Running your code through the converter before committing resolves the issue instantly.
A second common scenario is pasting code from an external source, Stack Overflow, a documentation page, a colleague's email, where tab characters may have been preserved from the original. These tabs can cause Python indentation errors or break the visual alignment of the surrounding code.
Data analysts encounter the same issue when opening TSV or log files in text editors: tab characters that were meant as column separators produce unexpected visual indentation when the file is viewed as code rather than data.
Who Should Use This Formatter?
Developers switching between projects with different indentation conventions, tabs in one, spaces in another, need a quick way to normalise snippets they copy across projects. The Tab to Space Converter is faster than configuring your editor's re-indentation command for a one-off snippet.
Open-source contributors submitting code to projects that enforce PEP 8, Google style, or Prettier will find this tool useful for cleaning up snippets before creating a pull request, particularly when the contribution is a small patch copied from a personal project with different settings.
Students and learners copying code examples from textbooks or PDFs, where the PDF-to-text conversion may have introduced tab characters, can use this formatter to clean up examples before running them. Combine it with the JSON Formatter when working with data examples.
Technical writers producing code samples for documentation need consistent space-based indentation so that code blocks render identically in Markdown, HTML, and publishing platforms, none of which respect tab-width settings.
What Insights Does the Tab to Space Converter Give You?
The output directly reflects the indentation depth of the original code. Selecting 8 spaces per tab makes deeply nested code visually obvious, blocks indented 4 levels wide become 32 spaces and stand out immediately as candidates for refactoring. Selecting 2 spaces per tab is useful for compacting deeply nested code for display in a narrow column, such as a blog post or documentation sidebar.
| Spaces per tab | Typical use |
|---|---|
| 2 | JavaScript/TypeScript (Airbnb, Google style), YAML, HTML templates |
| 4 | Python (PEP 8), Java, C#, PHP |
| 8 | Traditional Unix C code, GNU project style, some shell scripts |
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; } }
Frequently Asked Questions