Skip to content

Text Indent Converter

Convert tabs to spaces or spaces to tabs at the indent width you choose

0 lines · 0 characters

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.

$ faq

How do I convert tabs to spaces?
Paste the text or code, choose Tabs to Spaces and a width of 2, 4, or 8, and click Convert Indentation. Each leading tab becomes that many spaces, and the result is ready to copy or download.
How does spaces to tabs handle leftover spaces?
Leading spaces are grouped into tabs at the chosen width, and any remainder that does not complete a full group is kept as spaces after the tabs, so the visual alignment of the line is preserved.
Does the converter change whitespace inside lines?
No. Only leading indentation is converted. Tabs and spaces within a line — aligned comments, column gaps — are left untouched to avoid shifting content alignment.
What width should I use?
Match the project's convention: four spaces is the broad default and the PEP 8 standard, two is common in JavaScript, JSON, YAML, and HTML, and eight matches traditional terminal tab stops.
Why does Python complain about my indentation?
Python rejects inconsistent mixing of tabs and spaces in the same block. Normalize the file by converting everything to spaces in one pass, which removes tabs entirely and resolves the error.
Will the conversion change how my code works?
Structure and content are preserved; only the composition of leading whitespace changes. In indentation-sensitive languages like Python and YAML, normalizing to a single convention makes behavior more predictable, not less.
Is my code private when using this tool?
Yes. The conversion runs client-side in your browser; nothing is uploaded or stored. Proprietary code is safe, and the text is cleared from memory when the page closes.