Prettier vs an online formatter: when should I use which?

Dark navy cover card with the title 'Prettier vs an online formatter: when should I use which?' in white and a green accent bar

Use Prettier for any code that lives in a project, and an online formatter for code you only need to read. Prettier runs from your editor, your pre-commit hook and CI, so every file in the repo ends up in one style. An online formatter is faster for a one-off snippet, a minified API response or a log line, where you want readable output in seconds and nothing gets committed.

Prettier vs online formatter: the short answer

The rule of thumb in the Prettier vs online formatter question is simple: if the formatted code goes back into a repository, use Prettier; if it only goes into your eyes, use whatever is fastest.

Situation Better choice Why
Code in a team repo Prettier Shared config, same output for everyone
Format on save in your editor Prettier Editor extension runs it locally
Checking formatting in CI Prettier --check fails the build
Minified API response you need to read Online formatter Paste, read, close
Snippet from a ticket or chat Online formatter No project to format it against
Locked-down or borrowed machine Online formatter Nothing to install
Code that contains secrets Prettier (local) Nothing leaves your machine

What Prettier is built for

Prettier is built to end style arguments in a codebase. The Prettier docs describe it as an opinionated code formatter for JavaScript, TypeScript, JSX, CSS, SCSS, Less, HTML, JSON, GraphQL, Markdown, YAML and more.

The project's own explanation of why it exists is blunt: the top reason was to stop wasting time debating style nits. You run Prettier and accept its style. The option philosophy goes further. Prettier keeps a few options for historical reasons, won't add more, and no longer accepts option requests, because style debates just turn into debates over options.

That design only pays off when Prettier runs everywhere the code is touched. The install guide sets it up that way:

  1. Install it as an exact-version dev dependency: npm install --save-dev --save-exact prettier.
  2. Add a .prettierrc (even an empty one tells editors the project uses Prettier) and a .prettierignore for build output.
  3. Run npx prettier . --write once to format everything.
  4. Add npx prettier . --check to CI so unformatted code fails the build.
  5. Optionally run prettier --write --ignore-unknown from a husky and lint-staged pre-commit hook.

The same guide says you get the most from Prettier by running it from your editor. The VS Code extension respects editor.formatOnSave and uses the Prettier version from your project's local dependencies. For JSON files specifically, see how to format JSON in VS Code.

What an online formatter is good for

An online formatter is good for code that isn't part of a project yet, or never will be.

  • A one-line JSON response from curl or a webhook log, when you need to find one field.
  • Minified scripts from a third-party site you're debugging. Here's how to read minified JS.
  • That snippet from a bug report or chat message with tabs and spaces mixed.
  • Any machine where you can't install Node, like a locked work laptop or a client's computer.

None of these need a .prettierrc, a pinned version or CI. Setting up a project to indent one blob of JSON is a bad trade.

Why online output doesn't match your project

Online formatter output often won't match your repository, even when the tool runs Prettier itself. Two things cause this: config and version.

Config. Prettier's browser documentation says the standalone build only formats the code and has no support for config files, ignore files, CLI usage, or automatic loading of plugins. A web page running Prettier never reads your .prettierrc. If your project uses "singleQuote": true and the online tool uses the defaults, every string comes back with double quotes.

Version. Prettier's install guide recommends pinning an exact version because even a patch release can result in slightly different formatting. A website runs whatever version it last deployed, not the one in your lockfile.

Say you paste a function into a web formatter, copy the result back into src/api.ts, and open a pull request. You meant to change one line. The diff touches the whole file, and reviewers have to dig the real change out of quote and line-wrap noise. Prettier in the project would have given you the one-line diff.

Local setups can drift too. The VS Code extension reads settings in priority order: Prettier config file, then .editorconfig, then VS Code settings, which it ignores if any other configuration is present. A machine with no project config formats differently from one that has it.

Privacy: where your code goes

Prettier running locally never sends your code anywhere. An online formatter might, and you can't tell from the page design.

Before pasting anything sensitive, open DevTools, switch to the Network tab and format a test snippet. If a request goes out carrying your code, close the tab. The full check is in is it safe to paste JSON into online formatters?

The formatters on this site run in the page. The tool code makes no network requests with what you paste, and the input isn't saved. The pages do load Google Analytics, Google Fonts and Font Awesome from third-party servers, so they're not fully offline on the first visit. Production credentials don't go into any web tool, this one included.

When I reach for each one

My take: the moment code has a home in a repo, Prettier formats it, and an online formatter is only for reading. I never copy output from a browser formatter back into a project.

For JSON I need to read right now, I use the JSON formatter here, which indents with 2 spaces by default and shows the JSON.parse error when the input is broken. That error message is often the real reason I opened the tool. If it says the JSON is invalid, fixing invalid JSON covers the usual causes.

Limitations of both

Each option has a gap you should know about. Prettier won't fix broken code: if the parser can't read the file, it reports an error instead of guessing. It also needs Node and a project to be useful, which is overkill for one snippet.

The formatters on this site have a harder limit. They are not Prettier, so their output won't match a Prettier-formatted codebase character for character.

FAQ

Can an online formatter replace Prettier?

Not for a project. An online tool can't format every file in a repo, run on save, or fail a CI build when code isn't formatted. It's a good fit for snippets you only need to read.

Why does pasted Prettier output differ from my project?

The online version doesn't know your .prettierrc settings or which Prettier version your project pins. Prettier's own docs say even a patch release can format slightly differently.

Is it safe to paste code into an online formatter?

Only if the tool formats in your browser and doesn't upload what you paste. Check the Network tab while you format. For secrets, don't paste them into any web tool.

Do I need Prettier if my editor already formats code?

On a team, yes. Editor defaults differ from person to person, while a Prettier config committed to the repo gives everyone, and CI, the same output.

Sources