FormatterHQ

JavaScript Pretty Print with Prettier

JavaScript pretty print powered by Prettier: however the code was laid out, the output is identical, so a team can share one style. Four Prettier options are adjustable.

Input JAVASCRIPT
Output JAVASCRIPT
Ready.

How to use the JavaScript Pretty Print

  1. Paste your code into the Input editor, or use Sample, Upload file or Load URL.
  2. Choose Indent and Line width, then set Semicolons and Single quotes to your team's style.
  3. Press Format, or keep Auto update on to reprint the code as you edit.
  4. If the status bar reports a syntax error, fix it at the given line and column.
  5. Copy or download the result and put the same four settings in .prettierrc.

What JavaScript pretty print means on this page

This JavaScript pretty print tool runs Prettier in your browser. Prettier is an opinionated formatter: it reads the code into a syntax tree, throws away the original spacing and line breaks, and prints the program again under a fixed set of rules. You choose a handful of settings, and Prettier decides everything else. That is the point for teams: once everyone formats with the same settings, style stops being a topic in code review.

Need to keep your own layout, pick a brace style, or minify the result? Use the JavaScript Formatter instead. It runs js-beautify, which adjusts whitespace around the code you wrote and offers more layout switches, but it does not enforce a single style.

Three layouts in, one layout out

Here are three ways a developer might write the same line:

const total = items.filter(i => i.active).map(i => i.price * i.qty)

const total=items.filter(i=>i.active).map(i=>i.price*i.qty)

const total = items
  .filter((i) => i.active)
        .map((i) =>
   i.price * i.qty);

Prettier prints all three identically:

const total = items.filter((i) => i.active).map((i) => i.price * i.qty);

The beautifier on the main page keeps what it is given. The first two inputs come back as one line without a semicolon or parentheses around i, and the third keeps its line breaks and gets re-indented:

const total = items
    .filter((i) => i.active)
    .map((i) =>
        i.price * i.qty);

This is the practical difference. A beautifier makes code readable; Prettier makes it uniform, so a diff only shows real changes.

Side by side with the configurable beautifier

The same minified object, formatted by both engines with their page defaults:

const cfg={retries:3,endpoints:['/api/users','/api/orders'],onError:function(err){console.error('Request failed:',err.message)}}

JavaScript Pretty Print (Prettier, 2 spaces):

const cfg = {
  retries: 3,
  endpoints: ["/api/users", "/api/orders"],
  onError: function (err) {
    console.error("Request failed:", err.message);
  },
};

JavaScript Formatter (js-beautify, 4 spaces, Collapse braces):

const cfg = {
    retries: 3,
    endpoints: ['/api/users', '/api/orders'],
    onError: function(err) {
        console.error('Request failed:', err.message)
    }
}
DetailPrettier herejs-beautify on the main page
QuotesRewritten to one styleLeft as written
SemicolonsAdded (or removed, if you turn them off)Left as written
Trailing commasAdded to multi-line objects, arrays and argumentsNot added
Line breaksChosen from the line widthTaken from the input and from braces
Syntax errorsFormatting stops; the error and position are shownFormats the tokens anyway

For example, const a = {b:1 is rejected with Unexpected token, expected "," on line 1, while the beautifier prints a half-open object without complaint.

The four options and their .prettierrc names

Only four Prettier options are exposed. Each maps to a key you can put in a project configuration file:

Control.prettierrc keyDefault here
IndenttabWidth, or useTabs: true for Tab2 spaces
Line widthprintWidth (20–320)80
Semicolonssemion
Single quotessingleQuoteoff

Line width drives most layout decisions. The call sendWelcomeEmail(user.email, "Welcome aboard", { template: "onboarding", priority: "high" }); stays on one line at 120, hugs the object at 80, and at 40 becomes:

sendWelcomeEmail(
  user.email,
  "Welcome aboard",
  {
    template: "onboarding",
    priority: "high",
  },
);

Semicolons off does not simply delete them. Where a line starts with [ or (, Prettier keeps a leading semicolon so the statement cannot merge with the one above:

const a = b
;[1, 2].forEach((n) => log(n))

Single quotes is a preference, not a rule: 'it\'s' is printed as "it's" because that needs no escape. Everything else, such as trailingComma: "all", bracketSpacing: true and LF line endings, stays at Prettier's defaults.

Getting the same result locally

To make this output the team standard, add Prettier to the project and commit a configuration that mirrors the settings you tested here:

npm install --save-dev --exact prettier
{
  "tabWidth": 2,
  "printWidth": 80,
  "semi": true,
  "singleQuote": false
}

Save the second block as .prettierrc in the repository root. Then run npx prettier . --write to format everything once, and npx prettier . --check in continuous integration to fail builds that were not formatted. Pinning the exact version matters, because formatting rules can change between Prettier releases and two developers on different versions would get different output. Most editors can run Prettier on save through an extension or built-in support, and they read the same .prettierrc, so the editor, the CLI and this page agree.

When the output does not match your project

  • Different trailing commas or arrow parentheses. The project config probably sets trailingComma or arrowParens, which this page does not expose.
  • Type annotations fail to parse. The page uses the Babel parser for JavaScript and JSX. Paste TypeScript into the TypeScript Formatter.
  • React components. JSX works here, and the React JSX Formatter runs the same Prettier setup with a component sample.
  • Unsure where the syntax error is. The JavaScript Validator reports problems without reformatting anything.

The code is formatted in your browser and is not uploaded.

Frequently asked questions

When should I use this instead of the JavaScript Formatter?
Pick this page when your repository is already formatted by Prettier and pasted code should look the same. Use the JavaScript Formatter when you want to keep your own layout, choose a brace style, format code that does not parse, or minify.
Which .prettierrc keys match the controls?
Indent is tabWidth (or useTabs for Tab), Line width is printWidth, Semicolons is semi and Single quotes is singleQuote. All other options stay at Prettier's defaults, such as trailingComma set to all.
Why do two differently written files give the same output?
Prettier discards the original whitespace and line breaks and prints the program from its syntax tree. Only the code itself and the chosen options affect the result.
Is it safe to turn semicolons off?
Prettier keeps a leading semicolon on lines that start with [ or (, so the code is not merged with the previous statement. The behaviour of the program does not change.
Why is my local output different?
Your project may set extra options such as arrowParens or trailingComma, use plugins, or run a different Prettier version. Pin the version and keep the options in one .prettierrc to avoid drift.

Last updated September 27, 2026

Related tools

CSS Pretty Print Opinionated CSS pretty print with Prettier: normalises case, leading zeros, quotes and semicolons so a team's stylesheets look alike. HTML Pretty Print Opinionated HTML pretty print with Prettier: closes implied tags, enforces a line width and gives the same output for any input layout. JSON Pretty Print Pretty print JSON online with a 4-space default, 2 or 3 spaces or tabs, and see the matching JavaScript, Python, PHP and jq commands. XML Pretty Print Pretty print XML in the browser, with matching commands for xmllint, xmlstarlet, Python and .NET when it belongs in a script. YAML Pretty Print Pretty print YAML online and see the yq, PyYAML and js-yaml settings that give the same block style, key order and indent. JavaScript Escape JavaScript escape online: convert special characters into escape sequences so text is safe inside JavaScript. JavaScript Tester Run JavaScript online and see console.log, warnings, errors and tables instantly in a safe, sandboxed browser console. JavaScript Key Code Finder Press any key to see its event.key, event.code, legacy keyCode, location and modifier state for JavaScript keyboard handlers. JavaScript Minifier Minify JavaScript online with Terser to shrink file size for faster websites. React JSX Formatter Format React components and JSX online with Prettier. TypeScript Formatter Format TypeScript code online with Prettier, including interfaces, generics, decorators and type annotations. Babel Formatter Format modern JavaScript and JSX using the Babel parser and Prettier.