How to use JavaScript Beautifier & Minifier
What it does & when you need it
You've opened a bundle, a vendor script, or a snippet someone pasted into a ticket, and it's one dense line with no line breaks — or the opposite, a sprawl of inconsistent spacing you'd like to tidy before committing. This tool does both directions. Beautify re-indents JavaScript into a readable, consistent layout; Minify strips comments and redundant whitespace to shrink the source. Everything runs in your browser, so proprietary or unreleased code never touches a server — paste freely.
Reach for it when you want to read minified or machine-generated output, sanity -check a small script before shipping it inline, or normalize whitespace so a diff shows real changes instead of formatting noise.
How to use
- Paste your JavaScript into the input.js buffer, press Sample to load a
small annotated function, or Upload a
.js/.mjsfile. - Pick a mode with the toggle. Beautify expands and indents; Minify compresses. The output buffer updates live as you type or switch modes.
- The status bars report byte counts on both sides, so you can see exactly how
much minifying saved. Press Copy result (or
Ctrl/Cmd+Enter) to copy the output, or use the buffer's own Copy button.
Things worth knowing
This is a whitespace-and-comment minifier, not a compressor. It deletes line
and block comments and collapses insignificant spacing, but it never renames a
variableName to a and never reorders or dead-code-eliminates anything. That
keeps the result readable and safe, but it also means the savings are modest. For
production builds you want a real minifier such as Terser or esbuild:
because they parse the code into an AST, they can mangle identifiers, fold
constants, and drop unreachable branches, shrinking payloads far more than a
scanner ever can. Think of this tool as a quick cleanup, not a build step.
Newlines are preserved on purpose, so Automatic Semicolon Insertion is
unchanged. JavaScript's ASI rules are sensitive to line breaks — most
famously, a return sitting on its own line above its value returns undefined,
because a semicolon is inserted right after return. A naive minifier that joins
everything onto one line would silently change that behavior. This one keeps the
original newlines, so code that relied on ASI (for better or worse) behaves
exactly as it did before.
It actually understands the lexical grammar, so it won't corrupt your code.
The scanner tracks whether it's inside a single- or double-quoted string, a
template literal, or a regular-expression literal. That means a // sitting
inside a string is left alone rather than treated as the start of a comment, and
a / inside a regex like /a\/b/g is never mistaken for a division operator or
a comment delimiter. This is the class of bug that trips up regex-based
find-and-replace hacks — if you're crafting those patterns, the
Regex Tester is the right companion tool.
Beautify imposes one consistent brace and indent style. Whatever the input's spacing, the output uses a single predictable convention, which is what makes minified or machine-generated code legible again. It's the JavaScript sibling of the JSON Formatter and CSS Formatter: same idea, applied to a different grammar. For markup, reach for the HTML Formatter instead.