JavaScript Formatter and Minifier

Indent JavaScript so you can read it, or shrink it. Minifying is handed to terser, because minification requires understanding the grammar exactly — a homegrown one quietly breaks other people's code, and that kind of breakage does not surface until the code runs.

Indent

Pasted code never leaves your device. Everything runs in your browser; nothing is sent or stored anywhere. That is what makes it usable for internal config files and production queries.

Formatting is done by terser as well

Asking terser to skip compression and renaming and to print readable output is enough, so there is no second parser. That means formatting reads the syntax all the way through: code with unbalanced brackets or an unterminated string comes back with terser's own message about where it stopped, and no comment is lost. Terser is close to 1MB and is downloaded the first time you press a button, so only the first run is a little slow.

What minifying actually does

It is not just whitespace removal. Local variables inside functions are renamed to single letters, unreachable code is dropped, and constant expressions like 1 + 2 are folded ahead of time. Top-level names and object property names are left alone — if a name that other files call were changed, those files would break. This is why the result means the same thing but cannot be turned back into the original. The saving is reported in UTF-8 bytes.

Why the tool has to understand the syntax

In JavaScript a line break can carry meaning. A line break after return returns undefined, and / is division in one place and the start of a regular expression in another. Stripping whitespace by looking at characters alone quietly produces a different program at exactly these spots. For the same reason only JavaScript is accepted: TypeScript with type annotations, or JSX, comes back as a syntax error, so paste the compiled output instead.

What comes back from broken code

Empty input, or whitespace alone, does nothing. When the syntax is wrong you get terser's own message instead of a result — one English line such as Unexpected token …, with no line or column. Only the JSON tool points at a position; for JavaScript you search the original for the token the message names. Modules with import and export are accepted, but a top-level await comes back as a syntax error.

Working with the result

The result sits beside the input rather than overwriting it, so a wrong choice costs nothing, and you can send the result back up into the input to chain steps — format to read, then minify. Minified output is one line; wrapping in the view is for reading, and what you copy is still one line. Past 4,000 lines the line numbers are folded away and the text is drawn as one block, but the text and the copy are unchanged.

Frequently asked questions

Why is this the only tool here that uses a library?

Because there are too many places to get it wrong: automatic semicolon insertion, telling a regex apart from division, renaming bound identifiers. terser is the minifier that build tools actually ship, and BSD-2-Clause keeps the licensing clean. It is close to 1MB, so it is fetched only when you open this page — someone who only uses JSON, SQL, and CSS never downloads it.

Can it recover minified code?

It can re-indent the code, but the original names are gone. Once a minifier renames a variable to a single letter, that information is no longer in the file. If you have the source map, use that instead.

Are license comments preserved?

Yes. Comments starting with /*! are kept. That convention is how license notices are marked, and stripping them would be erasing someone else's copyright notice.

The minified result is one line — is that right?

Yes. Line breaks are whitespace and go with the rest. If you need to read it, format the result again; the wrap toggle only folds what you see, and the copied text stays on one line. For a file people will read, use the formatter alone.

Does anything I paste get sent to a server?

No. Everything runs inside your browser and nothing is uploaded or stored. That is why you can use it on things you would not normally paste into a web page, like an internal config file or a production query. It also works with your network disconnected.