JavaScript Beautifier

Paste minified JavaScript and get it back readable, or go the other way and strip comments and whitespace. The important thing here is what the tool refuses to touch: it tokenises your code and regenerates only the whitespace between tokens, so strings, template literals, regular expressions and comments come out byte-identical. Formatters built on regular expressions eventually reach inside one of those and corrupt it, and because the result still looks like code the damage is easy to miss. Getting that right means resolving whether a slash starts a regex or is division — undecidable from the character alone, since `(a + b) / c` is division while `if (x) /re/.test(y)` is a regex — and counting brace depth inside template literals so a nested one does not end the outer literal early. Both are handled. Everything runs in your browser.

Cases that break naive formatters

CodeThe trap
const r = /a\/b/gA slash inside a regex
(a + b) / cDivision, not a regex
if (x) /re/.test(y)A regex, despite following )
`a ${`b ${c}`} d`A template inside a template
"http://x.com"// inside a string is not a comment
a - -bMust not become a--b
return xMust not become returnx

When to use it

  1. Make a minified bundle readable enough to debug.
  2. Tidy code pasted from a Stack Overflow answer.
  3. Strip comments and whitespace before inlining a small script.
  4. Re-indent a file that arrived with mixed tabs and spaces.
  5. Read a snippet someone sent as one long line.

How to Use

  1. Paste your JavaScript or drop a file.
  2. Choose indentation, or switch to minify.
  3. Copy the result.

Features

  1. Token-based, so strings and regexes are never altered
  2. Regex versus division resolved from context
  3. Nested template literals handled correctly
  4. Indent with spaces or tabs, any width
  5. for-header semicolons do not break the line
  6. } else and } catch stay on the brace line
  7. ++ and -- bind to their operand
  8. Whitespace minify that keeps meaning-critical spaces
  9. 100% client-side

FAQs

Is my code uploaded?

No. It is tokenised and reformatted in your browser. Nothing is transmitted.

Will it break my strings or regexes?

No. Only whitespace between tokens is regenerated; token contents are copied verbatim. That is the whole design, because formatters that rewrite with regular expressions do eventually mangle a string or a regex, and the result still looks like valid code.

How does it know if a slash is a regex or division?

From context, which is the only way. After an identifier or number it is division; after an operator, a keyword like `return`, or an opening bracket it is a regex. The hard case is a closing paren — `(a + b) / c` versus `if (x) /re/` — so it tracks whether each paren opened a control-flow header.

Is the minifier a real minifier?

No, and it says so. It removes comments and whitespace only. Renaming variables, dropping dead code and rewriting expressions need a full parse and scope analysis, and a subtle error there gives you code that runs but behaves differently — much worse than a slightly larger file. Use a build-step minifier for production.

Does it handle JSX or TypeScript?

Partly. The tokenizer handles the syntax both share, so indentation is usually sensible. Type annotations and JSX have their own grammar, so results there are best-effort rather than guaranteed.

Can I reverse the minification?

You can restore readable formatting, but not names or comments that a real minifier removed. Beautifying mangled code gives you structure back, not meaning.

Technical Details

The source is tokenised and only the whitespace BETWEEN tokens is regenerated — no token's contents are ever rewritten. That single constraint is what makes the tool safe, because a formatter built on regular expressions will eventually reach inside a string, a template literal or a regex and corrupt it silently. Tokenising JavaScript has one genuinely hard decision: whether a slash opens a regular expression or is a division operator. It is not decidable from the character, only from context. After an identifier or a number it is division; after an operator or an opening bracket it is a regex; after `return`, `typeof`, `case` and a handful of other keywords it is a regex. The awkward case is a closing parenthesis, where `(a + b) / c` is division but `if (x) /re/.test(y)` is a regex, so a small stack records whether each open paren began a control-flow header and the closing paren is judged accordingly. Template literals need their own care because they nest: an interpolation can contain another template literal, so the brace depth is counted rather than scanning to the next backtick, which would end the outer literal in the wrong place. Beautifying then indents on braces, breaks lines on statement semicolons but not on the ones inside a for-header, keeps `} else` and `} catch` on the closing brace line, and binds `++` and `--` to their operand in both prefix and postfix position. Minifying removes comments and whitespace and nothing else: no renaming, no dead-code removal, no expression rewriting. Those require a full parse and scope analysis, and a subtle mistake there yields code that still runs while behaving differently, which is far worse than a larger file. Where two tokens would merge if printed adjacent — `return x` becoming `returnx`, or `a - -b` becoming `a--b` — a single space is kept.

Developer Tools

Developer Tools

  • GraphQL Formatter
  • Prettier Playground
  • XML Formatter
  • cURL Command Builder
  • cURL to Code
  • HTTP Status Codes
  • Subnet Calculator
  • IP & MAC Validator