Skip to content
Latchkey

What Is Prettier? The Opinionated Code Formatter Explained

Prettier is an opinionated code formatter that reprints your code in a consistent style automatically, ending arguments about formatting.

Prettier takes your code and reformats it to a single consistent style, regardless of how it was written. By removing formatting decisions from human hands, it eliminates style debates in code review and keeps an entire codebase looking uniform.

What Prettier is

Prettier is a code formatter supporting JavaScript, TypeScript, CSS, HTML, JSON, Markdown, and more. It parses code into an AST and reprints it from scratch using its own rules, so the original spacing and line breaks do not matter. It has few configuration options by design.

How it differs from a linter

A linter like ESLint finds problems and can enforce some stylistic rules; a formatter only rewrites layout. The two are complementary: Prettier owns formatting, ESLint owns code-quality rules. Configs like "eslint-config-prettier" turn off ESLint's stylistic rules so the two tools do not fight.

A usage example

Check formatting in CI, or write it locally.

Common Prettier commands
# fail if any file is not formatted (use in CI)
npx prettier --check .

# rewrite files to the canonical format
npx prettier --write .

Role in CI/CD

In CI, "prettier --check" verifies every file matches the canonical format and exits non-zero if not, failing the build on unformatted code. This guarantees the whole repository stays consistent and keeps diffs clean. Many teams also run Prettier on a pre-commit hook so CI rarely catches anything.

Alternatives

Biome includes a fast Rust-based formatter that aims to replace Prettier and ESLint together. dprint is another fast, pluggable formatter. Language-specific formatters (gofmt, rustfmt, Black for Python) play the same role in their ecosystems. Prettier remains the default for the JavaScript world.

Key takeaways

  • Prettier reprints code in one consistent, opinionated style.
  • It handles formatting; ESLint handles code-quality rules.
  • Use "prettier --check" in CI to fail builds on unformatted code.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →