JavaScript Beautifier

Formats minified or inconsistent JavaScript with two-space indentation and one statement per line. Strings, template literals and regular expressions are never modified.

The output will appear here.
Advertisement icyabmod — get a website for your business, design it on a live demo

How JavaScript Beautifier works

Formats minified or inconsistent JavaScript with two-space indentation and one statement per line. Strings, template literals and regular expressions are never modified.

Input JavaScript
Output Readable JavaScript
Works done 3,947

How to use it

This JavaScript beautifier turns a minified line or inconsistently indented script into readable code with one statement per line and two spaces per level. Braces open on the same line, operators get consistent spacing and object properties are listed one per line. Strings, template literals and regular expressions are never modified, and nothing you paste is executed: it is formatted as text, entirely in your browser.

How to use the JavaScript beautifier

  1. Paste the code you want to read, such as a minified bundle, an inline script or a single function.
  2. Run the formatter with "Run tool" or the Ctrl + Enter shortcut.
  3. Follow functions, conditions and loops through the indented output.
  4. Copy the result or download it and open it in your editor.

Formatting conventions

The output follows a common, widely used style. A short sample shows most of it:

InputOutput
if(cfg.retry>2){start()}else{stop()}if (cfg.retry > 2) {, then start() indented, then } else {, stop() and }
const cfg={api:"/v1",retry:3}const cfg = {, then api: "/v1", and retry: 3 on their own lines, then };
for(let i=0;i<n;i++)for (let i = 0; i < n; i++), header kept on one line
try{a()}catch(e){b(e)}try { ... } catch (e) { ... }
[1,2,3].map(n=>n*2)[1, 2, 3].map(n => n * 2), arrays and arguments stay inline

Two habits of the formatter to know: method chains such as fetch(u).then(...).then(...) stay on one line, with only brace-delimited function bodies expanded, and statements under a case label sit at the same depth as the label rather than one level deeper.

Beautifying is not un-minifying

A bundler's output such as function cartTotal(n,t){let o=0;for(const a of n)o+=a.price*a.qty;return o*(1+t)} becomes a clear five-line function, but the parameters are still n and t and the accumulator is still o. Meaningful names removed during minification are gone from the file, and no formatter can recover them. If you need the original names, look for the project's source map or repository. What the beautifier gives you is structure: enough to follow the logic and locate the line that misbehaves.

What stays exactly as it was

  • String and template contents, including the spaces in `Total: ${a+b}` and the expression inside ${}.
  • Regular expressions: the tokenizer tells a division sign from the start of a regex, so /\s+/g survives intact.
  • Line breaks that ASI depends on: let a = 1 and let b = 2 stay on separate lines in semicolon-free code. Missing semicolons are not added.
  • Comments, although a trailing comment after a semicolon may move to its own line.

The beautifier does not validate syntax and does not wrap long lines at a fixed width.

Practical uses

  • Auditing third-party scripts: before adding a chat widget, tag or embed to your site, read what it actually does and which endpoints it calls.
  • Debugging production errors: search the formatted file for the function name in a stack trace and read the surrounding logic. Line and column numbers in the trace still refer to the minified file.
  • Reviewing changes: format two versions with the same rules and compare them in the text diff checker.
  • Learning: step through a compressed example to see how it is put together.

If what you pasted is JSON rather than JavaScript, the JSON formatter is the better fit, because it also validates the syntax and reports errors by position.

Privacy and related tools

Formatting happens in JavaScript in your own tab; the code is treated as text, never run, and not sent to the server. Only an anonymous usage counter is incremented. To shrink the code again for production, use the JavaScript minifier.

Advertisement icyabmod — 7 sections × 10 designs and 10 color palettes: design your site yourself, preview ready in 48 hours

Frequently asked questions

No. Only whitespace, line breaks and indentation are added; the tokens and their order are unchanged. Line breaks that automatic semicolon insertion depends on are preserved, and strings and regular expressions are left alone, so the formatted file behaves exactly like the original. Because the code is never executed, you can also safely format scripts you do not trust in order to inspect them.

No. When a minifier renames variables to single letters, the original names are no longer in the file, so there is nothing for a formatter to restore. A beautifier recovers layout, which already makes the control flow readable. To get real names back you need the source map published with the bundle, or access to the original source code.

No. The tool keeps your code style: if the source does not use semicolons, neither does the output. Instead, it preserves the line breaks that matter for automatic semicolon insertion so semicolon-free code keeps working after formatting. If your team enforces a semicolon rule, apply it with a linter in your editor or CI pipeline, where the change can be reviewed.

No. The tool uses one fixed style: two spaces per level, with opening braces on the same line as the statement, which matches the most common JavaScript style guides. If your project uses four spaces or tabs, paste the output into your editor and use its indentation conversion command, or run your project's own formatter on the result.