Skip to content
Tezmy Tools

Tabs to Spaces Converter

Convert tabs to spaces, or leading spaces to tabs, in code and text

Usually 2, 4 or 8.

5 tabs found.

Runs in your browser. Nothing is uploaded.

About the Tabs to Spaces Converter

Tabs and spaces both indent text, but they look different in different editors and break formatting when mixed. A tab can show as two, four or eight spaces depending on settings, which is why code from one project looks ragged in another. This converter switches a text between the two styles. Tabs to spaces replaces each tab with a number of spaces you choose, and optionally lines the text up to tab stops so columns stay straight. Spaces to tabs turns each group of leading spaces into a tab. It is meant for source code, configuration files, plain text tables and logs.

Updated October 2026

How to use the Tabs to Spaces Converter

  1. 1Paste your code or text into the left box.
  2. 2Choose whether to convert tabs to spaces or leading spaces to tabs.
  3. 3Set the number of spaces per tab, usually 2, 4 or 8.
  4. 4Tick the tab stop option if tabs sit in the middle of lines.
  5. 5Copy or download the converted text.

A worked example

A small function indented with tabs has lines that start with one tab, two tabs and so on. With a width of 4 and tabs to spaces, those lines start with four and eight spaces. Convert them back with leading spaces to tabs and you get the original tabs. A line with six leading spaces becomes one tab and two spaces, because only complete groups of four turn into tabs.

When mixed indentation causes trouble

  • Python raises an error when blocks mix tabs and spaces.
  • YAML does not allow tabs for indentation at all.
  • Makefiles require real tabs before commands.
  • Diffs and code reviews look strange when tab width differs.
  • Markdown code blocks may render differently with tabs.

Choosing a width

Two spaces are common in web projects, four in Python, Java and C-style languages, and eight is the traditional terminal width. If you are not sure, four spaces are a safe choice and match what most editors show for a tab by default.

Related tools

The Code Beautifier formats entire programs, the Remove Extra Spaces tool tidies spacing in prose, the Line Ending Converter fixes Windows and Unix line breaks, and the Diff Checker shows what changed after you reformat.

Features

  • Tabs to spaces and spaces to tabs
  • Any width from 1 to 16
  • Optional tab-stop alignment
  • Counts the tabs it found
  • Copy and download
  • Runs in your browser

Frequently asked questions

How do I convert tabs to spaces?

Paste the text, choose Tabs to spaces and set the width. Each tab character is replaced by that many spaces, so with a width of 4 every tab becomes four spaces.

What is the difference between a tab and 4 spaces?

A tab is one character that editors show as a jump to the next tab stop, while four spaces are four characters. Spaces look the same everywhere, but a tab lets each reader choose their indentation width.

What does Line tabs up to tab stops do?

A tab moves to the next multiple of the tab width, so a tab after two characters only adds two spaces with a width of four. This option reproduces that behaviour so columns of text stay aligned. Leave it off for plain indentation at the start of lines.

How do I convert spaces to tabs?

Choose Leading spaces to tabs. Each group of spaces at the start of a line, equal to the tab width, becomes a tab, and any leftover spaces are kept. Spaces in the middle of a line are never changed.

Which is better for code, tabs or spaces?

It is a long-running debate. Many style guides, such as those for Python, JavaScript and Rust formatters, prefer spaces, while Go and some Makefiles use tabs. Follow the convention of the project you are working on.

Will it change anything else?

No. Letters, line breaks and all other characters are left as they are. Only tab characters or leading spaces are replaced.

Related tools