Skip to content
AZ Tools

Tabs to Spaces Converter (and back)

Convert leading indentation between tabs and spaces with a configurable tab width, in your browser.

Output

How to use

  1. Paste your code or text into the input box.
  2. Choose a direction (tabs to spaces or spaces to tabs) and set the tab width.
  3. Copy the re-indented result from the output box.

About this tool

Show

Convert indentation between tabs and spaces at a tab width you choose, from one to eight. Only the leading whitespace on each line is touched, which is what keeps the conversion safe: a tab inside a string literal, a Markdown table or an aligned comment survives untouched, where a blind find-and-replace would wreck all three. Tab stops are handled properly too — a tab advances to the next multiple of the tab width rather than expanding to a fixed number of spaces, so a file that mixes tabs and spaces in the same indent comes out with its levels intact instead of drifting. Useful for meeting a project's style rules, fixing a snippet pasted from somewhere else, or preparing code for a system with an opinion about whitespace.

Frequently asked questions

Does it change spaces inside a line?

No. Only the leading whitespace at the start of each line is converted, so alignment and spaces within your text stay exactly as they were.

What does tab width do?

It sets how many columns a tab advances to. Converting tabs to spaces uses it to expand each tab to the next tab stop; converting spaces to tabs uses it to pack runs of spaces back into tabs.

How is mixed tab/space indentation handled?

Each line's leading whitespace is measured in visual columns using tab stops, then re-emitted entirely as tabs or spaces, so inconsistent indentation gets normalized.

Is my text sent anywhere?

No. Conversion happens entirely in your browser; nothing is uploaded.

Tabs or spaces — does it actually matter?

For accessibility, tabs have a real argument: a tab is one character whose width the reader chooses, so someone using a large font or a braille display can set it to suit them, while spaces hard-code the author's choice. Beyond that it is a project convention, and the one that matters is that everyone in the repository follows the same one.

Why did my alignment survive but my indentation change?

Because only the leading whitespace is converted. Spaces used mid-line to line up a comment or a table stay exactly as they were, which is deliberate — converting those would shift columns that were aligned by eye. It is also why mixing tabs for indentation with spaces for alignment survives this tool intact.

Related tools