Code Formatter
Fix indentation in JavaScript, Python, Java, C-family, PHP, HTML, CSS, JSON, and more.
Paste code in any of 14 languages and re-indent it based on bracket or tag nesting depth — JSON gets a real parse-and-pretty-print, Python gets a safe whitespace-only tab/space conversion instead of guessed restructuring.
What it handles
- JSON — parsed and re-printed exactly, and it'll flag invalid JSON.
- Brace languages (JavaScript, TypeScript, Java, C, C++, C#, PHP, CSS/SCSS, Go, Rust, Swift, Kotlin) — indentation recomputed from
{ } ( ) [ ]nesting, ignoring brackets inside strings and comments. - HTML/XML — indentation from tag nesting;
<script>/<style>contents are left untouched. - Python — converts existing indentation between tabs and spaces (or resizes spaces), without guessing at structure.
How to use it
- Choose the language — JavaScript/TypeScript, JSON, HTML/XML, CSS/SCSS, PHP, Java, C, C++, C#, Go, Rust, Swift, Kotlin or Python.
- Pick an indent style: 2 spaces, 4 spaces or tabs.
- Paste your code and format it, then copy the result.
When it helps most
- Pasted code from emails, chat or web pages that lost its indentation.
- Minified or one-line JSON from an API response that you need to read.
- Mixed tabs and spaces after combining code from several people or editors.
- Deeply nested HTML that's hard to follow without clear indentation.
Tabs or spaces?
Both work — what matters is consistency within a project. Common conventions: 2 spaces for JavaScript, JSON, HTML and CSS; 4 spaces for Python (the PEP 8 style guide), Java, C# and PHP; and tabs for Go, whose standard formatter uses them. When working in an existing codebase, match whatever it already uses.
Frequently asked questions
Does this rewrite my code's style, like Prettier does?
No — it only fixes indentation based on bracket/tag nesting depth. It won't change quote style, line breaks, semicolons, or wrap long lines. For most "my code is a mess of inconsistent indents" situations, that's exactly what's needed.
Why is Python handled differently?
In Python, indentation is part of the code's meaning — guessing at structure could silently change what the code does. So instead of re-deriving indentation, this only converts the whitespace character/width already in your code (e.g. tabs to 4 spaces), which is always safe for valid Python.
Is my code sent to a server?
No — formatting happens entirely in your browser with plain JavaScript. Nothing you paste here is transmitted anywhere.
What happens to code inside <script> or <style> tags in HTML mode?
It's left completely untouched — only the surrounding HTML tag structure is re-indented, since JS/CSS formatting needs different rules than HTML does.
Why did my JSON give an error?
JSON is strict: keys need double quotes, trailing commas aren't allowed, and comments aren't permitted. The formatter parses JSON properly, so an error usually points to one of these problems in the input.