Skip to content

JavaScript Formatter & Beautifier

This JavaScript formatter makes minified or badly formatted JS readable again.

JavaScript input

Tab inserts indentation. Press Escape, then Tab, to move focus out of the editor.

Formatted JavaScript

How to format JavaScript

  1. Paste minified or messy JavaScript on the left, or open a .js file.
  2. The formatted code appears on the right and updates as you type.
  3. Pick 2 spaces, 4 spaces or tabs for indentation.
  4. Copy the result or download it as a .js file.

Before and after

Before
const f=(a,b)=>{if(!a)return b??0;return a.map(x=>x*2).filter(Boolean)}
After formatting
const f = (a, b) => {
  if (!a) return b ?? 0;
  return a.map(x => x * 2).filter(Boolean)
}

What the formatter does — and doesn't

The formatter uses js-beautify, which reads your code as a stream of tokens and re-lays it out: one statement per line, consistent indentation, spaces around operators and after keywords. It understands strings, template literals, regular expressions and comments well enough to leave them untouched.

It is not a full JavaScript parser and does not check that your code is valid — broken code is laid out as well as possible rather than rejected. Shortened names in minified code (a, b, t) stay short: the original names aren't in the file anymore.

Use cases

  • Reading a minified library or a third-party script to understand what it does.
  • Cleaning up a snippet from Stack Overflow, a chat or an old project.
  • Debugging production code copied from the browser's dev tools.

Formatting minified code: what to expect

Formatting restores indentation and line breaks, but it can't bring back what a minifier removed: shortened variable names like a and t and deleted comments stay as they are. For readable production code, look for the original source or a source map instead.

Other formatters and minifiers

Going the other way? The JavaScript minifier compresses code for production and reports syntax errors. Format stylesheets with the CSS formatter and markup with the HTML formatter, or run your script together with HTML and CSS in the HTML compiler.

Frequently asked questions

Does formatting change what my code does?
No. The formatter only changes whitespace and line breaks. Strings, template literals, regular expressions and comments are kept as they are.
Does it check my JavaScript for errors?
No. It is a formatter (js-beautify), not a full JavaScript parser, so it lays out the code without validating it. Broken code is formatted as well as possible. The JavaScript minifier, which parses the code, reports syntax errors with line and column.
Can it unminify JavaScript?
It restores readable indentation and line breaks. Names that a minifier shortened (like a, b, c) can't be restored, because the original names are no longer in the file.
Is modern JavaScript supported?
Yes: classes and private #fields, async/await, arrow functions, optional chaining, nullish coalescing, template literals, spread, ES modules and regular expressions with flags.