Indent Converter — Tabs ↔ Spaces

Convert leading indentation between tabs and spaces. Only leading whitespace is changed — your code content is untouched.

Input
Output
Paste code above to convert indentation.

How to Use the Indent Converter

  1. Choose a conversion mode — tabs to 2 spaces, tabs to 4 spaces, spaces to tabs, or custom.
  2. Paste your code — the output updates immediately as you type.
  3. Check the status bar — it shows how many lines were changed.
  4. Copy or download — grab the converted code with one click.

Tabs vs. Spaces: The Eternal Debate

The choice between tabs and spaces for code indentation is one of the longest-running debates in software development. Both approaches have legitimate advantages, and the right answer often depends on your team, language, and tooling conventions.

Arguments for Spaces

Spaces render identically in every editor, terminal, and code review tool regardless of configuration. When you share code on GitHub, in Slack, or in a terminal, space-indented code always looks exactly as intended. Most popular style guides — including Google's style guides for JavaScript, Python (PEP 8), and Java — specify spaces. The dominant JavaScript ecosystem tools (Prettier, ESLint) default to spaces. Two spaces is conventional in JavaScript/TypeScript (React, Node.js, Vue), while four spaces is the standard in Python, PHP, and Java.

Arguments for Tabs

Tabs are semantically correct: a tab character represents one level of indentation. Developers can set their editor to display tabs as 2, 4, or 8 columns wide according to personal preference. This is especially valuable for accessibility — developers with visual impairments sometimes prefer wider indentation that tabs make easy to configure. Go enforces tabs via gofmt, and the Linux kernel uses tabs. Tabs can also result in smaller file sizes for heavily indented code.

How the Converter Works

This tool processes each line of your code and looks at the leading whitespace only. For tabs-to-spaces conversion, each leading tab character is replaced by the specified number of spaces. For spaces-to-tabs conversion, leading groups of N spaces are replaced by a single tab. Non-leading whitespace — spaces inside strings, between tokens, in comments — is left completely unchanged. This means the conversion is safe for code in any language and will not alter your logic or string values.

Fixing Mixed Indentation

Mixed indentation (some lines using tabs, others using spaces) causes subtle bugs in Python (which treats tabs and spaces as different indentation levels) and creates inconsistent visual appearance in all languages. The recommended fix is to first convert everything to tabs, then convert back to your target space width. This two-pass approach normalizes all indentation levels correctly regardless of how mixed the original was. After normalizing, run your formatter (Prettier, Black, gofmt) to apply any remaining style rules.

Editor Integration

Most modern editors handle this automatically. In VS Code, set editor.tabSize and editor.insertSpaces in settings.json. Use the "Convert Indentation to Spaces" or "Convert Indentation to Tabs" commands from the command palette. In Vim, use :set expandtab for spaces or :set noexpandtab for tabs, then run :retab to reformat the buffer. For project-level consistency, use an .editorconfig file that all modern editors respect. See related tools: Code Line Counter, Diff Checker.

Frequently Asked Questions

Both have merits. Spaces produce consistent visual output across all editors. Tabs allow developers to set their preferred visual width. Most modern style guides (Google, Airbnb, PEP 8) prefer spaces. Python requires consistent indentation and most Pythonistas use 4 spaces. Go uses tabs by convention enforced by gofmt.
No. This indent converter only replaces leading whitespace at the beginning of each line. Whitespace in the middle or end of lines is left completely unchanged. Your strings, comments, and inline spacing are preserved exactly.
The Custom mode lets you specify any number of spaces per indent level. For example, if your code uses 3-space indentation you can set the custom size to 3 and convert to tabs or to a different number of spaces.
Yes. First convert to tabs (which collapses all space-based indentation), then convert back to your preferred space width. This two-step process normalizes mixed indentation into a consistent style.
No. The indent converter runs 100% in your browser. Your code never leaves your machine. There is no server, no logging, and no data collection.