Tabs to spaces converter

Replace tab characters with spaces so the layout is the same in every editor. Choose a tab width of 2, 4 or 8. Everything happens in your browser and nothing is uploaded, so you can use it on private source code.

Tab width

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

A table with columns separated by tabs (name, price, quantity) and an indented line becomes aligned text: name price quantity, with the columns padded to the next multiple of four. The note says how many tabs were replaced, here 7.

Tab stops, not a fixed count

A tab does not equal a fixed number of spaces. It jumps to the next tab stop, so the converter pads each tab to the next multiple of the width. That keeps text lined up as it was on screen.

Indentation or everything

Tick Only tabs at the start of a line when you want to convert the indentation and leave tabs between columns. Untick it to convert every tab.

Related

The opposite is spaces to tabs. To clean other whitespace, see normalize whitespace and remove double spaces.

Frequently asked questions

Why does the tab become a different number of spaces?

A tab moves to the next tab stop, so it takes 1 to 4 spaces in a width of 4. In `name<TAB>price` the tab after four letters becomes four spaces, but after `ab` it becomes two. That keeps columns aligned the way an editor shows them.

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

It converts the indentation only and leaves tabs further along the line, which may separate columns in a table, alone.

Why do some files require spaces?

YAML does not allow tab characters for indentation, and many style guides, such as the Python one, ask for spaces. A file that mixes both shows broken alignment in other editors.

Which width should I choose?

The width of the code's style guide: 4 for Python and many projects, 2 for many JavaScript, YAML and HTML projects, and 8 for the classic tab stop.