Code

Convert Tabs to Spaces and Back

Converts leading tabs to spaces or back, and reports mixed indentation.

Loading the tool…

Processing happens locally in your browser. What you paste or load is processed by this page and is not uploaded to a server. Nothing is stored unless you use a control that says it stores something, and you can clear anything this site has kept from the privacy page.

How to use this tool

  1. Paste the code whose indentation you want changed.
  2. Choose tabs or spaces, and the width one indent level should be.
  3. Select Convert.

What indentation converter does

Only leading whitespace is converted. A tab inside a string, inside a comment or between two words on a line is left exactly as it was, because changing it would change what the program does — in Python, in Makefiles and in any language with a here-document, that difference is not cosmetic.

Mixed indentation is reported rather than quietly fixed, because it is worth knowing: a file where some lines start with a tab and others with spaces looks correctly aligned in one editor and wrong in every other. Converting to tabs replaces whole groups only, so an odd remainder is left as spaces rather than rounded, which would silently move the code.

Frequently asked questions

No. Only leading whitespace is converted. A tab inside a string, a comment or between two words on a line stays as it is, because changing it would change what the program does.

Converting to tabs replaces whole groups only. Three leading spaces under a four-space rule stay as spaces rather than being rounded to a tab, since rounding would move the code — and in Python, moving the code changes what it means.

It is fixed, and reported as well, because it is worth knowing it was there. A file where some lines start with a tab and others with spaces looks correctly aligned in the editor it was written in and wrong in every other one, and that usually points at a missing editor configuration.