1. Home
  2. Developer
  3. JavaScript Beautifier & Minifier

JavaScript Beautifier & Minifier

Format JavaScript for readability, or minify it to shrink file size.

Runs in your browser · No upload Works offline

Loading the beautifier…

Your code is handled as text only — never executed — and never uploaded.

How to use

  1. Paste JavaScript into the input — a site’s .min.js, code squashed onto one line, or your own script.
  2. Beautify breaks blocks onto their own lines and indents them. Choose the indent width, brace placement (same line or next line) and whether to keep blank lines.
  3. Minify strips comments, indentation and unnecessary spaces. Comments that start with /*! or contain @license are kept by default.
  4. Copy the result or download it as a .js file, and check how much smaller it got.

How far does minify go?

Minify here puts never changing what the code does first. It shrinks less than a build tool, but any code you paste keeps working the same way.

Does Doesn’t
Remove comments (license comments optional) Shorten variable and function names (mangling)
Remove indentation and blank lines Drop unused code
Remove spaces around { } ( ) ; , and operators like = Rewrite expressions (true → !0)
Join lines only where automatic semicolon insertion stays the same Touch strings, regexes or template literals

JavaScript has automatic semicolon insertion (ASI): a line break can end a statement. Gluing let a = 1 to a following let b = 2 is a syntax error, and removing the line break after return changes what’s returned. So in semicolon-free code those line breaks stay, and lines are joined only where it’s safe — after {, , or ;, or before a line starting with . such as .then(). Spaces that would turn a + +b or x - -1 into ++ or -- are kept too.

Example

function add (a, b) {
  // add two numbers
  return a + b
}

This 59-byte snippet becomes function add(a,b){return a+b} (29 bytes), about 51% smaller. Comments and indentation go; the only space left is where two words would otherwise merge, between return and a. Line breaks after { and before } can’t change how statements are split, so they’re removed.

Things to watch out for

  • For production, build tools like terser or esbuild shrink far more by mangling names and removing dead code. This tool is handy for quickly shrinking a single file or reading minified code.
  • A regex right after ), as in if (x) /re/.test(s), can be mistaken for division, and spaces inside that regex may then be removed. Check the output for code like that.
  • Beautify can’t undo obfuscation (names already shortened to a, b); it restores line breaks and indentation only.

FAQ

Is the code I paste executed?

No. It’s analyzed as text and never run, and it isn’t uploaded.

Can I format JSON or CSS too?

Use the JSON Formatter, the CSS Beautifier & Minifier or the HTML Beautifier & Minifier.

Coming soon

Can't find the tool you need?

Tell us what you want to do. We build the most requested tools first.