Convert tabs to spaces (and back)

Paste your text or code and convert its tabs to spaces, or its indentation spaces to tabs. Set how many spaces one tab is worth: 2, 4, 8 or any width up to 16.

  • Free
  • No sign-up
  • Runs in your browser
tabs-to-spaces

100% private — your text is processed in your browser and never sent to any server.

How it works

Paste your text or code

Source code, a configuration file, a table or plain text with tabs.

Set the direction and width

Tabs to spaces, or indentation spaces to tabs, with the number of spaces per tab.

Copy the result

The change count tells you how many replacements were made.

Tabs and spaces: the argument you do not have to win

Whether to indent with tabs or with spaces is a long-running debate among programmers, but in practice the problem is usually that a file contains the wrong one for the place where it is going. A project may require spaces, a Makefile requires tabs, a YAML file forbids tabs for indentation, a forum post needs spaces to keep the alignment, and a text pasted between editors can end up with a jumble of both. This tool converts a text from one convention to the other.

Tabs into spaces

Every tab character is replaced by the number of spaces you choose: 2, 4 and 8 are the usual values. This simple rule has one limit that is worth knowing: a real tab jumps to the next tab stop, so its width depends on where it sits in the line, whereas this tool substitutes a fixed number of spaces. For indentation at the start of a line the result is exactly what you want. For tabs in the middle of a line, used to align columns, the alignment may change.

Only the indentation

The option "only the tabs at the start of a line" converts the indentation and leaves tabs inside the line untouched. That is the safer choice for code and for tab-separated data, where tabs in the middle of a line separate columns and must not become spaces.

Spaces into tabs

The opposite conversion turns the spaces that begin a line into tabs, one tab for each group of the chosen number of spaces. A line indented with eight spaces becomes two tabs when the width is four. Leftover spaces that do not fill a group are kept as spaces, so no alignment is lost, and spaces in the middle of a line are never touched.

What it does not do

The tool does not detect the indentation style of your file, does not reformat code and cannot tell whether a tab is inside a string or a comment. For code with strict layout rules, such as Python or YAML, check that the structure is still valid after converting.

Frequently asked questions

How do I convert tabs to spaces?
Paste the text, leave "Tabs into spaces" selected, set the number of spaces per tab and copy the result.
How many spaces should a tab be?
Four is the most common in modern code, two is popular in web projects, and eight is the traditional width. Use whatever your project or team expects.
Can I convert only the indentation?
Yes. Tick "only the tabs at the start of a line" to leave tabs inside lines, for example between columns, unchanged.
How do I convert spaces into tabs?
Choose "Leading spaces into tabs". Every group of spaces at the start of a line, as many as the tab width, becomes one tab.
Does it keep my alignment inside lines?
Tabs inside a line are replaced by a fixed number of spaces, which can change column alignment. Use the indentation-only option to avoid it.
Is my code uploaded anywhere?
No. It is processed in your browser.