Skip to content

Guide · Open source

How to use Prettier: install, format code and run it in CI

Updated · written with AI from the project's own documentation and checked against our catalogue data

Prettier is an opinionated code formatter. It reads your source code, parses it and reprints it using its own fixed rules, wrapping lines that exceed a maximum length. This guide covers what it does, which languages it supports, and where you can run it so your team's code looks the same.

Prettierprettier/prettier · ★ 52.4k · MIT

Quick start

  1. 1Check Node.js. Confirm that Node.js is installed, since the README lists it as the prerequisite.
  2. 2Install Prettier. Follow the package manager steps at https://prettier.io/docs/install. The README excerpt does not include the exact command.
  3. 3Format a file. Run Prettier on your source files so it reprints them with its fixed rules and wraps long lines.
  4. 4Automate formatting. Set up format-on-save in your editor, a pre-commit hook, or a CI check using the linked docs pages.

What does Prettier do to your code?

Prettier parses your code and re-prints it with its own rules. It takes the maximum line length into account and wraps code when a line is too long.

The README example takes one long function call on a single line and reprints it with each argument on its own line, with a trailing comma after the last one.

foo( reallyLongArg(), omgSoManyParameters(), IShouldRefactorThis(), isThereSeriouslyAnotherOne(), );

Which languages does Prettier support?

The README lists support for JavaScript, TypeScript, Flow, JSX, JSON, CSS, SCSS, Less, HTML, Vue, Angular, GraphQL, Markdown and YAML.

If your language is not listed, the README links to a plugins page. Check that page for a plugin before you assume it is supported.

  • JavaScript, TypeScript, Flow, JSX, JSON
  • CSS, SCSS, Less
  • HTML, Vue, Angular
  • GraphQL, Markdown, YAML

How do you install Prettier?

Prettier is installed through a package manager. The README excerpt says Node.js is required but does not state a Node.js version, so check the install docs for that detail.

The README excerpt does not include the exact install command. Follow the install guide on the official site rather than copying a command from this page.

  • Make sure Node.js is installed on your machine.
  • Open the official install guide at https://prettier.io/docs/install.
  • Follow the package manager steps listed there.

How do you run Prettier on save, in pre-commit hooks and in CI?

The README says Prettier can run in your editor on save, in a pre-commit hook, or in CI environments. Each option keeps formatting consistent without manual review comments.

Editor setup is described on the editors docs page. Pre-commit setup is on the precommit docs page. CI usage is covered on the CLI docs page under the list-different option.

  • Editor on save: see https://prettier.io/docs/editors
  • Pre-commit hook: see https://prettier.io/docs/precommit
  • CI check: see https://prettier.io/docs/cli#list-different

What are Prettier's limits?

Prettier is opinionated and offers limited options. If you want to control every formatting detail, it may not fit your project.

The README links to an Options page, which was not reviewed for this guide. Read it before deciding how much you can customize.

  • Best fit: teams that want one shared style without writing their own rules.
  • Poor fit: projects that need to customize every formatting detail.
  • Languages outside the README list may need a plugin.

What people use it for

  • Keeping JavaScript and TypeScript code in one style across a team.
  • Formatting CSS, SCSS or Less files consistently in a front-end project.
  • Formatting Markdown and YAML files in a repository.
  • Blocking unformatted code with a pre-commit hook or CI check.

Frequently asked questions

Is Prettier free to use?

Prettier is released under the MIT licence, as listed in the README. Check the LICENSE file in the repository for the full terms.

What do I need to install Prettier?

The README lists Node.js as the prerequisite. It does not state a Node.js version, so check the install docs at https://prettier.io/docs/install.

How do I install Prettier?

Install it through a package manager following the official install guide. The README excerpt does not include the exact install command.

Which languages does Prettier support?

The README lists JavaScript, TypeScript, Flow, JSX, JSON, CSS, SCSS, Less, HTML, Vue, Angular, GraphQL, Markdown and YAML. Other languages may be supported through plugins.

What are alternatives to Prettier?

Comparable projects include ESLint, Biome, dprint and StandardJS. This guide did not compare them in detail, so review each one against your needs.

Can I customize Prettier's formatting rules?

Prettier is opinionated and offers limited options. The README links to an Options page, which was not reviewed here, so check it for what you can change.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

Prettier suits teams that want one shared code style without writing their own formatting rules, especially for JavaScript, TypeScript, CSS and Markdown projects. If you need to control every formatting detail, pick a tool with more configuration options instead.

Install options & downloads