Skip to content
SmaftyTools

JavaScript Beautifier / Minifier

Beautify minified JavaScript into readable code, or minify it to shrink file size. Free online JS formatter — runs entirely in your browser.

About JavaScript Beautifier / Minifier

The JavaScript Beautifier / Minifier reformats messy or minified JavaScript into clean, readable code with consistent indentation, or compresses readable code down to the smallest possible size for production. It runs both directions from a single tool: paste a squashed bundle to beautify it for reading, or paste source code to minify it before shipping.

Beautifying is the move whenever you hit JavaScript you can't read at a glance — a minified vendor library you're debugging, a webpack bundle chunk pasted from browser dev tools, or a colleague's one-line function that needs breaking apart to actually review. Minifying goes the other way: shrinking a script's file size for a static site, a bookmarklet, or an embed snippet where every kilobyte matters and there's no build pipeline to run a bundler through.

Beautify mode uses js-beautify, the same formatting engine behind many IDE 'format document' commands, applying consistent brace placement, spacing and indent width. Minify mode uses Terser, the production-grade minifier that also powers most modern JavaScript bundlers — it doesn't just strip whitespace and comments, it renames local variables to shorter names and applies safe compression transforms (removing dead code, folding constants) the same way a real production build would, so the size reduction here is representative of what you'd actually ship.

Because minification actively rewrites code (renaming variables, restructuring expressions), a syntax error in the input is caught and reported clearly rather than producing broken or partial output — Terser needs to fully parse the code to minify it safely, unlike a beautifier that can often tolerate looser input. Both directions run entirely in your browser; JavaScript containing proprietary logic or API keys never leaves your device.

How to Use the JavaScript Beautifier / Minifier

  1. Paste JavaScript into the input box.
  2. Choose Beautify to format it, or Minify to compress it.
  3. Pick an indent size for Beautify mode.
  4. Copy or download the result.

Features

  • Beautify with js-beautify — the same engine behind many IDE formatters
  • Minify with Terser — the production-grade minifier used by modern bundlers
  • Clear syntax error reporting when input can't be parsed
  • 2 or 4-space indent options for beautified output

Examples

Beautifying a squashed function

Input

function greet(name){if(!name){return 'Hello, stranger!'}return 'Hello, '+name+'!'}

Output

function greet(name) {
  if (!name) {
    return 'Hello, stranger!'
  }
  return 'Hello, ' + name + '!'
}

Minifying readable code before shipping

Input

function add(a, b) {
  return a + b;
}

Output

function add(n,d){return n+d}

Catching a syntax error on minify

Input

function( {{{

Output

Error — the input could not be parsed as valid JavaScript.

Frequently Asked Questions

What's the difference between this and a bundler's built-in minifier?

It uses the same Terser engine that powers minification in tools like webpack and Rollup, so the compression behavior (variable renaming, dead code removal) matches what a real production build would produce — just without needing a build pipeline for a one-off file.

Why did minifying fail with a syntax error?

Terser has to fully parse your JavaScript to safely rename variables and restructure code, so it can't minify code with a syntax error the way a simple whitespace stripper could. Fix the reported error and try again.

Is minified code safe to read the original logic from?

No — minification renames variables and compresses structure, which is why this tool also offers Beautify mode: paste minified code in, switch to Beautify, and get readable (though not originally-named) code back for review.

Is the JavaScript Beautifier / Minifier free?

Yes, the JavaScript Beautifier / Minifier is completely free with no usage limits. No signup, no account and no installation required.

Is my data safe?

Yes. All processing happens locally in your browser using JavaScript — nothing you type is uploaded or stored on our servers.