Course contentsShow
← Web Development
Lesson 1463 of 2,98226. Code Quality ToolsFree lesson

Configuring Auto-Format on Save

Setting up Prettier to automatically format code on save with consistent rules across your team.

Configuring Auto-Format on Save

You'll learn how to set up Prettier to automatically format your code every time you save a file, ensuring consistent styling across your entire team.

What Is Auto-Format on Save?

Auto-format on save means your code gets cleaned up and styled consistently the moment you hit Ctrl+S (or Cmd+S). Think of it like autocorrect for your code—instead of manually running Prettier every time, your editor does it for you invisibly. This eliminates formatting debates, reduces cognitive load, and ensures everyone's code looks identical regardless of their personal habits.

How It Works

When you enable auto-format on save with Prettier, your editor (like VS Code) watches for save events. The moment you save, it calls Prettier with your project's configuration rules, reformats the file in memory, and writes the clean version to disk. You don't see the before—only the after.

This works because VS Code (covered in the previous lesson) has built-in support for "format on save" actions, and Prettier integrates as the formatter provider.

Setting It Up in VS Code

You've already installed the Prettier extension. Now add this to your workspace settings (.vscode/settings.json in your project root):

{
  "editor.formatOnSave": true,
  "editor.defaultFormatter": "esbenp.prettier-vscode"
}

The first line enables formatting on save. The second tells VS Code to use Prettier as the formatter (not the built-in one or another extension).

Why This Matters for Teams

When every team member has auto-format on save enabled with the same Prettier config, you get zero formatting differences in pull requests. No more whitespace changes cluttering your diffs, no more style arguments in code reviews.

Key Takeaway: Auto-format on save with Prettier removes formatting friction, keeps your codebase consistent, and lets you focus on logic instead of spacing.