JavaScript Beautifier (JS Formatter)

Make minified or messy code readable again. This JavaScript beautifier and JS formatter re-indents code and JSON, lets you choose the brace style and line wrapping, and can unescape \x and \u sequences in strings.

Press Ctrl+Enter (⌘+Enter on Mac) to run now.

Linecolumn

Beautify and Format JavaScript Online

Minified bundles, one-line snippets from Stack Overflow and code pasted from a chat rarely keep their formatting. This JavaScript beautifier, or JS formatter, rebuilds the layout: one statement per line, consistent indentation inside functions, classes and objects, and spaces around operators, so you can read, debug or review the code.

It uses js-beautify, the long-running open-source project behind jsbeautifier.org. Modern syntax such as arrow functions, classes, template literals, optional chaining and async/await is supported, JSON works too, and strings full of \x41 or \u0042 escapes can be turned back into readable text. Everything runs in your browser.

Minified JavaScript beautified into indented codef(){a() a();JavaScriptBeautifier

How to beautify JavaScript

  1. Paste your code or open a .js, .mjs or .json file.
  2. Pick the indentation and brace style that match your project or style guide.
  3. Set wrapping and blank lines: wrap long lines at 80 to 120 characters and decide how many existing empty lines to keep.
  4. Enable extras if needed: keep hand-aligned arrays, put each chained method call on its own line, unescape strings, or support JSX.
  5. Copy or download the formatted code as script.js.

Brace styles compared

SettingResultCommon in
Same lineif (a) { … } else {Most JavaScript style guides, Prettier
Same line, keep short blocksLeaves blocks such as { return 1 } on one line when they were written that wayCode with many tiny callbacks
Same line, else on new line} then else { on the next lineStroustrup style
Next lineOpening brace on its own lineAllman style, C# habits
Keep as writtenLeaves braces where they are and only re-indentsMixed codebases

Other formatting options

  • Wrap lines at breaks long expressions at operators and commas once a line passes the chosen width. “No wrapping” keeps long lines intact.
  • Blank lines keeps up to one or two empty lines in a row from your input, all of them, or none.
  • Keep array indentation preserves arrays you aligned by hand, such as matrices or lookup tables.
  • Break chained methods puts each .then(), .map() or .filter() call in a chain on its own line.
  • Unescape strings converts printable \xNN and \uNNNN escapes to characters, so "\x48\x69" becomes "Hi". Handy for inspecting obfuscated code.
  • JSX / XML literals keeps JSX tags in React components from being split apart.

Unminifying: what can and cannot come back

A beautifier restores layout, not information. Whitespace, indentation and line breaks come back; comments that a minifier removed do not, and variable names that were shortened to a, b and c stay short. If you have the source map for a bundle, your browser’s dev tools can show the original files instead. The beautifier also does not check syntax: it formats whatever you paste, so a missing bracket simply produces odd indentation. To find syntax errors with an exact line and column, run the code through the JavaScript Minifier, which parses it fully.

Tips

  • Formatting JSON? This page works, but short arrays stay on one line and nothing is validated. For strict JSON with error messages, use the JSON Formatter or the JSON Validator.
  • TypeScript usually formats well because its syntax is close to JavaScript, but type-heavy code such as generics can be laid out oddly; check the result.
  • Inspecting a third-party script? Beautify it first, then search for network calls such as fetch( or XMLHttpRequest to see what it does.
  • Formatting a whole page? The HTML Formatter formats inline scripts together with the markup, and the CSS Beautifier handles stylesheets.

Frequently Asked Questions

Common questions about beautifying and formatting JavaScript.

Paste the code into the left box. The formatted version appears on the right; choose the indentation, brace style and wrapping, then copy it or download it as a .js file.

Yes. The beautifier restores line breaks and indentation so the code is readable again. Shortened variable names and removed comments cannot be recovered.

Yes. JSON is valid JavaScript, so it is indented the same way. The tool tells you when the input is valid JSON; for strict JSON formatting and validation use the JSON formatter.

Yes. Arrow functions, classes, template literals, destructuring, spread, optional chaining, async/await and modules are formatted correctly.

Simple TypeScript formats well because the syntax is close to JavaScript. For JSX, tick “JSX / XML literals” so tags are kept together.

It turns printable \x and \u escape sequences inside string literals into the characters they represent, which makes obfuscated strings readable.

No. It formats any input without validating it. To find syntax errors with their line and column, paste the code into the JavaScript minifier.

No. The js-beautify library is downloaded once and formatting runs in your browser, so your code stays on your device.