DataToolsLab
Code Formatter Tools

Indentation Converter

Convert code between tabs and spaces, with a configurable spaces-per-tab width, for any language.

Loading tool…

What is Indentation?

A converter for the tabs-versus-spaces argument that does not require re-formatting a whole file. It reads the existing indentation, infers the unit, and re-emits it in the shape your project expects.

How it works

Leading whitespace is measured per line (a tab counting as the configured width) and divided by the source unit to get a depth, which is then re-emitted as tabs or as N spaces per level. The histogram shows which indent widths are actually present, so an inconsistent file is visible before you convert it.

  1. Paste the source. Drop in code, a stylesheet, a query or a selector list. Everything is read locally — the page never uploads what you paste.
  2. Choose the options. Indent width, quote style, keyword case or target browsers. The result updates as you change them, so you can see the effect immediately.
  3. Copy or download. Copy the result to the clipboard or download it as a file. Reset clears the form and returns every option to its default.

Examples

A file indented with 8-wide tabs

Converting to 2-space indentation drops the visual width while keeping the block structure identical, which is exactly what a diff-friendly reformat should do.

Mixed tabs and spaces

The histogram shows lines at 1, 2, 4 and 8 columns — the 1- and 2-column lines are the misaligned ones, and converting rounds them to a consistent level.

Common mistakes

Expecting a formatter to fix invalid code

Formatting is whitespace and quoting. A missing brace, an unclosed tag or an unquoted variable survives the round trip and is reported instead — check the findings list.

Minifying without running the tests afterwards

Even a safe, non-mangling minifier can expose an existing automatic-semicolon-insertion bug. The JavaScript Minifier keeps the newlines that matter, but re-run your tests before shipping.

Treating a rewritten query as verified

The SQL Dialect Converter translates the syntax it can prove; data types, casts and function differences are listed for review, not guessed. Run the converted query against a real database.

Renaming or reformatting generated files

Regenerating a formatter's output is a no-op only if the formatter is the same one that produced it. Keep generated code out of the round trip and format the source it came from.

Frequently asked questions

Does it change anything except leading whitespace?

No. Every character after a line's first non-space character is copied byte for byte, so trailing whitespace, string contents and operator spacing are all preserved.

What is the right width?

Whatever the project's `.editorconfig` says — 2 is the JavaScript/TypeScript default, 4 is common in Python, Java and Go, and tabs with a width of 4 is what the Linux kernel style uses. The `.editorconfig` Generator can write that file for you.

Will a mixed file convert cleanly?

A line indented by a width that is not a multiple of the unit is rounded to the nearest level. That is why the histogram is shown: fix the outliers first and the conversion becomes exact.

Online