Prettier is an opinionated code formatter. It automatically formats your code so that it follows consistent style rules. It supports many programming languages, including:
- JavaScript / TypeScript
- HTML / CSS / SCSS
- JSON / YAML / Markdown
- Python (via plugins)
- And more
It does not check for errors or bugs—it just makes your code look clean and consistent.
Why People Use Prettier
- Consistency: Everyone on the team uses the same formatting, so code looks uniform.
- Saves time: No more arguing over tabs vs. spaces, quotes, or line breaks.
- Integration: Works with editors like VS Code, Sublime Text, and tools like ESLint.
- Reduces diffs: Git diffs are cleaner because formatting differences are removed.
How It Works
- You install it via npm:
npm install --save-dev prettier
- You can format files manually:
npx prettier --write .
- Or integrate it with your editor so it formats code automatically on save.
Example
Before Prettier:
function hello(name){console.log("Hello, "+name)}
After Prettier:
function hello(name) {
console.log("Hello, " + name);
}
Notice the consistent spacing, indentation, and line breaks.