⚡Free Tools

JavaScript Beautifier & Minifier

Beautify minified or messy JavaScript and JSX, minify it with Terser and see the gzipped size, and find syntax errors by line and column. Your code never leaves your browser.

More options
Input JavaScript
Output

Beautify, minify and check JavaScript in one place

Paste minified, compressed or just untidy JavaScript — a bundle from a website, a snippet from Stack Overflow, a bookmarklet, a JSON response or a React component with JSX — and press Beautify JS or Ctrl+Enter. The code is re-indented with 2 spaces, 4 spaces or tabs, every statement goes on its own line, and braces follow the style you choose. When the code is ready for production, Minify (Terser) compresses it with the same minifier that webpack, Vite and Rollup use, and shows the new size and the gzipped size. Check syntax tells you whether the code parses, and if not, the exact line and column of the error.

Everything runs in your browser. The js-beautify and Terser libraries are bundled with this page, not loaded from a third-party CDN, and the code you paste is never uploaded. That matters when you are inspecting a client's bundle, an internal admin script or code containing API endpoints. After the first visit the tool also works offline and can be installed as an app.

What beautifying does — and does not do

A JavaScript beautifier changes only layout: indentation, line breaks, spaces around operators and the position of braces. It does not rename variables, reorder code or change behaviour, so the beautified program does exactly what the original did. Strings, regular expressions and template literals are kept intact, including ${…} expressions. Modern syntax is supported: arrow functions, classes with private #fields, optional chaining ?., nullish coalescing ??, async/await, destructuring, spread, ES modules and JSX.

Beautifying minified code makes it readable again, but it cannot restore what minification threw away. Local variable names shortened to a, b and c stay short, and deleted comments do not come back. If the site ships a source map, your browser's DevTools can show the original source; otherwise the beautified output is the best view you can get.

Options explained

Your options are remembered in this browser.

Minify with Terser

Minification removes whitespace and comments, shortens local variable and function names (“mangling”), and applies safe compressions such as removing dead code and joining consecutive declarations. Terser runs two compression passes here. Licence comments that start with /*! or contain @license or @preserve are kept by default, because many open-source licences require the notice to stay with the code. You can also remove all comments or keep all of them.

The stats bar shows the minified size, the percentage saved and the gzipped size, measured in your browser with the Compression Streams API. That last number is the one that matters for page speed, because web servers send JavaScript compressed with gzip or Brotli. Google's web.dev guidance is to do both: minify, then compress. Minifying a typical hand-written script saves 30–60% before compression.

Terser (about 1 MB) is loaded only the first time you press Minify or Check syntax, so the page itself stays fast. After that it is cached for offline use.

Syntax errors with line numbers

When you press Check syntax or Minify, the code is fully parsed. If it is not valid JavaScript you see a message such as Unexpected token: punc (}) with the line and column, a snippet with a caret under the problem and a Go to error button. Common causes are a missing closing bracket, a trailing comma in old code, a stray character from copy-and-paste, or import/export without the ES module option. Beautify also runs a quick compile-only check (your code is never executed) and warns if something looks wrong.

Why we do not unpack eval-packed code

Some online beautifiers offer to “unpack” code wrapped in eval(function(p,a,c,k,e,d){…}). Doing that safely is hard, because the usual approach runs part of the untrusted script inside the page. This tool never executes the code you paste. If you need to look at packed code, beautify it first; the packer's dictionary at the end is usually enough to understand what it does.

Typical uses

Good habits

In a real project, let a formatter such as Prettier or ESLint's fixer run automatically on save and in CI, so formatting is never a discussion in code review. Ship minified and compressed code with a source map so errors can still be traced. And never paste code you do not trust into your browser console: reading it in a beautifier is safe, running it is not.

Privacy, offline use and limits

All processing is local. Drafts, options and the last 12 inputs are kept only in this browser's localStorage and can be cleared from the History dialog. The tool handles files of a few megabytes; very large bundles may take a few seconds to minify. TypeScript type annotations are not supported by the minifier — compile TypeScript to JavaScript first.

Sources and references

Frequently asked questions

Is my JavaScript uploaded?

No. js-beautify and Terser are bundled with this page and run in your browser. Nothing is sent to a server, and the tool works offline after it has loaded.

Does beautifying change what my code does?

No. It only changes indentation, line breaks and spacing. Strings, regular expressions and template literals are kept exactly.

Can it restore original variable names?

No tool can. Minification throws the original local names away. Beautifying makes the structure readable; a source map is the only way to get the original names back.

Is the Terser minify safe for production?

Terser is the minifier used by webpack, Vite and Rollup. Mangling renames only local names and licence comments are kept by default. As with any build step, test the minified file before you ship it.

Why does import/export give an error?

Tick the ES module option under More options, so the code is parsed as a module.

Does it support TypeScript?

Beautify works on most TypeScript, but the minifier and syntax check need plain JavaScript. Compile TypeScript first.

Keyboard shortcuts

Ctrl + EnterBeautify
Ctrl + Shift + MMinify with Terser
Ctrl + Shift + CCopy output
Ctrl + SDownload .js