Skip to main content
Programming Language Tools

Code Indentation Tool

Re-indent code using a configurable number of spaces or tabs.

Paste your code and choose your target indentation (spaces or tabs, and how many) - this tool re-indents it consistently.

This adjusts indentation width/style only - it does not re-parse or validate the code's syntax for any specific language.

What Does This Tool Do?

It detects each line's current indentation level and re-applies it using your chosen indentation style (a specific number of spaces, or tabs) - a simple, language-agnostic way to normalize indentation.

Why Use This Tool?

Team members using different editor settings (tabs vs. spaces, 2 vs. 4 spaces) produce inconsistently-indented files - this tool normalizes a whole file to one consistent style in one pass.

How to Use It

  1. Paste your code.
  2. Choose spaces (and how many) or tabs.
  3. Copy the re-indented result.

Limitations

This works on relative indentation levels detected from your input - it doesn't validate or understand the syntax of any particular programming language.

Example

Code indented with tabs:

if (ready) {
	start();
	if (debug) {
		log("started");
	}
}

re-indented with 2 spaces becomes:

if (ready) {
  start();
  if (debug) {
    log("started");
  }
}

Common Conventions

Language / toolUsual indentation
Python (PEP 8)4 spaces
JavaScript / TypeScript (Prettier default)2 spaces
PHP (PSR-12)4 spaces
Go (gofmt)Tabs
YAMLSpaces only (2 is common)
MakefilesTabs in recipes - required

Prevent the Problem

Add an .editorconfig file to your repository so every editor uses the same settings:

root = true

[*]
indent_style = space
indent_size = 4

[Makefile]
indent_style = tab

For Python code, where indentation defines blocks, use the Python Formatter. For full formatting, try the Code Beautifier.

Frequently Asked Questions

Follow your language's convention or project style guide - for example 4 spaces for Python, 2 for many JavaScript projects, and tabs for Go and Makefiles.

In most languages no. In Python and YAML indentation carries meaning, so check the result.

Yes. Choose the output indentation and existing indentation is converted to it.
Share this tool: