Tab to Space Converter

Convert tabs to spaces and spaces to tabs online. Choose 2, 4, or 8 spaces per tab. Free indentation converter for code and text.

๐Ÿ”’ Your text stays in your browser - nothing is sent to our servers
Spaces per tab:
Input
Output
How to Use

Three steps to get started

1

Choose direction

Select "Tabs โ†’ Spaces" or "Spaces โ†’ Tabs" to set the conversion direction.

2

Set spaces per tab

Choose 2, 4, or 8 spaces per tab to match your project's coding style.

3

Paste and copy

Paste your code into the input field and copy the converted output instantly.

About This Tool

Why indentation consistency matters

A tab is a single control character (U+0009, written\t) that instructs the display to advance to the next tab stop, while indenting with spaces writes a fixed number of literal space characters (U+0020). The distinction matters because a tab has no intrinsic width - it is a request, rendered as 8 columns in a POSIX terminal, 4 in Visual Studio, and whatever the editor is configured for elsewhere. Spaces have exactly one width everywhere.

That is the whole tabs-versus-spaces argument in a sentence. Spaces guarantee the file looks identical to everyone; tabs are one byte instead of two to eight and let each developer choose their own visual width, which is the accessibility argument - a reader who needs wide indentation can get it without reformatting the file.

The languages have largely settled it for you. Python's PEP 8 specifies four spaces and Python 3 refuses to run a file mixing tabs and spaces inconsistently, raising TabError: inconsistent use of tabs and spaces in indentation. YAML forbids tabs for indentation outright at the spec level. Go went the other way:gofmt emits tabs and there is no option to change it. Makefiles are the strictest of all - a recipe line must begin with a real tab character, and pasting spaces there produces the notoriousmissing separator error.

Common use cases

  • Pasting code from Stack Overflow or a PDF - copied snippets routinely arrive with mixed or converted indentation
  • Migrating between editors - VS Code inserts spaces by default via editor.insertSpaces, while a stock Vim inserts real tabs until expandtab is set
  • Normalizing before a formatter run - cleaning input for Prettier, Black, or clang-format so the diff stays readable
  • YAML and JSON editing - Kubernetes manifests, GitHub Actions workflows, and Docker Compose files all reject tabs
  • Meeting a linter rule - ESLint's indent, Rubocop, and gofmt -l checks in CI

Picking a width, and one thing to watch

Two spaces is conventional for JavaScript, TypeScript, JSON, YAML, and Ruby; four for Python, Java, C#, PHP, and Rust; eight for Linux kernel C, where the kernel coding style argues that deep indentation should hurt enough to discourage it. If the project has an .editorconfig, itsindent_style and indent_size keys are the authoritative answer.

The gotcha to watch is alignment versus indentation. Spaces used to line up continuation arguments under an opening parenthesis are not structural indentation, and converting them to tabs will scramble that alignment for anyone whose tab width differs from yours. This is why some codebases adopt the hybrid rule "tabs for indentation, spaces for alignment". Converting tabs to spaces is always safe; the reverse direction deserves a review of the diff.

The conversion runs entirely in your browser - no code is uploaded, and the page keeps working after you go offline, which makes it usable on proprietary source.

FAQ

Frequently Asked Questions

Related Tools