JavaScript Formatter

Prettier for JavaScript, TypeScript and JSX — no install, no upload.

Runs in your browser Instant No sign-up
Language
Indent
Line width
Quotes
Code
Formatted

Paste, type or drop a file — output appears as you type.

Waiting for input
Processed locally · nothing is uploadedProcessed locally

How to use the JavaScript formatter

  1. Paste, drop or open code in the left pane.
  2. Choose Language: JavaScript / JSX or TypeScript / TSX.
  3. Adjust Indent, Line width, Quotes, Semicolons and Trailing commas. The result updates as you type.
  4. Copy or Download the formatted code.

The formatter is Prettier, loaded on demand in your browser.

Example

const user={name:'Linh',roles:['admin','dev']};function greet(u){return `Hi ${u.name}`}

With the defaults, this becomes:

const user = { name: "Linh", roles: ["admin", "dev"] };
function greet(u) {
  return `Hi ${u.name}`;
}

With Quotes set to ‘Single’ and Semicolons off:

const user = { name: 'Linh', roles: ['admin', 'dev'] }
function greet(u) {
  return `Hi ${u.name}`
}

Template literals are left as written.

Options and their Prettier names

Option Prettier setting Default here
Indent tabWidth, useTabs 2 spaces
Line width printWidth 80
Quotes singleQuote “Double”
Semicolons semi On
Trailing commas trailingComma ("all" or "none") On ("all")

The same settings in a .prettierrc:

{
  "tabWidth": 2,
  "printWidth": 80,
  "singleQuote": false,
  "semi": true,
  "trailingComma": "all"
}

Why Prettier is opinionated

Most formatters expose dozens of settings, and teams end up arguing about them. Prettier takes the opposite approach: it parses your code, throws away the original formatting and prints it again from scratch, following fixed rules. Line breaks depend on Line width, not on where you pressed Enter, so the same code always produces the same output. That is also why code reviews get shorter once a team adopts it: diffs contain only real changes.

JSX and TypeScript

JSX is formatted in both modes. For example, const A=()=><div className="x"><b>hi</b></div> becomes a multi-line component wrapped in parentheses. TypeScript syntax needs TypeScript / TSX:

const f=(x:number):string=>String(x)

In JavaScript mode this fails with Unexpected token, expected "," at line 1, column 12. In TypeScript mode it becomes const f = (x: number): string => String(x);.

Errors

A syntax error stops formatting and shows the message with its position, for example const x = ; gives Unexpected token at line 1, column 12. Jump to error puts the cursor there.

Format markup with the HTML Formatter and styles with the CSS Formatter. For JSON data rather than code, the JSON Formatter keeps big numbers exact and explains errors in plain English.

Doing it locally

npx prettier --write "src/**/*.{js,jsx,ts,tsx}"
npx prettier --single-quote --no-semi file.js

Frequently asked questions

Is my code uploaded?

No. Prettier runs in your browser and nothing is uploaded, so proprietary code and snippets with secrets stay on your machine.

Does it support JSX and TypeScript?

Yes. JavaScript / JSX uses Prettier's Babel parser, which understands JSX and modern syntax. TypeScript / TSX uses the TypeScript parser for type annotations, interfaces, enums and generics. Type annotations in JavaScript mode are a syntax error.

Why can't I configure more options?

Prettier is intentionally opinionated: it offers a few options and makes every other decision itself, so a whole team gets identical output. The options here are the ones teams most often change.

Will the output match Prettier in my project?

Yes, if your .prettierrc uses the same settings. The equivalent configuration is shown below; any option not listed uses Prettier's default.

Does it check my code for bugs?

No. It only reports syntax errors, with their line and column. Use a linter such as ESLint or the TypeScript compiler to find logic and type errors.

Last updated