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.
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.
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.
How to use
- Install Prettier in your project:
npm install --save-dev prettier - Create a
.prettierrcconfig file with your preferred options (or use the defaults) - Run
npx prettier --write .to format all files, or integrate with your editor for format-on-save
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.
| Option | Default | Common Override |
|---|---|---|
| semi | true | false |
| singleQuote | false | true |
| tabWidth | 2 | 4 |
| trailingComma | 'all' | 'es5' |
| printWidth | 80 | 100 or 120 |
Related on TokRepo
- AI tools for coding — browse more developer productivity tools on TokRepo
- Automation tools — formatters, linters, and CI helpers curated on TokRepo
Common pitfalls
- Running Prettier without a
.prettierignorecan 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-prettierto 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
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.
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.
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.
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.
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)
- Prettier GitHub— Prettier supports JavaScript, TypeScript, CSS, HTML, JSON, GraphQL, Markdown and…
- Prettier Docs— Prettier is an opinionated code formatter
- eslint-config-prettier GitHub— eslint-config-prettier disables ESLint rules that conflict with Prettier
Related on TokRepo
Discussion
Related Assets
NAPI-RS — Build Node.js Native Addons in Rust
Write high-performance Node.js native modules in Rust with automatic TypeScript type generation and cross-platform prebuilt binaries.
Mamba — Fast Cross-Platform Package Manager
A drop-in conda replacement written in C++ that resolves environments in seconds instead of minutes.
Plasmo — The Browser Extension Framework
Build, test, and publish browser extensions for Chrome, Firefox, and Edge using React or Vue with hot-reload and automatic manifest generation.