prettier

v3.8.1 MIT

Prettier is an opinionated code formatter

Weekly Downloads
63.9M
Stars
51.7K
Forks
4.7K
Open Issues
1.5K
Gzip Size
1.0 MB
Unpacked Size
8.6 MB
Dependencies
1
Last Updated
2mo ago

prettier Download Trends

Download trends for prettier090.2M180.4M270.6M360.8MFeb 2025MayAugNovFebApr 2026
prettier

About prettier

Prettier is an opinionated code formatter designed to eliminate stylistic disagreements in codebases. It addresses the core problem of inconsistent code formatting, which can arise from different developer preferences, team standards, or editor configurations. By enforcing a single, consistent style, Prettier reduces the need for manual code review of stylistic issues and improves code readability across the entire project.

Its philosophy centers on minimizing configuration and maximizing developer productivity. Prettier aims to be a "zero configuration" tool, meaning it applies sensible defaults that work well for most projects without requiring extensive setup. This approach makes it accessible to a broad audience, from individual developers to large teams working on complex applications. The primary goal is to allow developers to focus on writing logic rather than debating code aesthetics.

Key to Prettier's operation is its Abstract Syntax Tree (AST) parser. It parses code into an AST, then prints it back out according to its own formatting rules. This process ensures that formatting is applied intelligently, respecting code structure rather than just applying simple text transformations. While there isn't a direct public API for end-users to "call" formatting logic from within application code, its command-line interface (CLI) and integration with build tools are the primary interaction points.

Prettier integrates seamlessly into various development workflows and ecosystems. It is commonly used with linters like ESLint (often with the `eslint-plugin-prettier` to disable ESLint's formatting rules and let Prettier handle them) and can be configured to run automatically on commit via tools like Husky and lint-staged. It supports a wide range of languages and file types, including JavaScript, TypeScript, CSS, SCSS, Less, HTML, JSON, GraphQL, and Markdown, making it versatile for full-stack projects.

The package has an unpacked size of 8.6 MB and a gzipped bundle size of 1.0 MB. While this size might seem substantial for a formatter, it reflects the comprehensive parsing and printing logic required for its broad language support and opinionated formatting. The tool is mature and widely adopted, with 71.1 million weekly downloads and 51.6K GitHub stars, indicating a stable and actively maintained project.

One limitation to be aware of is Prettier's "opinionated" nature. While its defaults are generally well-received, it does not offer extensive customization for stylistic choices. For developers or teams who require highly specific, non-standard formatting rules that deviate significantly from Prettier's defaults, it might not be the ideal solution. In such niche cases, manually formatting or exploring more configurable tools might be necessary, though this often reintroduces the very problems Prettier aims to solve.

When to use

  • When enforcing consistent code style across a JavaScript, TypeScript, CSS, HTML, or Markdown codebase.
  • When aiming to reduce time spent on code reviews by automating stylistic checks.
  • When integrating with pre-commit hooks using tools like Husky to ensure formatted code is committed.
  • When working in a team environment where diverse developer preferences could lead to stylistic inconsistencies.
  • When leveraging editor integrations (e.g., VS Code, JetBrains IDEs) for automatic code formatting on save.
  • When you need to format configuration files like JSON or YAML consistently alongside source code.

When NOT to use

  • If your project requires highly granular and non-standard formatting rules that Prettier does not support out-of-the-box.
  • If you are working with a codebase where stylistic debates are considered a feature rather than a problem.
  • If the 1.0 MB gzipped bundle size is a critical concern for a very constrained runtime environment where every kilobyte matters significantly.
  • If you only need to enforce basic indentation and line break rules and prefer a lighter, more configurable tool.
  • If your primary goal is to enforce complex code quality rules beyond simple formatting, where a dedicated linter without formatting capabilities might be more appropriate.

prettier Alternatives

prettier Categories