Skip to content

JavaScript Beautifier

Re-indent minified or messy JavaScript with braces on their own lines and consistent 2-space indentation.

Runs in your browser Free, no sign-up
Loading tool workspace...

What is JavaScript Beautifier?

This JavaScript beautifier re-indents minified or badly formatted JavaScript so you can read it. Paste code from a bundle, a script tag or an old file, and the beautifier breaks it into lines at curly braces and indents each block by two spaces, so functions, loops, conditionals and object literals become easy to follow.

It is a quick way to make sense of compressed third-party scripts, inspect what a snippet does before using it, or tidy up code pasted from a chat or ticket.

How to use JavaScript Beautifier

  1. Paste the minified or messy JavaScript into the input panel.
  2. The beautified code appears in the output panel immediately.
  3. Read through the indented blocks.
  4. Copy or download the formatted code.

Key features

  • Re-indents JavaScript by block with 2 spaces
  • Puts braces and blocks on their own lines
  • Works on minified and badly indented code
  • Instant output as you paste
  • Runs entirely in your browser

Common use cases

  • Reading minified third-party scripts and bundles
  • Inspecting snippets before adding them to a project
  • Tidying code pasted from chats, tickets and emails
  • Understanding the structure of legacy JavaScript files
  • Preparing readable code for teaching or documentation

Technical details & standards

The beautifier places each opening brace at the end of a line and each closing brace on its own line, then indents everything between them by two spaces per nesting level. Statements already on separate lines keep their line breaks.

It formats by block structure rather than by fully parsing JavaScript, which keeps it fast but means statements separated only by semicolons on one line are not split, and braces inside strings, template literals or regular expressions are treated as code. Minified variable names cannot be restored, since the original names were removed during minification. For full formatting in a project, use Prettier.

Format JS code from the command line

To format JavaScript across a whole project, run a formatter from the terminal. Both commands below take the one-line function add(a,b){if(a){return a+b}else{return 0}} and print it indented.

Prettier

npx prettier --write app.js
# function add(a, b) {
#   if (a) {
#     return a + b;
#   } else {
#     return 0;
#   }
# }

Prettier also adds semicolons and normalizes quotes, so the output can differ from the input in more than whitespace.

js-beautify

npx js-beautify app.min.js -o app.js
# indents with 4 spaces by default; use -s 2 for 2

Frequently asked questions

How do I unminify JavaScript?

Paste the minified code into the beautifier to restore indentation and line breaks. Browser developer tools can also pretty-print scripts with the {} button in the Sources panel.

Can the beautifier restore original variable names?

No. Minifiers replace names like totalPrice with short ones like a, and the original names are not stored in the code. Only a source map can map them back.

Why are some statements still on one line?

The beautifier breaks lines at braces, not at every semicolon, so several statements written on one line stay together. Prettier or your editor's formatter splits every statement.

Is it safe to paste private code?

Yes. Formatting runs entirely in your browser and the code is never uploaded.

Is my data safe?

Processing happens locally in your browser. Tool input is not sent to CodeUnpack servers.

Does it work offline?

Once the page has loaded, this tool can process input without an internet connection.

More formatters & viewers tools

View all