Zero Signup ToolsFree browser tools

Text Tools

Tab to Spaces Converter

Convert tabs to spaces or spaces to tabs with column-aware tab stops. Pick 2, 4, or 8 wide tabs and fix mixed indentation in your browser.

Quick presets

One click sets the direction, scope, and tab width to match common coding-style conventions. Tweak any option below afterwards.

165 chars

1 line has mixed tabs and spaces in the indent. Keep Normalize mixed indentation on so the converter produces clean output.

Replaced 2 tab characters across 2 lines.

Input lines

12

Total number of newline-separated lines in the input.

Lines rewritten

2

Lines whose indentation changed in the output.

Mixed-indent lines (input)

1

Lines whose indent had both tabs and spaces. Usually a sign of trouble.

Mixed-indent lines (output)

0

Should be zero after a clean conversion.

Direction

Which way to convert: turn tabs into spaces, or collapse runs of spaces back into tabs.

Scope

Whether to touch every tab on every line, or only the leading whitespace at the start of each line.

Tab width

How many spaces wide a tab stop is. Tabs jump to the next column that is a multiple of this value, so this number affects exactly how many spaces each tab expands into.

between 1 and 16

Cleanup

Extra normalization the converter applies while it walks each line.

Indent preview (first 12 lines)

tab space

Each row shows the leading whitespace of a single source line as a sequence of colored squares so you can spot mixed indentation at a glance. Tabs are blue, spaces are gray, blank lines have no marks.

  • 1(no indent)
  • 2
  • 3(no indent)
  • 4(no indent)
  • 5(no indent)
  • 6
  • 7
  • 8mixed
  • 9
  • 10
  • 11(no indent)
  • 12(no indent)

How tab expansion works

  • A tab does not always expand to N spaces. It expands to the next column that is a multiple of N. So with a 4-wide tab, a tab on column 0 becomes 4 spaces, a tab on column 2 becomes 2 spaces, and a tab on column 3 becomes 1 space.
  • In Indent only mode the converter walks just the leading whitespace of each line and leaves the rest of the line alone. Tabs inside string literals, regex, comments, and any in-line alignment are preserved exactly.
  • In Whole line mode every tab is expanded, including tabs used as column separators in plain text. Pick this mode when the text is data and not code. Spaces to tabs always stays in the leading whitespace so that runs of spaces inside strings and comments are not accidentally collapsed.
  • Spaces to tabs collapses every run of 4 leading spaces into a single tab character and leaves any remainder as spaces. So with width 4 and 11 leading spaces you get 2 tabs plus 3 trailing spaces.
  • Normalize mixed indentation first turns the leading whitespace into a single column count, then rewrites it using the chosen direction. This is the safest way to deal with files where someone has hit Tab in the middle of an already-indented line.

Common style guides

  • Python (PEP 8): 4 spaces per indent. Tabs are not allowed in new code. Use the Python preset above.
  • JavaScript / TypeScript: Prettier defaults to 2 spaces. Most repo styles agree.
  • Go: gofmt uses real tab characters. Editors typically render tabs as 4 or 8 spaces wide.
  • Linux kernel: hard tabs, 8 columns wide. The most strict tab-based style.
  • Makefile:the first character of every recipe line must be a literal tab. Most "missing separator" errors come from spaces here.
  • YAML and JSON: spaces only. Tabs in YAML indentation cause a parse error.

How to use

  1. Paste a block of code, configuration, or plain text into the input area.
  2. Pick a preset (PEP 8, JS or TS, Go, Linux kernel, Makefile, YAML) or set the direction, scope, and tab width manually.
  3. Choose Indent only to limit the conversion to leading whitespace, or Whole line to expand every tab in the text.
  4. Pick a tab width from 1, 2, 3, 4, 6, or 8 spaces, or type any custom value between 1 and 16. This sets how far each tab expands.
  5. Leave Normalize mixed indentation on so lines that mix tabs and spaces get cleaned up in one pass.
  6. Read the converted result on the right and click Copy output to grab it, or Replace with output to load it back for another pass.

About this tool

Tab to Spaces Converter rewrites the indentation of a block of text, either expanding tab characters into spaces or collapsing runs of leading spaces back into tabs. Conversion is column-aware, which means a tab does not blindly become N spaces; it expands to however many spaces are needed to reach the next column that is a multiple of the chosen tab width. So with a 4-wide tab, a tab on column 0 becomes four spaces, but a tab on column 2 becomes just two spaces, which is the same behavior every code editor's Convert Indentation command uses. Two scopes are available: Indent only walks the leading whitespace of each line and leaves the rest of the line untouched, so tabs inside string literals, regex bodies, comments, and in-line alignment are preserved exactly; Whole line expands every tab character on every line and is the right choice for plain text, ASCII tables, or any data where tabs act as column separators. Six one-click presets cover the most-searched style guides: Python (PEP 8, 4 spaces), JavaScript and TypeScript (Prettier default, 2 spaces), Go (spaces back to tabs at width 4 to match gofmt), Linux kernel (spaces back to 8-wide tabs), Makefile (spaces back to tabs so recipe lines start with the required hard tab), and YAML (tabs to 2 spaces because YAML rejects tab indentation). A Normalize mixed indentation option treats any leading whitespace, even messy combinations of tabs and spaces, as a single column count and rewrites it cleanly using the chosen direction; it is the safest way to fix files where someone has hit Tab in the middle of an already-space-indented line. An indent preview card shows the first forty lines of the input as a row of colored squares (blue for tab, gray for space) so mixed indentation jumps out before you convert. A stats panel reports total input lines, lines rewritten, mixed-indent lines in the input, and mixed-indent lines in the output, so you can confirm at a glance that the cleanup worked. Useful for fixing Python PEP 8 indentation, restoring tab characters to a Makefile that lost them on copy paste, normalizing inconsistent indents across a long file before a code review, switching a JavaScript repository from tabs to two spaces or back, preparing YAML and JSON files that forbid tab indentation, and any time a code editor's built-in Convert Indentation command is not available. Everything runs locally in your browser; the code you paste is never uploaded.

Free to use. Works in your browser. No signup, no login.

Related tools

You may also like

All tools
All toolsText Tools