JavaScript Formatter and Minifier
Beautify minified JavaScript, minify it with Terser, or check its syntax with the exact line and column of any error. Runs in your browser only.
How to format or minify JavaScript
- Paste your code, or click Open a file to load a
.js,.mjsor.jsxfile (up to 10 MB). - Choose the Indentation and, if you prefer the Allman style, tick Braces on their own line.
- Click Format (beautify) to make the code readable.
- To shrink it, set the Minify options and click Minify. To only look for errors, click Check syntax.
- Copy or download the result. The status line shows the size before and after, and the percentage saved.
The code is only read and transformed, never run: nothing you paste is executed on this page.
Beautify with js-beautify
Format (beautify) uses js-beautify. It puts one statement per line, indents blocks, adds spaces around operators and after keywords, and keeps up to one blank line where you had some. It also understands modern syntax (classes, arrow functions, template literals, async/await) and JSX. It is the quickest way to read a minified library or a one-line snippet copied from a web page.
Beautifying only changes whitespace. It does not check that the code is valid: a missing parenthesis simply produces odd indentation. Use Check syntax for that.
Minify with Terser
Minify uses Terser, the minifier used by most JavaScript build tools. Because it is large, it is only downloaded when you first click Minify or Check syntax. The options map directly to Terser settings:
- ES module (import/export) parses the code as a module (
module: true): strict mode applies and top-level names are private, so they can be renamed and unused ones removed. Leave it unticked for a classic script whose global functions are used by other scripts. - Compress (
compress) rewrites the code into shorter equivalent code: constant folding (2*60becomes120), dead code removal, joining ofvardeclarations, shorter conditions. - Shorten variable names (
mangle) renames local variables and parameters to one or two letters. Global names and object properties are never renamed. - Keep license comments keeps comments that start with
/*!or contain@licenseor@preserve. All other comments are removed.
Minification cannot change what the code does, but code that relies on function names (fn.name) or on eval can behave differently after renaming. Untick Shorten variable names in that case.
Syntax errors with line and column
When Terser cannot parse the code, Minify and Check syntax show the error message with its line and column, for example “Line 12, column 8 – Syntax error: Unexpected token punc «)»”. The column counts characters from 1. A typical cause is a missing bracket earlier in the file, so look at the lines just before the reported position too.
Frequently asked questions
Is my code uploaded anywhere?
No. js-beautify and Terser both run in your browser, and your code stays on your computer.
Can I minify TypeScript?
No. Terser only accepts JavaScript. Compile TypeScript to JavaScript first, then minify the output. Formatting simple TypeScript with Format (beautify) often works, but type annotations may be spaced oddly.
Why does my minified code look different from what I wrote?
Compress evaluates constant expressions, inlines single-use values and removes unreachable code. The result behaves the same. Untick Compress to only remove whitespace and comments.
Does "ES module" need to match my code?
Yes. Code with import or export should be minified as a module. A classic script minified as a module could lose global functions that other scripts call, because top-level names are then treated as private.
What about JSON?
JSON is valid JavaScript, so both buttons accept it, but the dedicated JSON formatter gives better error messages and sorts keys.
Related tools
- JSON Formatter and Validator Free JSON formatter and validator that beautifies, minifies and checks JSON in your browser, with syntax errors reported by line and column.
- CSS Formatter and Minifier Beautify messy CSS with clean indentation or minify it with csso, and see the size before and after. Runs in your browser; nothing is uploaded.
- HTML Formatter Beautify messy HTML with clean indentation, or minify it safely, in your browser. Inline CSS and JavaScript are formatted too. Nothing is uploaded.
- Regex Tester Test JavaScript regular expressions live with highlighted matches, capture groups, replacement and a plain-English explanation of every token.