Why do tabs vs spaces matter in code?

Tabs and spaces are the two primary methods for indenting source code, and mixing them is one of the most common causes of formatting inconsistencies across projects. Different editors display tab characters at varying widths — some show them as 2 spaces, others as 4 or 8 — which means code that looks perfectly aligned on one machine may appear broken on another. Spaces, on the other hand, render identically everywhere but take up more bytes and require multiple keystrokes without editor support.

Most modern style guides and linters enforce a single indentation style. Languages like Python are whitespace-sensitive and can throw errors when tabs and spaces are mixed within the same block. Configuration files such as YAML and Makefiles also have strict whitespace rules that make choosing the right character essential.

Tool description

This tool converts between tabs and spaces in any text or code snippet. Paste or type content with tab-based indentation to replace every tab with a configurable number of spaces, or convert space-based indentation back into tabs. Both the input and output use a code editor with visible whitespace rendering, so you can immediately see dots for spaces and arrows for tabs.

Examples

Tabs to spaces (4 spaces per tab):

Input:

function greet() {
→   const name = "World";
→   console.log(`Hello, ${name}`);
}

Output:

function greet() {
    const name = "World";
    console.log(`Hello, ${name}`);
}

Spaces to tabs (2 spaces per tab):

Input:

def greet():
  name = "World"
  print(f"Hello, {name}")

Output:

def greet():
→ name = "World"
→ print(f"Hello, {name}")

Features

  • Bidirectional conversion between tabs and spaces
  • Configurable number of spaces per tab (1–32)
  • Code editor with syntax-highlighted invisible characters (dots for spaces, arrows for tabs)
  • Instant real-time conversion as you type
  • Works with any programming language or plain text

Use cases

  • Reformatting code to match a project's .editorconfig or linter rules before committing
  • Converting legacy codebases that use tabs to a spaces-based standard (or vice versa)
  • Cleaning up copy-pasted code from Stack Overflow or documentation that uses inconsistent indentation

Options explained

Option Description
Spaces per tab Sets how many space characters represent a single tab. Common values are 2 (Ruby, JS) and 4 (Python, Java). Accepts any value from 1 to 32.
Direction dropdown Choose "Tabs" → "Spaces" or swap to "Spaces" → "Tabs" using the swap button.

Tips

  • Use the invisible character rendering in the editor to verify your input actually contains tabs before converting — many editors silently replace tabs with spaces on paste.
  • When converting spaces to tabs, ensure your space count setting matches the original indentation width, otherwise partial indentation may remain.