JavaScript Formatter

Beautify JavaScript and JSX with Prettier, choosing your own semicolon, quote and indentation style.

Runs in your browser

JavaScript

Formatted JavaScript

Formatted with Prettier, in this browser tab. Nothing is uploaded.

How to use the JavaScript Formatter

  1. Paste your JavaScript, open a .js file, or press Sample.
  2. Set indentation and line width in the options if the defaults do not suit your project.
  3. Press Format, or Ctrl + Enter. Errors show the line and column of the problem.
  4. Copy the result or download it as a .js file.

Example

Unformatted JavaScript
Input
const fetchUsers=async(ids)=>{const res=await fetch(`/api/users?ids=${ids.join(",")}`);if(!res.ok){throw new Error("Request failed: "+res.status)}return (await res.json()).filter(u=>u.active).map(({id,name})=>({id,name}))}

What it does

A real parser, not find-and-replace
Your JavaScript is parsed into a syntax tree before printing, so nesting is always correct and invalid code is reported rather than mangled.
Your style settings
Choose 2 or 4 spaces or tabs, and a maximum line width. Settings are remembered on this device.
Style options
Semicolons on or off, single or double quotes, and trailing commas.
Runs in your browser
The formatter loads on demand and runs locally. Nothing you paste leaves your device.

Frequently asked questions

Which engine formats the JavaScript?

Prettier, the widely used open-source code formatter. It parses your JavaScript into a syntax tree and prints it again, so the output is consistent and the same input always gives the same result.

Is my code uploaded anywhere?

No. The parser and printer run in your browser. Your code is never sent to a server, logged or stored.

Can it unminify a minified bundle?

Yes, it will lay the code out readably. Variable names shortened by a minifier cannot be restored.

Will formatting change how my code behaves?

No. Prettier only changes whitespace, line breaks, quotes and similar layout details. If it cannot be sure a change is safe, it leaves the code as written.