JavaScript Formatter

Beautify minified or badly indented JavaScript so you can read and debug it. Choose the indent and brace style, and keep or collapse your blank lines.

Updated
Runs in your browser. Your data is not uploaded.
Formats as you type for inputs up to 200 KB.

How to use the JavaScript Formatter

  1. Paste code into Code input, or upload or drop a .js file.
  2. Pick the Indent and Brace style, and untick Keep blank lines if you want them removed.
  3. Press Format, then copy the result or download it.

How it works

The code is split into tokens (keywords, names, strings, regex literals, operators) by js-beautify, then written out again with new whitespace.

  • Each statement goes on its own line, and each block adds one level of indent.
  • Spaces are put around operators and after commas and keywords.
  • Brace style: Same line keeps { at the end of the line, Next line moves it down (Allman style), and End expand puts else and catch on a new line after }.
  • Strings, template literals, regex literals, and comments are never changed inside.

Examples

Input:

function add(a,b){if(!b){return a}return a+b}const total=[1,2,3].reduce((s,n)=>add(s,n),0);

Formatted with 2 spaces and braces on the same line:

function add(a, b) {
  if (!b) {
    return a
  }
  return a + b
}
const total = [1, 2, 3].reduce((s, n) => add(s, n), 0);

Limitations

  • Formatting restores layout, not names. Minified variables such as a and b stay short, and removed comments can't come back.
  • TypeScript type annotations and JSX usually format fine, but unusual syntax may be spaced oddly. Prettier handles those best.
  • The formatter doesn't check the code for errors.
  • Files are limited to 5 MB.

Frequently asked questions

Can this unminify JavaScript?

It restores line breaks and indentation, so minified code becomes readable. Original variable names and comments can't be recovered, because minification removes them.

Will formatting break my code?

No. Only whitespace changes, and the formatter treats strings, regex literals, and template literals as single tokens. Code that ran before runs the same afterwards.

Which brace style should I use?

Most JavaScript style guides, including Airbnb, Google, and StandardJS, keep the opening brace on the same line.

Is my code uploaded?

No. Formatting runs in your browser.

Often used together with the JavaScript Formatter.