piapia123
en

JavaScript Indentation Beautifier

Formatting

Everything runs locally in your browser — nothing is uploaded

Input
Output

Re-lay out JavaScript that was squeezed onto one line, using braces and semicolons as the structure: blocks indent a level each, statements get their own line, } else { stays joined, and short object literals stay inline. This tool only re-indents, it does not parse the language, so brackets inside regular expression literals and expressions inside template strings do not take part in the structural scan and results can be off in those cases. String and comment contents are carried through verbatim, and nothing but whitespace is ever changed.

Features

  • Indents by brace depth, with the closing brace returned to the matching level
  • Breaks lines after semicolons, but not inside for (;;) where they are separators
  • Keeps } else {, } catch { and } finally { on one line
  • Object literals stay on a single line when they have no semicolon and are short, while code blocks are expanded
  • Class bodies are always expanded across lines
  • Strings, template literals (including nested templates and ${} expressions) and comments are preserved verbatim
  • A line comment always forces a line break, so following code can never be commented out
  • Whitespace is only added where the grammar leaves no doubt: after commas and between control keywords and their parenthesis
  • Whitespace around operators is left as written, and no semicolon is ever inserted or removed
  • Known limitation: without lexical analysis, brackets inside regular expression literals are read as structure

How to use

  1. Paste your JavaScript into the input box
  2. Pick the indentation width
  3. Press Ctrl/⌘ + Enter or click Run
  4. Click Copy to take the result

FAQ

Why do regular expressions throw the layout off?
Telling a division slash from the start of a regular expression needs a full lexer, including unary versus binary operators. Guessing wrong swallows the rest of the line as a pattern, so instead of guessing the limitation is stated plainly: indentation may be off when a regular expression contains brackets.
Why is the spacing around operators left alone?
Spacing a=b out requires knowing whether a minus is unary or binary, as in a - -b, i++ or x=-1. That is lexical analysis again, and guessing wrong can change what the code means. This tool sticks to indentation so it cannot break your code by guessing.
Can it change how my code behaves?
Nothing but whitespace is touched: no semicolon, bracket, operator or string content is altered. You can verify this yourself by stripping all whitespace from the input and the output and comparing the two.
Is my code uploaded anywhere?
No. Everything runs in your browser memory, the page makes no network requests, and it works offline.

Related tools