JavaScript Formatter

Format JavaScript code.

FreeNo accountOn your device

Runs in your browser. How to verify

Loading tool…

About this tool

Paste JavaScript and format it with Prettier, the same formatter most projects use. Every Prettier option that applies to JavaScript is available: tab width, tabs, print width, semicolons, quotes, quote props, trailing commas, bracket spacing, arrow parentheses, object wrapping, JSX options, line endings and the experimental ternary and operator-position styles. If your code has a syntax error you get the line and column instead of silently broken output. JSX is understood, and nothing leaves your browser.

How to use

1
Step 1
Paste your JavaScript into the Input box.
2
Step 2
Set tab width, print width, semicolons and quotes, or open All Prettier options for the rest, and choose a parser if you need Flow or a different one.
3
Step 3
Press Format, then copy or download the result and check the bytes before and after.
4
Step 4
Press Copy as.prettierrc (JSON) to take your non-default options into a project, or Reset to Prettier defaults to start over.

How it works

The code is parsed into a syntax tree with Prettier's Babel parser by default (or babel-flow, acorn, espree, meriyah or flow if you pick one) and printed again from scratch using your options, so layout is decided by the code's structure, not by how you spaced it. Long calls and objects wrap at the print width, quotes are normalised to your choice and semicolons are added or omitted consistently. Only the parser you choose is downloaded, and the CSS, GraphQL, HTML and Markdown plugins load only if your code contains matching template literals. Your option choices are remembered in this browser. If Prettier cannot load, a basic indentation formatter is used and the page says so.

Worked example

Messy to tidy

Input
const a={b:1,c:'x'};function f(x){if(x){return x+1}else{return 0}}
Output
const a = { b: 1, c: "x" }; function f(x) { if (x) { return x + 1; } else { return 0; } }
Walkthrough
Spaces are added around operators and braces, the single-quoted string becomes double-quoted, and each block gets its own indented lines.

Limitations

  • Code with a syntax error is not formatted; fix the reported line and try again.
  • Prettier has opinions: it will not keep hand-aligned columns or extra blank lines beyond one.
  • Only options that apply to JavaScript are shown; file-level settings such as overrides, plugins and.prettierignore are not.
  • Some parsers are stricter than others: acorn, espree and meriyah do not accept Flow annotations, and flow does not accept every Babel proposal.
  • Very large files may take a moment, since formatting runs in your browser.

Questions

Is this the real Prettier?
Yes. It runs Prettier's standalone build with the Babel parser in your browser, so results match Prettier with the same options.
How do I switch to tabs or single quotes?
Tick Use tabs and Single quotes, then press Format again. Tab width sets how wide a tab or indent level counts.
Which options can I change?
Tab width, tabs, print width, semicolons, single quotes, JSX single quotes, quote props, trailing commas, bracket spacing, bracket on same line, arrow parentheses, object wrap, one attribute per line, end of line, embedded language formatting, and the experimental ternaries and operator position settings.
Can I reuse my settings in a project?
Yes. Copy as.prettierrc (JSON) outputs only the options that differ from Prettier's defaults, so an unchanged page gives an empty object.
Which parsers can I choose?
babel (default), babel-flow, acorn, espree, meriyah and flow. babel is the safest choice for modern code and JSX; pick babel-flow or flow for Flow type annotations.
Are my settings saved?
Yes, in this browser's local storage, separately for the JavaScript and TypeScript pages. If storage is blocked, the defaults are used each visit. Reset to Prettier defaults clears them.
What happens with a syntax error?
You get a message such as 'Syntax error at line 2, column 11: Unexpected token' with the offending line marked.
Does it handle JSX and modern syntax?
Yes, including async functions, optional chaining, classes and JSX. When JSX is detected in your code, the note under the output says so.
Is my code uploaded?
No. Formatting happens entirely in your browser.

Features

  • Real Prettier engine
  • Every JavaScript Prettier option
  • Parser choice: babel, babel-flow, acorn, espree, meriyah, flow
  • Copy as.prettierrc with only non-default options
  • Reset to Prettier defaults
  • Settings remembered in your browser
  • Bytes before and after
  • Line and column for errors
  • Runs in your browser

Related resources

Guides and videos from around the web—opens on YouTube or the publisher’s site.

  • SQL Tutorial - Full Database Course

    freeCodeCamp.org

    SQL formatters shine when reviewing long beginner queries.

    Watch on YouTube
  • Learn Regular Expressions - Crash Course

    freeCodeCamp.org

    Regex primer for tester and explainer pages.

    Watch on YouTube
  • Prettier documentation

    Prettier

    Industry-standard formatting rules—compare with quick browser formatters.

  • web.dev

    Google

    Modern web guidance that pairs with encoding and tooling pages.