ScriptsApr 12, 2026·3 min read

Prettier — Opinionated Code Formatter for Consistent Style

Prettier is an opinionated code formatter that enforces a consistent code style across your entire codebase. It supports JavaScript, TypeScript, CSS, HTML, JSON, GraphQL, Markdown, and many more languages with minimal configuration.

TL;DR
Prettier auto-formats your code so every file looks the same, no debates needed.
§01

What it is

Prettier is an opinionated code formatter that rewrites your source files to enforce a single, consistent style. It supports JavaScript, TypeScript, CSS, HTML, JSON, GraphQL, Markdown, and many other languages through plugins.

Prettier is built for teams who want to stop arguing about tabs vs spaces, trailing commas, and line length. You configure it once, integrate it into your editor or CI pipeline, and every file follows the same rules from that point forward.

§02

Why it saves time or tokens

Manual formatting eats developer hours. Code review comments about style waste everyone's attention. Prettier eliminates both problems by making formatting automatic and deterministic. The same input always produces the same output, so diffs stay clean and reviewers focus on logic instead of semicolons.

When working with AI coding assistants, Prettier ensures that generated code matches your project style without manual cleanup. This reduces the back-and-forth token cost of asking an LLM to reformat its output.

§03

How to use

  1. Install Prettier in your project: npm install --save-dev prettier
  2. Create a .prettierrc config file with your preferred options (or use the defaults)
  3. Run npx prettier --write . to format all files, or integrate with your editor for format-on-save
§04

Example

{
  'semi': false,
  'singleQuote': true,
  'tabWidth': 2,
  'trailingComma': 'es5',
  'printWidth': 80
}

With this .prettierrc, Prettier drops semicolons, uses single quotes, 2-space tabs, trailing commas in ES5-valid positions, and wraps at 80 characters.

OptionDefaultCommon Override
semitruefalse
singleQuotefalsetrue
tabWidth24
trailingComma'all''es5'
printWidth80100 or 120
§05

Related on TokRepo

§06

Common pitfalls

  • Running Prettier without a .prettierignore can reformat generated files, vendor code, or build artifacts you did not intend to touch
  • Combining Prettier with ESLint style rules causes conflicts; use eslint-config-prettier to disable overlapping ESLint rules
  • Forgetting to add Prettier to your CI pipeline means developers who skip editor integration will push unformatted code

Frequently Asked Questions

What languages does Prettier support?+

Prettier natively supports JavaScript, TypeScript, JSX, TSX, CSS, Less, SCSS, HTML, JSON, GraphQL, Markdown, and YAML. Additional languages like PHP, Ruby, Java, and XML are available through community plugins. The plugin API lets anyone add a parser and printer for new languages.

How does Prettier differ from ESLint?+

ESLint finds bugs and enforces code-quality rules like no-unused-vars or no-implicit-globals. Prettier only handles formatting: indentation, line breaks, quote style, and spacing. They complement each other. Use eslint-config-prettier to disable ESLint rules that conflict with Prettier formatting.

Can I use Prettier with AI code generation tools?+

Yes. AI assistants often produce code with inconsistent formatting. Running Prettier on generated output normalizes style instantly. Many editors run Prettier on save, so AI-generated code is reformatted the moment you paste it. This saves tokens you would otherwise spend prompting the model to fix style.

Does Prettier support format-on-save in VS Code?+

Yes. Install the Prettier VS Code extension, set Prettier as your default formatter in settings, and enable format-on-save. Every time you save a file, Prettier rewrites it to match your config. This works for all supported languages without additional setup beyond the extension.

How do I ignore files from Prettier formatting?+

Create a `.prettierignore` file in your project root. The syntax is identical to `.gitignore`. Common entries include build output directories like dist/ and node_modules/, generated files, and vendor code. You can also use `prettier-ignore` comments inline to skip specific blocks of code.

Citations (3)

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets