JavaScript Beautifier
Paste minified or messy JavaScript and get clean, consistently indented code, or squeeze it into a compact minified version. Choose your indent, brace style and line wrapping. Your code stays in your browser.
How to use the JavaScript Beautifier
- Paste your code into the left box, or press Upload .js to open a file.
- Choose the options: indent size, brace style, blank lines and line wrap. Tick JSX for React components.
- Press Beautify. The formatted code appears on the right and updates as you edit.
- Or press Minify to remove comments and whitespace and see how many bytes you save.
- Copy the result or Download it as a .js file.
Brace styles compared
The same function formatted with each brace style:
| Style | Result | Common in |
|---|---|---|
| Collapse | | Most JavaScript style guides (Airbnb, Google, Standard, Prettier) |
| Expand | | Teams coming from C# (Allman style) |
| End-expand | | Some legacy and PHP-influenced code bases |
Collapse, preserve inline behaves like collapse but leaves short blocks such as { x: 1, y: 2 } or if (a) { b(); } on one line when you wrote them that way.
What the minifier removes and what it keeps
- Removed: line comments, block comments (except
/*!license comments if the option is on), indentation, blank lines and spaces that are not needed between tokens. - Kept exactly: the contents of strings, template literals (including nested
${…}expressions) and regular expression literals such as/\/\*.*\*\//g. - Kept for safety: a line break wherever automatic semicolon insertion could depend on it, for example after
return,break,throwandyield, around++and--, and between two statements written without semicolons. A space stays between tokens that would otherwise merge, such asa - -bor1 .toString(). - Not done: renaming variables, removing dead code or rewriting expressions. Those need a full parser-based minifier such as Terser, esbuild or SWC, which typically save another 20 to 40 percent.
Reading minified code: practical tips
- Beautify first, then use your browser's search to find string literals such as error messages or URLs, which survive minification unchanged.
- Single-letter names like
e,tandnare usually function parameters renamed by the minifier. Rename them in your copy as you work out what they do. - Patterns like
!0and!1meantrueandfalse,void 0meansundefined, anda && b()is a compactif (a) b(). - If a
//# sourceMappingURL=comment is present, the original sources may be available in the browser developer tools, which is far better than any beautifier.
Which settings match popular style guides?
| Style | Indent | Braces | Notes |
|---|---|---|---|
| Prettier (default) | 2 spaces | Collapse | Wraps at 80 characters, semicolons on |
| Airbnb | 2 spaces | Collapse | Lines up to 100 characters |
| Google JavaScript Style Guide | 2 spaces | Collapse | Lines up to 80 characters |
| StandardJS | 2 spaces | Collapse | No semicolons, space before function parentheses |
| WordPress and jQuery | Tabs | Collapse | Spaces inside parentheses |
For a team project, the settings matter less than applying them everywhere. Once you have picked a style, a formatter in your editor or a pre-commit hook keeps every file consistent automatically.
Frequently asked questions
Can it unminify JavaScript?
Yes. Beautifying adds line breaks and indentation back to minified code so you can read it. It cannot restore original variable names or comments that a minifier removed or shortened, but the structure becomes easy to follow.
Does beautifying change how my code runs?
No. The beautifier only changes whitespace and line breaks, which do not affect how JavaScript runs. The one exception is very old code that relies on automatic semicolon insertion in unusual ways, which the beautifier also handles conservatively.
How safe is the minifier?
It removes comments and unnecessary whitespace only. It understands strings, template literals and regular expressions, keeps /*! license comments if you want, and keeps a line break wherever removing it could change automatic semicolon insertion (for example after return). It does not rename variables, so for production builds a full minifier such as Terser or esbuild will save more.
What do the brace styles mean?
Collapse keeps the opening brace on the same line as the statement (K&R style, the most common in JavaScript). Expand puts every brace on its own line (Allman style). End-expand puts only closing braces on their own line, and preserve-inline keeps short one-line blocks such as { a: 1 } on one line.
Can I format JSON or TypeScript here?
JSON is valid JavaScript and formats fine, but the JSON Formatter also validates it. TypeScript usually formats well because the beautifier is tolerant, although type annotations are treated as plain tokens. For JSX, tick the JSX option.
Is my code uploaded anywhere?
No. Formatting and minifying happen in your browser. The js-beautify library is downloaded once from a public CDN, and your code is never sent to a server.