Convert Between Tab and Space Indentation Cleanly
Tabs versus spaces is the longest-running argument in programming, and mixed indentation is its ugly byproduct: code that looks aligned in one editor and staircased in another, Python that refuses to run, diffs cluttered with whitespace-only changes. Whatever side you are on, files must be internally consistent and match the project's convention. This free converter rewrites indentation in either direction — tabs to spaces or spaces to tabs — at a width of 2, 4, or 8 spaces per tab, processing the leading whitespace of every line in one pass. It runs instantly and entirely in your browser.
Tabs to Spaces
Converting tabs to spaces replaces each leading tab with the chosen number of space characters, producing indentation that renders identically everywhere — editors, terminals, web pages, diffs, and printouts. Spaces are the dominant convention in most modern style guides, including PEP 8 for Python at four spaces and many JavaScript configs at two. Run code through this direction before sharing it in contexts that mangle tabs, such as chat tools, web forms, and email.
Spaces to Tabs
The reverse direction groups leading spaces into tabs at the width you specify: with four selected, every four leading spaces become one tab, and leftover spaces that do not complete a group are preserved after the tabs to keep alignment intact. Tabs keep files slightly smaller and let every reader choose their own display width — the core argument of the tab convention, used by Go's gofmt among others. Use this direction when contributing to projects whose style mandates tabs.
Fixing Mixed Indentation
Files edited by different people in different editors accumulate both kinds of whitespace, and the result misaligns the moment tab width assumptions differ. Python raises errors outright when tabs and spaces mix inconsistently; YAML forbids tabs entirely. The cure is normalization: convert the whole file to one convention in a single pass. Converting tabs to spaces is the safest normalizer, since the output contains no tabs at all and renders the same regardless of editor settings.
Choosing the Right Width
The width setting defines the exchange rate between one tab and its space equivalent. Four is the most common default across languages and editors. Two is standard in JavaScript, JSON, YAML, and HTML, where nesting runs deep and narrow indents keep lines short. Eight matches traditional terminal tab stops and some legacy codebases. Match the width to the project's existing convention — converting at the wrong width changes the visual nesting depth even though the structure is preserved.
What the Converter Does Not Touch
Only leading whitespace — the indentation — is converted. Tabs and runs of spaces inside a line, such as those aligning inline comments or separating columns in data, are left exactly as written, because rewriting them would shift content alignment unpredictably. Line breaks and blank lines pass through unchanged. The output is your text with identical structure and content, differing only in what the indentation is made of.
Privacy and Client-Side Processing
Conversion runs locally in your browser with JavaScript; the code or text is never uploaded, stored, or logged. Proprietary source files and internal documents are safe to process here. The output statistics report the number of lines converted, and everything is cleared from memory when you close the page.