Spaces to tabs converter

Replace runs of spaces with tab characters. Convert only the indentation at the start of each line, or every run of spaces, at a width of 2, 4 or 8. The conversion happens in your browser and nothing is uploaded.

Spaces per tab

How it works

  1. Paste your text

    Type or paste the text in the left box, or open a .txt file. No text to hand? Click Example.

  2. Instant result

    The result appears as you type. Change the options and see straight away what changes.

  3. Copy or download

    Copy the result with one click, save it as a file or use it as input for a next step.

Example

function hello() {
    if (true) {
        return 1;
    }
}

with indentation of four spaces becomes the same code with one tab for the first level and two tabs for the second. The note reports how many tabs were made, here 4.

Indentation or the whole text

By default only the indentation is converted, which is what you want for code. Untick Only indentation at the start of a line to turn runs of spaces that fall on a tab stop into tabs anywhere in the line, for example in aligned columns.

Files that need tabs

Makefiles require tab characters before recipe lines, and Go's formatter indents with tabs. Pasted code often arrives with spaces, and one pass here fixes it. For the opposite, use tabs to spaces; to remove stray extra spaces first, use remove double spaces.

Frequently asked questions

When are tabs required?

In Makefiles, where recipe lines must start with a tab, and in Go, where the standard formatter uses tabs for indentation. Some teams also prefer tabs because everyone can set their own width.

What does "Only indentation at the start of a line" do?

It converts leading spaces only. A line indented by 8 spaces becomes two tabs at width 4. Spaces inside the line stay as they are.

Why is one stray space not converted?

A single space between words is just a space. Only runs that reach a tab stop become a tab. The leftover spaces after the last whole tab are kept.

Which width should I enter?

The width the indentation was made with, usually 4 or 2. A wrong width gives odd results: 4-space indentation read as width 2 becomes twice the number of tabs.