Free Tabs to Spaces Converter

Free tabs to spaces converter. Expand tabs to 2, 4 or 8 spaces using real tab stops, or convert spaces back to tabs, for whole lines or indentation only.

  • No upload, 100% private
  • Instant, in your browser
  • 100% free, no signup
Loading tool…
Read the complete guideTabs vs Spaces: How Tab Stops Work and How to Convert Between Them →

About the Tabs to Spaces Converter tool

Tabs versus spaces is an old debate, but in practice you often just need to match the rest of a codebase, satisfy a linter or make text line up in a place that renders tabs differently. Replacing every tab with a fixed number of spaces is not quite right, because a tab jumps to the next tab stop: "ab" followed by a tab only needs two more spaces to reach column 4.

This converter expands tabs using real tab stops, so columns in tab-aligned text keep lining up after conversion. Choose a tab width of 2, 3, 4 or 8. In the other direction, Spaces → Tabs works like the Unix unexpand command: runs of two or more spaces that end on a tab stop become tabs, and single spaces between words stay as they are.

Switch on "Leading indentation only" to change only the indentation at the start of each line while leaving tabs or spaces inside strings, comments and tables untouched. That is the safe choice for source code. The counter shows how many tabs were expanded or inserted, and the conversion happens entirely in your browser.

How to use Tabs to Spaces Converter

  1. Paste code or text into the “Input” box, or click “Sample”.
  2. Choose “Tabs → Spaces” or “Spaces → Tabs” under “Direction”.
  3. Pick the “Tab width” that your editor or style guide uses.
  4. Turn on “Leading indentation only” to convert just the indentation.
  5. Copy the result or download it.

Features

True tab stops

Tabs expand to the next multiple of the tab width, preserving column alignment.

Both directions

Convert tabs to spaces or spaces back to tabs, like expand and unexpand.

Indentation-only mode

Change only leading whitespace and leave the rest of each line alone.

Common widths

2, 3, 4 or 8 spaces per tab.

Conversion count

Shows how many tabs were expanded or inserted.

When to use it

  • Convert tab-indented code to 2 or 4 spaces to match a project's style guide.
  • Re-indent a Python or YAML snippet where mixed tabs and spaces cause errors.
  • Turn tab-separated data into space-aligned text for an email or README.
  • Convert space indentation back to tabs for a Makefile or Go code.

Frequently asked questions

How many spaces is a tab?

There is no fixed answer. Many editors default to 4, the Linux kernel and Go use 8-column tabs, and JavaScript projects commonly use 2 spaces. Pick the width your project uses.

Why not just replace each tab with 4 spaces?

A tab moves to the next tab stop, not a fixed distance. Replacing blindly breaks alignment when text precedes the tab. This tool calculates the correct number of spaces per tab.

Is converting spaces to tabs safe for code?

Use “Leading indentation only” for code. Converting spaces inside lines could change string literals or alignment in comments.

Why do Makefiles need tabs?

Make requires recipe lines to start with a real tab character. If an editor converted them to spaces you will see “missing separator” errors; convert the indentation back to tabs here.

Related tools