Zero Signup ToolsFree browser tools

Developer Tools

Tabs to Spaces Converter

Convert tabs to spaces or spaces to tabs in your browser with correct tab-stop math, adjustable tab width, and a leading-indentation-only mode.

Tabs to spaces converter

Tab width

Scope

Only the whitespace at the start of each line is converted. Tabs and spaces inside the line (string literals, aligned comments, data) are left untouched.

Paste code or text with tabs or spaces.

6 lines · 5 tabs · 10 spaces · LF (Unix)

0 tabs · 30 spaces in output

Why tab stops matter

A tab is not a fixed number of spaces. It moves the cursor to the next tab stop, which is the next column that is a multiple of the tab width. With a width of 4, a tab at column 0 expands to 4 spaces, but a tab at column 2 expands to only 2 spaces so the text still lands on column 4. A naive find and replace of every tab with 4 spaces breaks this alignment. This converter uses the same tab-stop math as the Unix expand and unexpand commands and your code editor.

Common uses

  • Convert tab-indented code to spaces for a project whose style guide requires spaces (PEP 8 for Python, many JavaScript and Go house styles).
  • Fix a snippet pasted from a chat, an issue tracker, or a PDF that arrived with mixed tabs and spaces.
  • Re-indent YAML, where tabs are illegal and indentation must be spaces.
  • Collapse leading spaces back to tabs for files that should stay tab-indented (Makefiles require tabs).
  • Normalize indentation before a diff so whitespace-only changes do not show up in the review.

How to use

  1. Paste your code or text into the input box, or press Load sample to try a worked example.
  2. Choose the direction: Tabs to spaces expands tabs, Spaces to tabs collapses spaces back to tabs.
  3. Pick the tab width (2, 3, 4, or 8 spaces per tab stop) so the math matches your editor.
  4. Leave Convert leading indentation only on to re-indent without touching tabs and spaces inside lines, or turn it off to convert the whole line.
  5. Read the converted result on the right. The status line reports the tab and space counts and warns when nothing changed.
  6. Press Copy to grab the output, or Use as input to chain another conversion. Line endings are preserved automatically.

About this tool

Tabs to Spaces Converter changes the indentation of code or text between tab characters and spaces in both directions, using the same tab-stop math that code editors and the Unix expand and unexpand commands use. This matters because a tab is not a fixed run of spaces. A tab moves the cursor to the next tab stop, the next column that is a multiple of the chosen tab width, so with a width of four a tab at column zero expands to four spaces but a tab already sitting at column two expands to only two spaces, keeping the following text aligned on column four. A naive find and replace of every tab with four spaces ignores this and silently shifts anything that was not at column zero, which is why a dedicated converter is worth using instead of a blanket replace. You pick the direction (tabs to spaces, or spaces to tabs), the tab width (two, three, four, or eight spaces per stop), and whether to convert only the leading indentation at the start of each line or every tab and space run on the line. Leading-only mode is on by default and is what you usually want: it re-indents the code while leaving tabs and spaces inside the line alone, so tabs inside string literals, aligned trailing comments, or pasted tabular data are not disturbed. Turning leading-only off converts the whole line, matching plain expand and unexpand. The tool detects and preserves the original line endings, whether the file uses LF on Unix and macOS, CRLF on Windows, or bare CR, so converting indentation does not quietly rewrite the newlines, and a trailing newline is kept if the input had one. A live count shows the lines, tabs, and spaces in both the input and the output and the detected line ending, and it tells you when the input already matches the selected output so you do not copy a no-op. Typical uses include converting tab-indented code to spaces to satisfy a style guide such as PEP 8 for Python, fixing a snippet that arrived from a chat window or an issue tracker with mixed tabs and spaces, re-indenting YAML where tabs are not allowed, collapsing spaces back to tabs for files such as Makefiles that require tabs, and normalizing indentation before a diff so whitespace-only noise stays out of the review. Everything runs locally in your browser. The text you paste is never uploaded, logged, or stored.

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

Related tools

You may also like

All tools
All toolsDeveloper Tools