JavaScript Formatter & Beautifier

Paste JavaScript and reprint its indentation locally. The code is not run, and it is not sent to UtilChain.

Use this tool

The file is read on this page and is not uploaded.

Result

The result appears in this panel after you run the tool.

About this tool

Beautify and pretty-print mean the spacing js-beautify produces: indentation, braces, and line breaks. The engine understands ordinary modern JavaScript used in these pages’ checks, including optional chaining, nullish coalescing, template literals, classes, private fields, and async functions. It does not execute the program. Strings, comments, and template literals are the library’s job, which is why this page does not reformat JavaScript with a search-and-replace.

Use it to read a minified function, to line up a snippet before a review, or to compare two copies that differ only by whitespace. Load sample shows a short example. If the library reports a failure, the page shows that error. If the source is simply invalid, the reprint can still be incomplete, because this is not a compiler.

The beautifier is loaded only on this page. Other tools do not download it. The source stays in this browser.

How to use it

  1. Paste JavaScript, or choose a local file. The file is read on this page and is not uploaded.
  2. Choose an indent, then Format JavaScript. Ctrl+Enter or Cmd+Enter does the same thing from the box.
  3. Copy or download the reprint. This is spacing, not a type check or a test run.

Limitations

js-beautify reprints source and does not run it

Beautify is a printer, and the script stays unrun

js-beautify reprints the script. The page loads the browser build of that library and asks it to print the paste with an indent of two spaces, four spaces, or a tab. Existing line breaks are kept, but a stack of more than two blank lines in a row is reduced to two. The library is not asked to force a newline at the end of the file. If the library throws, that message is the failure. If it returns an empty string while the paste was not empty, the page rejects the result instead of pretending the script became blank.

The script is not executed. No function in the paste is called, no import is fetched, and no effect at the top level runs. Optional chaining, template strings, and nullish defaults in a sample are reprinted as source text. They are not evaluated against a value. A beautifier can also emit text for source that a parser would reject. Success on this page means the printer returned text. It does not mean the program is legal, typed, or safe to ship.

What the printer will not settle

There is no type checker in this pass. An undefined variable is still printed. A misspelled method name is still printed. The validator page is the one that asks Acorn to parse the paste as a module and then stops. The minifier is the one that compresses and renames. This formatter keeps names. Indent and blank-line policy are the changes. Comments that the beautifier knows how to keep stay with the code. The page does not have a switch for brace style beyond the indent size and the tab choice.

When the output looks surprising

A very long line may stay long if the library does not wrap it. A semicolon the library inserts, or a space it prefers around an operator, can differ from the house style you typed. That is the printer’s style, applied to the source it was given. If you needed a syntax verdict, run the validator on the same paste. If you needed a shorter file, run the minifier, and expect names to change there. Use this page when the goal is a readable listing of the source you already have.

Privacy

Your JavaScript is processed in your browser and is not uploaded to UtilChain. File names, source text, and results are not sent to analytics.