JavaScript Beautifier & Minifier
Unpack minified scripts, or compress your own and catch syntax slips.
How to use the JavaScript Beautifier & Minifier
- Paste JavaScript into the left panel, or open a .js file.
- Pick Beautify to expand and indent it, or Minify to compress it with terser.
- When minifying, decide whether variable names get shortened. When beautifying, set the indent and brace style under More options.
- If the parser finds a mistake, the message names the line and column. Fix it and the output updates on its own.
Examples
About this tool
Minified JavaScript is great for browsers and useless for people. The beautify mode uses js-beautify to turn a dense one-liner back into properly indented statements, with a newline after each one, consistent spacing around operators, and your choice of brace placement. Modern syntax such as classes with private fields, optional chaining, template strings and async functions is handled, and JSX tags can pass through untouched.
The minify mode runs terser, the same minifier most bundlers use, entirely inside your browser. By default it removes whitespace and comments, folds constant expressions, drops unreachable code and renames local variables to single letters. Names at the top level are preserved so that other scripts on the page can still call your functions; flip the top-level option for modules or self-contained scripts to save a little more. Licence comments that begin with /*! or contain @license are kept.
Because minifying requires a full parse, it doubles as a syntax checker. Instead of the raw parser message, you get a plain sentence describing what went wrong, the line and column where parsing stopped, and the offending line itself. Beautify mode is deliberately forgiving and will format incomplete snippets, so switch to Minify when you want the code checked.
Frequently asked questions
Does any of my code leave my computer?
No. The beautifier and terser both run as JavaScript in this tab. Nothing is uploaded, so you can safely paste scripts that contain keys, internal URLs or unreleased features.
Is the minified code safe to use in production?
Terser is the minifier behind most build tools and its default optimisations keep the behaviour of your code. Two cases deserve care: code that reads a function's .name (turn on "Keep function and class names") and scripts whose top-level functions are called by other scripts (leave "shorten top-level names" off, which is the default).
Why does Beautify not report my syntax error?
Beautifying only needs to recognise tokens, so it formats snippets and even broken code without complaint. Minify parses the whole program and is the mode that reports errors with line and column.
Can I format TypeScript or JSX?
JSX is fine in Beautify mode, where tags are left as they are. TypeScript annotations are not JavaScript, so both modes may trip over them. Compile TypeScript to JavaScript first.
Does it support ES modules and top-level await?
Yes. Import and export statements work in both modes. If a script fails to parse as a classic script, the minifier automatically retries it as a module, which is what allows top-level await.