VS Code

How to Use Prettier in VSCode to Format Code

How to Use Prettier in VSCode to Format Code

Installing the Prettier extension doesn’t do much on its own. VSCode keeps using its built-in formatter until you set Prettier as the default formatter and turn on format on save, and most broken setups I’ve seen are missing one of those two settings.

Prettier reads your file into a syntax tree and prints it back out in its own style, so it doesn’t matter how messy the original was. JavaScript, TypeScript, CSS, HTML, JSON, Markdown and YAML all come out the same way for everyone. A .prettierrc file in the repository then fixes options such as printWidth and singleQuote for every contributor.

What catches teams off guard is version drift. Prettier’s install documentation (2026) states that even a patch release can change formatting slightly, which is why it recommends pinning an exact version. I’d do that on day one, before anyone commits a formatted file.

How to Install the Prettier Extension in VSCode

In the Extensions view, search for “Prettier – Code formatter” and check that the ID reads esbenp.prettier-vscode before you click Install.

That check matters more than it sounds. Several lookalikes carry “Prettier” in their names. The real one is published by Prettier and shows more than 73 million installs on the Visual Studio Marketplace (listing checked November 2026).

Installing from the Extensions view and the terminal

  1. Open the Extensions view with Ctrl+Shift+X (Cmd+Shift+X on macOS).
  2. Type Prettier, pick the result published by Prettier, and check the ID.
  3. Click Install, then reload the window if VSCode asks.

From the terminal it’s one line: code --install-extension esbenp.prettier-vscode. Quick Open (Ctrl+P) also takes ext install esbenp.prettier-vscode, if you’d rather not leave the editor.

If the editor is still mostly stock, a broader look at VS Code extensions is worth a read.

Which Prettier version the extension runs

The extension doesn’t always run the Prettier you think it does. It looks for a project-local copy in node_modules first, and VSCode asks you to confirm loading it the first time.

With no local install, it falls back to the copy bundled inside the extension. That bundled copy is also the only one used in untrusted workspaces.

A global npm or yarn install gets ignored unless prettier.resolveGlobalModules is true. Leave it off. The extension README warns it can slow formatting, especially on Windows with attached network drives.

Pin the project copy with npm install prettier -D --save-exact. The bundled copy moves with the extension, not with your lockfile, and a teammate on a different Prettier version will produce diffs nobody asked for.

How to Set Prettier as the Default Formatter

The setting is editor.defaultFormatter, and the value you want is esbenp.prettier-vscode. VSCode ships built-in formatters for JavaScript, TypeScript, JSON, HTML and CSS, so after you install Prettier there are two candidates and VSCode wants you to pick one.

The quick way is to run Format Document on any file. VSCode asks which formatter to use. Click Configure and choose Prettier – Code formatter.

Or write the setting yourself. If you have never touched the file, here is how to open settings.json in VSCode.

{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}

Write one block per language. The extension README states that a combined key such as [javascript][typescript] is not accepted for this setting. It looks like it should work, which is exactly why people get stuck on it.

Where you put the setting matters as much as the value. User settings apply to every project on your machine.

Workspace settings live in .vscode/settings.json and travel with the repository through Git. On a team project that’s the better place, since a teammate who never set a personal default still ends up formatting with Prettier.

You can also keep Prettier everywhere except one language by giving that language a different formatter in its own block. The README shows the reverse pattern too, with another formatter globally and Prettier only for JavaScript.

How to Format Code with Prettier in VSCode

YouTube player

Most of the time you’ll either run Format Document by hand or let format on save handle it. The shortcuts below come from the Visual Studio Code documentation, plus the standard Command Palette keys.

ActionWindowsmacOSLinux
Format DocumentShift+Alt+FShift+Option+FCtrl+Shift+I
Format SelectionCtrl+K Ctrl+FCmd+K Cmd+FCtrl+K Ctrl+F
Command PaletteCtrl+Shift+PCmd+Shift+PCtrl+Shift+P

Format Selection only covers JavaScript, JSX, TypeScript, TSX, JSON, GraphQL and Handlebars, according to the extension README. In any other language, format the whole document.

Formatting automatically

editor.formatOnSave formats the file each time you save. It’s off by default. The extension respects it, including per language.

editor.formatOnPaste is off by default too, and it only works with formatters that can handle a range. Then there’s source.fixAll.prettier, a code action that goes under editor.codeActionsOnSave. You can ignore that one until ESLint joins the setup.

VSCode can autoformat files on save with whichever formatter is installed, and Prettier plugs into that same setting. Scope it to the languages you actually want formatted:

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

Turn on format on save. I leave format on paste off, because it re-wraps pasted code before I’ve even decided where it belongs.

Which Languages and Files Does Prettier Format?

Out of the box, the list is longer than most people expect. Anything not on it needs a plugin or gets skipped.

Supported languages

  • JavaScript, JSX and Flow
  • TypeScript
  • CSS, SCSS and Less
  • HTML, Vue, Angular and Handlebars
  • JSON
  • Markdown and YAML
  • GraphQL

Plugins add more languages, but Workspace Trust blocks plugins and local modules in untrusted workspaces (extension README).

Ignoring files and code

Put a .prettierignore file in the project root. It uses the same pattern syntax as a gitignore file, and Prettier also reads the .gitignore in the directory where it runs, per the Prettier docs.

Some folders are skipped by default: .git, .jj, .sl, .svn, .hg and node_modules. Your own entries will mostly be whatever the build spits out:

  • build/ and dist/
  • *.min.js
  • package-lock.json and pnpm-lock.yaml

To point the extension at a different ignore file, use prettier.ignorePath. Setting it to null stops the extension from reading ignore files at all. It’s disabled in untrusted workspaces.

For one stubborn block, a comment does the job. Each language has its own syntax:

LanguageCommentSkips
JavaScript// prettier-ignoreNext node
HTML<!-- prettier-ignore -->Next node
CSS/* prettier-ignore */Next rule
Markdown<!-- prettier-ignore -->Next block
YAML# prettier-ignoreNode on the next line

JSX uses {/* prettier-ignore */} and skips the next element.

How to Configure Prettier Options

Prettier reads options from its own config file or from .editorconfig, and the VSCode extension adds its own settings on top. On a shared project, use the config file.

Config file formats

  • .prettierrc, written in JSON or YAML, with no extension needed
  • .prettierrc.json, .yaml or .toml if you want the format spelled out
  • prettier.config.js, .mjs or .cjs, which is a JavaScript module that exports the options
  • a “prettier” key inside package.json
{
"semi": false,
"singleQuote": true,
"tabWidth": 4
}

The extension also exposes settings such as prettier.singleQuote. Those only apply while the extension runs, not when Prettier runs from the command line (extension README). So the CLI and CI never see them, and that’s how “works on my machine” formatting bugs start.

Defaults worth knowing

OptionDefaultControlsChange it when
printWidth80Preferred line lengthWide monitors, long JSX
tabWidth2Spaces per indentTeam uses 4
semitrueSemicolons at line endsNo-semicolon style
singleQuotefalseQuote style in stringsSingle-quote codebase
trailingComma“all”Commas in multiline listsOlder runtimes

The Prettier 3.0 release (July 5, 2023) changed the trailingComma default from “es5” to “all”. Tutorials written before that date still show the old value.

Don’t treat printWidth as a hard limit. The Prettier docs say lines can come out shorter or longer, which is why it does not replace ESLint’s max-len. A max_line_length entry in .editorconfig sets it too, unless a Prettier config overrides it.

On mixed Windows and Mac teams, check two more defaults. useTabs is false and endOfLine is “lf”, so CRLF files from a Windows checkout get rewritten on format.

Per-glob overrides

The overrides key applies options to matching files only. Here CSS gets four spaces while everything else keeps two:

{
"tabWidth": 2,
"overrides": [
{
"files": "*.css",
"options": { "tabWidth": 4 }
}
]
}

Which Setting Wins When Configuration Sources Conflict?

The Prettier config file, every time. The extension README publishes the full order:

  1. Prettier configuration file (.prettierrc and its variants)
  2. .editorconfig
  3. VSCode settings, ignored if any other configuration is present

This is the one that trips people up. Set prettier.singleQuote in settings.json inside a repository that already has a .prettierrc, and the setting is simply ignored, according to the extension README.

Keep personal preferences in your VSCode settings and project rules in the config file, since the file always wins anyway.

Finding the config that actually applies

Prettier uses the config file nearest to the file being formatted. So a monorepo with several .prettierrc files formats different folders with different options, which can look random until you know this.

npx prettier --find-config-path src/app.js

If .editorconfig turns out to be the culprit, edit it or set prettier.useEditorConfig to false.

Requiring a config, or forcing one

prettier.requireConfig defaults to false. Set it to true and a file only formats when a Prettier config file exists, though untitled files still use VSCode settings. It’s handy if you open a lot of repositories and only want formatting in the ones that opted in.

prettier.configPath goes the other way. It points at one config file that always gets used, and local config files are ignored. The README suggests a ~/.prettierrc as the better global default.

What Workspace Trust switches off

Restricted Mode changes which sources apply. On top of ignorePath, the README restricts configPath, prettierPath, resolveGlobalModules, documentSelectors and withNodeModules, and it forces useEditorConfig off.

In practice, any option that came from .editorconfig stops applying in a restricted window. The same file can format differently there than it does in your trusted project.

Trust a folder through the Manage link in the Restricted Mode banner, or run Workspaces: Manage Workspace Trust from the Command Palette. VSCode’s own docs advise leaving unfamiliar folders in Restricted Mode, so only trust code you know.

How to Use Prettier with ESLint in VSCode

Keep them as two separate jobs and add eslint-config-prettier, which turns off the ESLint rules that clash with Prettier’s output. Prettier’s own docs prefer running Prettier directly over routing it through ESLint.

Prettier handles formatting. ESLint keeps linting for bugs and unused code.

Turning off conflicting rules

With flat config, import eslint-config-prettier/flat and add it after the configs whose rules it should override. On a legacy .eslintrc, add “prettier” to the extends array, and make it the last entry.

Order matters. In flat config, any rules you define after eslint-config-prettier switch the conflicting ones back on.

To check for leftovers, run npx eslint-config-prettier path/to/main.js. It exits with 0 when clean and 2 when conflicting rules remain.

A few rules need care even then. max-len, no-mixed-operators and no-unexpected-multiline can clash with Prettier’s output, and quotes, curly and no-tabs need matching options if you turn them back on (eslint-config-prettier README).

Running both on save

Set both code actions to “explicit” so Prettier runs before ESLint applies its fixes:

{
"editor.codeActionsOnSave": {
"source.fixAll.prettier": "explicit",
"source.fixAll.eslint": "explicit"
}
}

Watch for one gotcha. If another default formatter is set, such as ESLint with a Prettier plugin, source.fixAll.prettier won’t run unless it’s “explicit” or “always”. Per the extension README, that requirement is what prevents double formatting.

Separate run or plugin?

I’d go with the separate run plus eslint-config-prettier. Prettier runs directly, so it’s faster, and you don’t get red squiggles every time spacing is off. There are also fewer layers to break. The cost is two steps in the editor and in CI, and you have to remember that the config sits last.

eslint-plugin-prettier does have one real advantage: it reuses an existing ESLint setup and its editor integrations. Everything else about it is worse. Formatting differences show up as a wall of red squiggles, it’s slower than running Prettier directly, and it adds another place for things to go wrong.

The Prettier docs call the plugin route “generally not recommended”, though they note it was especially useful when Prettier was new. Plenty of setup tutorials still install it by default. Skip it unless an ESLint-only pipeline leaves no room for a second step.

How to Keep Prettier Settings Consistent Across a Team

The editor alone won’t keep a team consistent, because sooner or later someone commits from a machine without the extension. Back it up with a pre-commit hook and a CI check.

LayerRunsCatches
EditorOn saveFiles you edit
Pre-commit hookOn commitStaged files from editors without Prettier
CI checkOn every pushAnything that slipped through

A continuous integration job runs npx prettier . --check, which reports unformatted files without rewriting them. The Prettier docs recommend this to avoid merge conflicts and collaboration problems.

Their install example pins an exact version (3.10.1 as of November 2026), so the CI check and every editor agree.

What goes in the repository

  • .prettierrc and .prettierignore
  • .vscode/settings.json with the formatter settings from the earlier sections
  • .vscode/extensions.json, so VSCode suggests the extension on clone
  • Prettier in devDependencies
{
"recommendations": ["esbenp.prettier-vscode"]
}

Dev containers take the same two entries, settings and extensions, under customizations.vscode.

Pre-commit hooks

lint-staged is the better fit if ESLint or Stylelint is already in the project. It’s also the one to pick when developers stage hunks with git add --patch. Running npx mrm@2 lint-staged installs Husky and lint-staged and writes the config into package.json.

pretty-quick formats entire files that are changed or staged. The catch is partially staged files, which get formatted in full.

Most hook examples in the Prettier docs pass --ignore-unknown, so files Prettier can’t parse are skipped instead of failing the commit.

Why Is Prettier Not Formatting in VSCode?

Before touching any settings, open the Prettier output panel. It shows the error and tells you which Prettier copy ran.

Reading the output panel

Click “Prettier” in the status bar at the bottom right to open the panel. Look for the version line. “Using bundled Prettier” means the built-in copy ran, not your project’s.

If the panel doesn’t tell you enough, turn on prettier.enableDebugLogs, reload VSCode, retry the file, and copy the full output.

Symptoms, causes and fixes

SymptomLikely causeFix
Save does nothingNo default formatter for that languageAdd the language block with esbenp.prettier-vscode
One file is skippedMatch in .prettierignore or ignorePathRemove the pattern or repoint ignorePath
A whole repo never formatsrequireConfig is true, no config fileAdd .prettierrc or set it to false
Plugin failsUntrusted workspace, or plugin not installed locallyTrust the folder, install plugin and Prettier locally
Local Prettier not foundnode_modules missingRun your package manager’s install

A syntax error stops formatting too, because Prettier parses a file before it prints it. The panel shows the SyntaxError with its position. The other common cause is an outdated Prettier version, and the README’s fix for that is just to upgrade.

Checking whether the extension is at fault

Run Prettier from the integrated terminal: npx prettier --write yourfile.js.

Same result from the CLI? Then the problem sits in Prettier core, not in the extension (extension troubleshooting guide).

Prettier in VSCode FAQ

How do I format an entire project with Prettier?

From the project root, run npx prettier --write . in the terminal. Add a .prettierignore file first. The Prettier docs recommend it so the run skips build output and lockfiles.

Can I change the Format Document keyboard shortcut?

Yes. Open Keyboard Shortcuts with Ctrl+K Ctrl+S (Cmd+K Cmd+S on macOS), search for Format Document, and assign a new key binding.

The binding belongs to VSCode, so it applies to whichever formatter is the default, not only Prettier.

How do I sort Tailwind classes with Prettier?

Install prettier-plugin-tailwindcss locally next to Prettier, then list it in the plugins array of your .prettierrc.

Plugins only run in trusted workspaces. If the Prettier output panel says the workspace isn’t trusted, trust the folder and format again.

Does Prettier format code inside Markdown files?

By default, yes. The embeddedLanguageFormatting option defaults to “auto”, so Prettier formats embedded code it can identify, such as fenced code blocks.

Set the option to “off” and those blocks stay untouched.

Reformatting an Existing Codebase in One Commit

Adding Prettier to an old project? Do the reformat in one dedicated commit, then list that commit in .git-blame-ignore-revs.

  1. Commit .prettierrc and .prettierignore.
  2. Format the whole project and change nothing else.
  3. Record that commit’s hash in the ignore list.

Git applies the list through git config blame.ignoreRevsFile .git-blame-ignore-revs, one full hash per line, and GitHub reads a root-level file of that name (Git and GitHub documentation, November 2026).

Without it, blame becomes useless. git blame attributes each line to the last commit that changed it, so one sweeping format commit would end up owning most of the codebase.

The downside is merge conflicts, since that commit touches nearly every file. Merge or rebase open branches first. And keep the commit free of logic changes so no real edit hides inside it.

Bogdan Sandu

Stay sharp. Ship better code.

Every week: one curated article, one tool worth knowing, one tip you can use tomorrow. No noise, no padding.