JavaScript

JavaScript Beautifier

Reformats minified or messy JavaScript into consistently indented code.

Loading the tool…

Processing happens locally in your browser. What you paste or load is processed by this page and is not uploaded to a server. Nothing is stored unless you use a control that says it stores something, and you can clear anything this site has kept from the privacy page.

How to use this tool

  1. Paste the minified or badly formatted JavaScript.
  2. Set the indent size, or switch to tabs.
  3. Select Format.
  4. Run the result through again if you want to confirm the formatting is stable — it produces the same output.

What javascript beautifier does

Reading a minified bundle, or a snippet pasted out of a log with every line run together, is close to impossible until it is laid out. This page re-indents it: braces open a level, statements go on their own lines, object properties get a line each, and spacing follows the usual conventions — a space after a keyword, none between a function name and its argument list.

Only braces change the indent. Parentheses and square brackets are tracked, but only so a semicolon inside for(;;) is not mistaken for the end of a statement and a comma between array elements does not become a line break — breaking on those is what turns a short call into six lines of nothing. Ternaries keep their spacing, object keys do not, and the two are told apart properly rather than guessed at. Comments are kept by default and can be dropped. Running the result through again produces the same output, so the formatting is stable.

Frequently asked questions

Deliberately. Only braces change the indent here; parentheses and brackets are tracked but do not force breaks, because breaking on them is what turns a short call into six lines of nothing. Object properties do get a line each, since that is where the readability actually comes from.

Yes. It counts the unmatched question marks in the current bracket frame, so "a ? b : c" keeps its spaces and "name: value" stays tight. Guessing between the two is the usual way a simple formatter produces odd-looking output.

Yes — formatting an already-formatted result produces exactly the same text. That matters if you paste the output into a file that is under version control, because a second pass will not produce a spurious diff.