JavaScript Beautifier
Beautify minified or messy JavaScript with the industry-standard js-beautify engine.
What does a JavaScript beautifier do?
A JavaScript beautifier (or formatter) re-indents minified or poorly-formatted code to make it human-readable. This tool uses js-beautify— the same engine behind many editors and the beautifier.io site — so it correctly handles the cases a naive brace-counter breaks on: for (…;…;…) loops, regular-expression literals like /a{2,3}/g, and } else {spacing. It runs entirely in your browser — nothing is uploaded.
Built and maintained by Meet Shah · Last updated
What this tool is used for
- Making a minified bundle readable enough to find which function is throwing.
- Normalising a file that arrived with mixed indentation before reviewing it.
- Reading a snippet pasted from a blog post that lost all its line breaks.
- Checking the real structure of a nested callback chain that is hard to follow on one line.
- Preparing an obfuscated-looking third-party script for inspection during an audit.
Frequently Asked Questions
- Can beautifying recover minified code?
- Only the formatting. Whitespace and line breaks come back, but variable names do not — minifiers rename everything to a, b, c, and that mapping is discarded. The result is readable structure with meaningless identifiers.
- What is a source map, and why does it matter more?
- A separate file mapping minified positions back to the original source, including real names. If one exists, DevTools reconstructs the actual code — far better than beautifying. Check for a //# sourceMappingURL comment first.
- Is beautifying safe for all JavaScript?
- Almost, with one real trap: automatic semicolon insertion. Code relying on ASI can change meaning if lines are rejoined, particularly around return statements — a return followed by a newline returns undefined regardless of what follows.
- How does this differ from Prettier?
- Prettier is opinionated and reprints from the AST, discarding your original formatting entirely. A beautifier is more conservative and mainly adds structure back. For a codebase you own, Prettier with a config is the better tool.
- Does it work on modern syntax?
- It needs a parser that knows the syntax — optional chaining, top-level await, decorators and JSX all postdate older beautifiers. An outdated parser will either throw or silently mangle newer constructs.
- Why does automatic semicolon insertion make reformatting risky?
- Because JavaScript infers semicolons from line breaks. Moving a `return` onto its own line makes it return `undefined`, and a line starting with `(` or `[` can join with the previous statement. A correct formatter parses first for exactly this reason.
- Does beautifying affect a source map?
- Yes — it invalidates it. The map records positions in the exact bytes that were minified, so reformatting shifts every offset. Load the original map against the original file; do not beautify first and expect the mapping to hold.
Common errors and gotchas
- Expecting beautifying to recover names. Minifiers rename variables, and formatting cannot undo that.
- Reformatting a file with a template literal spanning lines, where reindenting changes the string's contents.
- Assuming the output is functionally identical when automatic semicolon insertion is involved. Line breaks can matter.
- Treating it as a linter. It reformats; it does not tell you the code is wrong.
- Beautifying a source map's target and then wondering why the map no longer lines up.
Related Formatters & Validators tools
JSON Formatter
Format, validate, and beautify JSON payloads.
Text Diff / Compare
Side-by-side or unified line/character diff comparison tool.
XML Formatter
Beautify and indent XML strings.
Minifier Suite
Minify HTML, CSS, and JS by stripping comments and whitespace.
Markdown Converter
Convert Markdown to HTML with live preview.
CSS Formatter
Beautify and indent minified or messy CSS.
HTML Formatter
Beautify and indent raw HTML markup.
SQL Formatter
Format SQL queries with keyword casing and indentation.