Indent Fixer

Detect mixed tabs and spaces, then normalize indentation to your target width — without touching strings or comments.

100% client-side

Input code

0 characters · 0 lines
Paste code to detect its indentation style
Normalize to

Result


        

How indentation detection works

Absolute indentation width alone doesn't reveal the step size a file uses — a line indented 8 spaces could be one level of 8-space indent or two levels of 4-space indent. The reliable signal, the same one code editors like VS Code use, is the difference in leading-whitespace length between one line of real code and the previous one. The most common positive difference is the detected step; whichever of tabs or spaces shows up more often is the detected character:

// Before (mixed 2-space and inconsistent indentation)
function greet(name) {
  if (name) {
      console.log("Hi, " + name);
  } else {
    console.log("Hi!");
  }
}

// After (normalized to 2 spaces)
function greet(name) {
  if (name) {
    console.log("Hi, " + name);
  } else {
    console.log("Hi!");
  }
}

Only each line's leading whitespace is rewritten — everything from the first non-whitespace character onward is left byte-for-byte untouched. A lightweight shared state machine also tracks single/double-quoted strings, backtick template literals, triple-quoted Python strings and /* */ block comments as it scans, and skips reindenting any line that is a continuation of one of those constructs, since that whitespace is string/comment content, not code structure. If a file genuinely mixes two different indentation widths in different blocks, the more common width wins and the minority is treated as noise — this is a documented trade-off of using one global step size rather than a per-block heuristic.

Frequently asked questions

How does the automatic indentation detection work?

It uses the same heuristic most code editors use: instead of looking at each line's absolute indentation width, it looks at the difference in leading-whitespace length between consecutive lines of real code. The most common positive difference is the detected step size (usually 2, 4 or 8), and whichever of tabs or spaces appears more often is the detected character.

Will it corrupt strings, template literals or comments?

No. It tracks a small state machine as it scans the code (single/double-quoted strings, backtick template literals, triple-quoted Python strings, and /* */ block comments) and only ever rewrites a line's leading whitespace when that line is not a continuation of one of those constructs. The rest of every line is copied through untouched.

Does it work for languages other than JavaScript?

Yes, reasonably well for JS/TS, Python, CSS, JSON and similar C-like or Python-like languages, because it uses one lightweight shared tokenizer instead of a full parser per language. Very unusual syntax (custom raw-string delimiters, uncommon comment styles) may not be handled perfectly.

Is it safe to paste proprietary code here?

Yes. All processing happens in your browser; no code is ever sent to a server.