§

Options

Beautify options
§

Paste JavaScript

§

Beautified JS

js

Developers across the US and UK reach for a beautifier when they hit a bundled script in production and need to read it. Open the Sources panel in Chrome DevTools, paste a minified vendor file here, and you get back something a code review can follow. Teams that adopt Prettier or the Airbnb JavaScript Style Guide use the same indentation rules this tool exposes, so the output drops straight into an ESLint-checked repository. It also helps when auditing a third-party widget for a SOC 2 review, or when a GDPR data-mapping exercise means tracing exactly what an analytics snippet does before it ships.

How JavaScript beautification works

The beautifier reads your code character by character, tracks how deeply nested each statement is, and re-emits it with consistent spacing. It never changes what the code does — only how it looks.

  1. Tokenize. The library scans your input into a stream of tokens: keywords, identifiers, strings, operators, and punctuation. Strings, template literals, and regular-expression literals are recognized as single units, so a brace inside a string never gets mistaken for a block delimiter.
  2. Track nesting. As it walks the token stream, the beautifier keeps a running indent level. Every opening brace, bracket, or parenthesis pushes the level deeper; every closing one pops it back. That depth decides how many indent units sit in front of each line you get back.
  3. Apply your options. Your indent choice (2 spaces, 4 spaces, or a tab) sets the width of one level. The brace-style setting decides whether an opening brace hugs the statement that precedes it or drops to its own line. The blank-line cap collapses long runs of empty lines down to the limit you pick.
  4. Re-emit. Finally the formatter prints the tokens back out with the indentation and line breaks it has worked out, optionally adding the semicolons that automatic semicolon insertion would have supplied at runtime. The result is the same program, laid out so a human can read it.

Why beautify JavaScript

  • Read minified code. Production bundles ship on one line with single-letter variable names. Beautifying restores the line breaks and indentation so you can actually trace a bug back to the statement that caused it, even without a source map.
  • Tidy inconsistent files. Code that several people have touched drifts into mixed indentation and brace styles. One pass through the beautifier normalizes the whole file to a single layout, which makes the next diff show real logic changes rather than whitespace noise.
  • This tool doesn't tax your page. Most online formatters load their whole library the moment you open the page. This one lazy-loads js-beautify only when you click Beautify or switch Live mode on, so opening the page costs a few kilobytes instead of a few hundred, and the initial render stays quick.
  • Nothing leaves your browser. The beautifier runs entirely on your device. Your code is never uploaded to a server, which matters when the script you're inspecting belongs to a client, contains internal API paths, or falls under a confidentiality agreement.

Common applications

Beautifying JavaScript comes up whenever someone needs to read code that wasn't written to be read.

  • Debugging production: paste a minified bundle pulled from the Network tab to find the function behind an error stack you can't otherwise decode.
  • Code review prep: reformat a contributor's inconsistently-indented file before opening the pull request so reviewers see logic, not layout churn.
  • Security and compliance audits: expand a third-party analytics or ad snippet to confirm exactly what it does before it goes live.

A worked example

Take a minified one-liner: function f(a){if(a){return a*2}else{return 0}}. Paste it above with indentation set to 2 spaces and brace style Collapse, then click Beautify. You get back a readable block: function f(a) {, then an indented if (a) {, the return a * 2; statement nested one level deeper, and the matching braces lined up underneath. Switch the brace style to Expand and each opening brace drops onto its own line instead. Change indentation to Tabs and every level shifts from two spaces to a tab character. The structure is identical; only the layout changes.

FAQ

Does this run in my browser?

Yes. The js-beautify library is lazy-loaded the first time you click Beautify or enable Live mode, then cached. Your code never leaves the page — there is no server round-trip and no upload.

Is beautifying the same as un-minifying?

It restores readable formatting — indentation, line breaks, and spacing — but it cannot bring back the original variable names or comments that minification removed. If a source map exists, your browser's DevTools can recover the original names; a beautifier alone works only with what's in the file.

Will beautifying change how my code behaves?

No. Beautification only adds and removes whitespace and line breaks; the program runs identically. The one option that touches tokens is "Add missing semicolons," which inserts the statement terminators that automatic semicolon insertion would have added at runtime anyway, making the code safe to later minify.

What do the brace-style options mean?

Collapse keeps an opening brace on the same line as the statement (if (x) {), which is the common JavaScript convention. Expand drops every opening brace onto its own line (the Allman style). End-expand keeps the opening brace attached but puts else and catch on a fresh line after the closing brace.

Browser-side JavaScript beautification gives you readable code without a build step or an upload. Paste a minified or messy script, pick your indentation and brace style, then copy or download the result. Nothing leaves your device, there's no account, and the library only loads when you ask it to — so opening this page costs you a few kilobytes, not a megabyte.