Convert Tabs to Spaces Online
Updated: May 2026
Tab characters and spaces are both whitespace, but they behave very differently across editors, terminal emulators, web renderers, and file formats. Converting tabs to spaces standardizes indentation and ensures your text looks the same everywhere it is displayed or processed.
Free · 2, 4 or 8 spaces per tab · No upload
Why tabs and spaces conflict
A tab character (ASCII 0x09) renders at a variable width depending on the tab-stop settings of the rendering environment. In most terminal emulators, a tab advances to the next multiple of 8. In most code editors, the default tab width is 4. In HTML, a tab inside a pre element renders as 8 spaces by default. This variability means that a document indented with tabs can look correct in one environment and misaligned in another.
Spaces, by contrast, occupy a fixed width defined by the font. A document indented with spaces looks identical everywhere — in terminals, browsers, email clients, and PDF renderers. This predictability is why many style guides and linters enforce spaces-only indentation for projects that produce output read by multiple tools.
Python's indentation rules make this concrete: mixing tabs and spaces in the same block is a SyntaxError in Python 3. If you are cleaning Python code copied from an environment that uses tabs, convert them to spaces at the correct width before pasting.
Choosing the right tab width
The tab width you choose should match the indentation convention of the target format or project style guide.
- 2 spaces — common in JavaScript (especially with Prettier defaults), HTML, CSS, and Ruby projects. Keeps code compact on narrow screens.
- 4 spaces — the default for Python (PEP 8), C#, Java, and most legacy codebases. Balances readability and density.
- 8 spaces — traditional Unix convention. Still used in some kernel and systems programming contexts. Makes deep nesting very visible — and painful — by design.
For plain prose documents, CSV data, and configuration files that don't use indentation as syntax, the tab width choice has no functional significance — convert to whichever looks cleanest in your target editor.
Formats where tab conversion matters most
- Python — Python 3 forbids mixed indentation. Converting tabs to 4 spaces is required for code that will be run.
- YAML — the YAML specification forbids tab indentation entirely. YAML blocks indented with tabs will fail to parse. Convert to spaces before using any YAML validator or Kubernetes/Docker manifest.
- Markdown inside code blocks — fenced code blocks preserve whitespace. A tab renders as 8 spaces in some Markdown renderers and as 4 in others, making examples look inconsistent across platforms.
- HTML pre and code elements — browsers render tabs in pre elements at 8-space width by default. Converting to 4 spaces gives predictable results without CSS tab-size overrides.
- CSV from spreadsheets — Excel sometimes uses tabs as column delimiters in .txt exports. If you are processing tab-delimited data as plain text, converting tabs to spaces (or keeping them as delimiters) depends on the intended use.
Frequently asked questions
Does converting tabs to spaces change the meaning of my code?
For most languages, no — the indentation structure is preserved. For YAML (which forbids tabs) and Python (which is indentation-sensitive), converting to the correct number of spaces is necessary for the code to function correctly.
What width should I use for Python files?
Use 4 spaces per tab to match PEP 8, the official Python style guide. Most Python linters and IDEs default to 4-space indentation.
Can I convert spaces back to tabs?
Not with this tool — it converts tabs to spaces only. For spaces-to-tabs conversion, use your code editor's format settings or a dedicated command-line tool like unexpand on Unix.