JavaScript Minify and Beautify
Make your JavaScript easier to read, or as small as possible. Paste your code or open a .js file, then choose Beautify to lay it out on separate lines with consistent indentation and spacing, or Minify to strip comments and unnecessary whitespace so the file downloads and loads faster.
Both modes only change spacing, line breaks and comments, never your code itself, and the result is checked before it’s shown: the tool reads your original and the result and makes sure they’re the same program. It understands modern JavaScript, including classes, private fields, optional chaining and template literals, and can unpack code compressed with the classic “packer”. Everything runs in your browser.
JSInput
JSBeautify
Only whitespace and comments are ever changed, and every result is checked against your original before it’s shown. Your code never leaves your browser.
Looking for mistakes in your code? Try the JavaScript Validator.
About this tool
Beautify or minify?
- Beautify while you write and debug. Code laid out on separate lines with consistent indentation is far easier to read and makes mistakes easier to spot.
- Minify before you publish. A smaller file downloads and is parsed faster, which helps your page load sooner.
- Keep the beautified version as your working copy: a minified file isn’t meant to be edited by hand.
Why it can’t break your code
JavaScript inserts semicolons automatically at some line breaks, so careless minifiers can join two statements into one. This tool keeps every line break that matters: a return at the end of a line still returns nothing, and a line starting with ++ stays separate.
return // ends here: returns undefined
value;
As a final check, the original and the result are both parsed and compared. If they’re not exactly the same program, nothing is changed.
What minifying does and doesn’t do
Minifying here removes comments, indentation, spaces and line breaks that aren’t needed. It doesn’t rename variables or rewrite your code, which is why it’s always safe. Tools such as Terser or esbuild go further by shortening names, usually saving another 20 to 40%, and serving files with gzip or Brotli compression shrinks them further still.
Turn on Unpack packed code to decode scripts compressed with Dean Edwards’ Packer, which start with eval(function(p,a,c,k,e,d), before they’re laid out, even if they were packed more than once. The packed code is decoded as text and never run, so it’s safe to unpack code you don’t trust.
Frequently Asked Questions
What is the difference between minifying and beautifying JavaScript?
Beautifying adds line breaks, indentation and spacing so the code is easy to read. Minifying does the opposite: it removes comments and every space and line break that isn’t needed, making the file as small as possible for your website. Neither changes what the code does.
Is it safe to minify my JavaScript here?
Yes. Only whitespace and comments are removed, and line breaks that JavaScript’s automatic semicolon insertion depends on are kept. As a final check, the tool parses your original and the result and compares them, and refuses to show a result that isn’t exactly the same program.
Does minifying rename my variables?
No. Names and code are left exactly as you wrote them. Build tools such as Terser or esbuild can also shorten variable names for a smaller file, but that needs to understand your whole project, while this tool is safe to use on any snippet.
How much smaller will my file be?
It depends on how much whitespace and how many comments the code has. Typical hand-written code shrinks by 20 to 35%. Code that’s already minified won’t get any smaller. The output pane shows the size before and after.
What does “Keep /*! licence comments” do?
Comments that start with /*! are, by convention, copyright or licence notices that must stay with the code. With this option on, the minifier keeps them and removes all other comments.
Can this tool decode obfuscated JavaScript?
It can unpack code compressed with the classic Packer, which starts with eval(function(p,a,c,k,e,d). Turn on Unpack packed code in Beautify mode. Other kinds of obfuscation, such as renamed variables or encoded strings, are laid out neatly but not decoded.
Why does it say my code couldn’t be read?
The tool has to find where every string, comment, template literal and regular expression starts and ends before it changes anything. If one is never closed, it stops and leaves your code unchanged. The JavaScript Validator will point to the exact spot.
Does it support modern JavaScript?
Yes, including classes and private fields, arrow functions, async and await, optional chaining (?.), nullish coalescing (??), template literals, regular expression flags, BigInt and ES modules with import and export.
Is my code uploaded?
No. Minifying and beautifying both happen in your browser, and nothing is sent to a server or stored.