Tabs to Spaces

Convert tabs to spaces or spaces back to tabs, respecting tab stops. Choose the tab width and whether to touch only the leading indentation. Runs in your browser; nothing is uploaded.

Try:
Converted text

About this tool

Tabs to Spaces converts the whitespace in text or code between tabs and spaces — the same job as expand/unexpand — right in your browser. A tab is never a fixed run of spaces: it advances to the next tab stop, the next column that is a multiple of the tab width, so the result stays aligned.

Each line is processed independently and existing line breaks are preserved. Everything runs locally via WebAssembly — your text is never uploaded.

Worked example

Expanding this input with tab width 4 and direction expand:

→if (ok) {
→→return 1;
→}

(where marks a tab) produces spaces to the next tab stop on each line:

    if (ok) {
        return 1;
    }

The first tab (column 0) fills 4 spaces; the doubly-indented line fills 8. A tab placed after ab (column 2) would fill only 2 spaces, because it only needs to reach column 4 — that is what "respecting tab stops" means.

Handy for

FAQ

Why doesn't every tab become the same number of spaces?

Because a tab advances to the next tab stop, not a fixed count. At tab width 4, a tab at column 0 becomes 4 spaces, but a tab after ab (column 2) becomes only 2 spaces — both land on column 4. This keeps columns aligned exactly the way an editor with the same tab width would show them.

What does "leading indentation only" change?

With scope set to leading, only the whitespace before the first non-blank character on each line is converted; any tabs or spaces later in the line are left exactly as they are. Use it to re-indent code without disturbing aligned comments or tab-separated data further along the line.

Does unexpand turn single spaces into tabs?

No. When converting spaces → tabs, a tab is only used when it lands on a tab stop and replaces two or more columns. A single leftover space (or a lone space before a stop) stays a space, so unexpand never mangles ordinary word spacing — only genuine indentation runs collapse into tabs.

Are my line breaks and non-whitespace characters preserved?

Yes. Every line is processed independently, and line breaks are kept exactly as in the input. Only tabs and spaces are rewritten; all other characters pass through unchanged.

Limits & edge cases

Developer & Automation Access

Run it from the terminal

Same engine as this page, headless — via the gizza CLI:

gizza tool tabs-to-spaces "Paste text or code to convert…"

New to the CLI? Get gizza →

Open it by URL

Pre-fill and auto-run this tool with query parameters — the names match the API/CLI:

https://gizza.ai/tools/tabs-to-spaces/?text=Paste%20text%20or%20code%20to%20convert%E2%80%A6&direction=expand&tab_width=4&scope=all

Machine-readable descriptor: tool.json — title + parameters JSON Schema for agents.