200 tools

Web Developer Tools · · 4 min read

How to Beautify and Format JavaScript

Use the JavaScript Beautifier to turn minified or messy JS into clean, indented code with 2-space, 4-space, or tab indentation.

To beautify JavaScript, paste it into the JavaScript Beautifier, pick an Indent size (2 spaces, 4 spaces, or Tab), and read the formatted result in the output box — it reformats live as you type or paste, with no button to click.

What the JavaScript Beautifier does

Minified production bundles, code copied out of a browser's dev tools, or scripts typed in a hurry all tend to collapse onto one dense line or end up with inconsistent spacing. The JavaScript Beautifier reformats that code: it puts each statement on its own line, indents the contents of every block, function, and object literal, and keeps line breaks you already had (up to two in a row) — all without changing what the code actually does. It runs on js-beautify, the same formatting engine used by many code editors, loaded directly in your browser.

How to beautify JavaScript with Toolbench

  1. Open the JavaScript Beautifier.
  2. Paste your JavaScript into the input box on the left.
  3. Choose an Indent size from the dropdown: 2 spaces (the default), 4 spaces, or Tab.
  4. Read the formatted code in the output box on the right — it reformats instantly, with no "Beautify" button to press.
  5. Click Copy to copy the result, or use the Send to → menu to pass the output straight into another tool, such as the JavaScript Minifier.

Indentation width is the only setting — the engine preserves your variable names, string contents, and comments exactly as written.

A real worked example

Starting from this cramped, single-line JavaScript:

function greet(name,loud){if(loud){return "HELLO, "+name.toUpperCase()+"!";}else{return "Hello, "+name+".";}}const users=["Ana","Bo","Cy"];users.forEach(u=>console.log(greet(u,false)));

With the default 2 spaces indent, the JavaScript Beautifier produces:

function greet(name, loud) {
  if (loud) {
    return "HELLO, " + name.toUpperCase() + "!";
  } else {
    return "Hello, " + name + ".";
  }
}
const users = ["Ana", "Bo", "Cy"];
users.forEach(u => console.log(greet(u, false)));

Every block body drops one indentation level deeper than the line that opens it, operators get surrounding spaces, and each statement lands on its own line. The arrow function in the last line keeps its compact form — the beautifier doesn't rewrite => into a different style, it only fixes spacing and indentation.

How the indent options compare

Indent setting What changes When to use it
2 spaces (default) Each nesting level adds two spaces Matches common JS style guides and keeps deeply nested callbacks from running too wide
4 spaces Each nesting level adds four spaces Easier to scan visually; common in some editor defaults
Tab Each nesting level adds one tab character Lets each developer's editor render the indent width they prefer

All three options leave variable names, string literals, numbers, and comments untouched — only indentation and line placement change, and up to two consecutive blank lines in your original code are preserved.

Tips and common mistakes

  • It won't fix broken syntax. The beautifier reformats structure; it doesn't close unmatched braces or parentheses for you. If the output still looks wrong, check the original code for a missing } or ).
  • It doesn't rename or shrink anything. Variable and function names stay exactly as you wrote them — for that, use the JavaScript Obfuscator or JavaScript Minifier instead, which are built for the opposite goals.
  • Going the other way? If you need compact JavaScript for production, run the beautified output through the JavaScript Minifier — the two tools are inverses of each other.
  • Debugging obfuscated code? If the script you pasted is deliberately obfuscated (hex escapes, flattened control flow), try the JavaScript Deobfuscator first — it simplifies that pattern before handing off to the beautifier's formatting.

Frequently asked questions

How do I format messy or minified JavaScript?

Paste it into the JavaScript Beautifier. It reformats the code instantly, putting each statement on its own indented line — no button to click, and no account needed.

What's the default indent size?

Two spaces per nesting level. Switch to four spaces or a tab character using the Indent dropdown above the input box.

Does beautifying change how my code runs?

No. Beautifying only changes whitespace and line breaks in the source — variable names, logic, and string contents are untouched, so the code behaves identically before and after.

Will it fix syntax errors in my code?

No. The beautifier only reformats spacing and indentation; it doesn't repair invalid JavaScript or catch typos for you.

Is my JavaScript sent to a server?

No. Formatting runs in your browser using the js-beautify library. If you're signed in, your input syncs privately to your account; if you're signed out, nothing is saved anywhere.

More guides

All guides →