JavaScript Formatter

Beautify JavaScript code.

About the JavaScript Formatter

Reformats minified or badly indented JavaScript into something readable, at 2 or 4 spaces. It is deliberately conservative: statements get their own lines and the indentation is rebuilt, but your blank lines survive and long lines are not rewrapped. Use it to read a bundled file, review a snippet pasted into a bug report, or tidy code that never went through a formatter.

How to use the JavaScript Formatter

  1. Paste your JavaScript into the input panel, or press Sample to load an example.
  2. Choose 2 spaces or 4 spaces from the Indent selector.
  3. Press Beautify to reformat the code.
  4. Copy the result, or Download it as script.js.

Frequently asked questions

Does it check my syntax?
No. This is a reformatter, so it re-indents what it can and passes broken code through unchanged instead of reporting an error. Run the file through the JavaScript Minifier if you want a real parse.
Is this the same as Prettier?
No. It uses js-beautify, which re-indents your code without reprinting it to a target line width. Prettier rebuilds the output from the syntax tree and will move things its own way; js-beautify leaves your line structure largely intact.
Can it unminify code?
It restores indentation and line breaks, which is usually enough to read minified code. It cannot bring back the original variable names or the comments, because the minifier threw them away.
Does it keep my blank lines?
Yes, up to two consecutive blank lines. Longer runs are collapsed to two.
Is my code uploaded?
No. Formatting happens in your browser; this page has no server side.

Related tools