What is a JavaScript beautifier and minifier?
A JavaScript beautifier reformats code with consistent indentation and line breaks, which makes minified scripts readable when you're debugging a production issue or studying how a page works. A minifier does the reverse for your own code, producing the smallest equivalent script so pages load faster.
This tool does both in the browser: js-beautify for formatting with your choice of indentation, and Terser, the minifier behind most JavaScript bundlers, for production-grade minification with compression and variable mangling. The size before and after is shown so you can see what you saved.
How to use the JavaScript Beautifier
1.Paste JavaScript
A function, a module or a minified bundle snippet.
2.Beautify or minify
Beautifying is instant; minifying loads Terser on demand.
3.Copy or download
Minify shows the size before and after.
Example: minifying a small function
The 195-byte sample with a greet() function and a loop, run through Terser:
- Before
- 195 bytes
- After
- 167 bytes
- name and greeting
- renamed to e and o
- if (…) { console.log() }
- rewritten as a && expression
Top-level names greet and users are kept, so other code can still call them.
What Terser does
Minifying uses Terser with compression and name mangling: it removes whitespace and comments, shortens local variable names, and rewrites code into shorter equivalents, such as an if statement into &&. Top-level names stay, because other scripts may use them. Syntax errors are reported instead of producing broken output.
Terser is a large library, so it's downloaded only when you press Minify. Beautifying uses js-beautify, which restores indentation but can't restore the original variable names once they've been mangled.
Frequently asked questions
Can I get the original code back from minified JS?
Only the layout. Beautifying adds indentation, but shortened variable names and removed comments are gone. Source maps exist for that.
Does it support modern JavaScript?
Yes, including ES modules, classes, async/await and optional chaining.
Is this obfuscation?
No. Minified code is smaller, not secret; anyone can beautify it and read the logic.
Is my code uploaded?
No. Both beautifying and minifying run in your browser.
Related tools
HTML Beautifier & Minifier
Indent messy HTML or minify it for production.
CSS Beautifier & Minifier
Format CSS readably or minify it safely.
JSON Formatter & Validator
Pretty-print, minify, sort and validate JSON with line-numbered errors.
JSON ↔ CSV Converter
Convert JSON arrays to CSV and CSV back to JSON.
JSON to TypeScript Interface Generator
Generate TypeScript interfaces or types from a JSON sample.
JSON ↔ YAML Converter
Convert JSON to YAML and YAML to JSON.