Skip to main content
Preparing workspace

JS Beautifier

Re-indents minified JavaScript with the js-beautify tokenizer at 2, 4 or 8 spaces, braces on the same or their own line. Copy it or save a .js file.

Still loading. If the tool doesn’t appear, reload this page.

About this tool

JS Beautifier

Format, beautify, and clean minified or messy JavaScript code with options to adjust tab indentation size and copy output.

JS Beautifier re-indents minified or run-together JavaScript with the js-beautify tokenizer, so strings, template literals and regular expressions are read as tokens rather than split at every semicolon or brace. Pick 2, 4 or 8 spaces per level and whether an opening brace stays on the same line or gets its own line; a blank line you left between blocks is kept. It makes a minified bundle or a pasted snippet readable — it is not a full parser-based printer like Prettier, so treat the output as a reading aid rather than a replacement for your source file.

How to use JS Beautifier

  1. Paste minified or run-together code into the Input JS Code box, or press Load Sample JS to try it.

  2. Set Indentation Size to 2, 4 or 8 Spaces, pick a Brace Style (opening brace on the same line or on its own line), then press Beautify JS Code.

  3. Read the Beautified JS Code panel, then use Copy Code or Download (.js), which saves script.beautified.js.

Why use JS Beautifier

  • Tokenizer-based, not regex

    js-beautify reads the code as tokens, so a semicolon or brace inside a string, template literal or regex is left alone instead of being split onto a new line.

  • Indent width is your choice

    Switch between 2, 4 and 8 spaces to match the project you are pasting into rather than a fixed house style.

  • Brace style is your choice

    Keep each opening brace on the same line as its statement, or move it onto its own line to match an Allman-style codebase.

Common use cases

  • You opened a minified script in devtools, copied one function out of the single-line bundle, and need to see its control flow before you can reason about a bug
  • A snippet pasted from a chat message or a PDF arrived with the line breaks stripped, and you want it readable again before pasting it into an editor
  • Your team indents with 4 spaces and the code you were sent uses 2, so you want it restated at your depth before it goes into a review comment

Frequently asked questions

Is this the same as running Prettier?

No. Prettier parses JavaScript into an AST and prints it in its own fixed style. This tool uses js-beautify, which tokenizes the code and re-indents it with the indent and brace options you pick, keeping the blank lines you left between blocks rather than rewriting the layout.

Link to answer
Can it break my code?

It only changes whitespace, and because js-beautify tokenizes the code, braces and semicolons inside strings, template literals and regular expressions stay as they are. Unusual syntax can still be laid out oddly, so use it to read unfamiliar or minified JavaScript and re-run your own formatter before committing anything.

Link to answer
Does it undo minification?

Only the whitespace part. Layout, indentation and statement breaks come back, but names do not: a minifier that renamed `userAccount` to `n` has thrown that information away, and no beautifier can recover it without a source map.

Link to answer
What indent sizes are available?

Three: 2, 4 and 8 spaces, applied per nesting level. Two spaces is the common default in modern JavaScript style guides, four suits code being read alongside other languages, and eight makes deep nesting visually obvious when you are auditing a bundle.

Link to answer