Everyday Toolkit

Automated Formatting in VS Code: A Complete Guide

Published 2026-07-27

Updated Jul 2026

Some links on this page are affiliate links. If you buy through them we may earn a small commission at no extra cost to you. We only recommend what we'd use.

Key takeaways
  • Automated formatting saves time & reduces errors
  • VS Code extensions customize your coding style
  • Prettier handles basic formatting
  • ESLint enforces coding rules
Automated Formatting in VS Code: A Complete Guide
Photo: MONUSCO (BY-SA) via Openverse

Automated Formatting in VS Code: A Complete Guide

Automating code formatting in Visual Studio Code relies on built-in editor settings and extensions like Prettier and ESLint to clean, indent, and structure code upon saving or typing. Setting up automated formatting keeps project files consistent across teams and cuts down on manual review tediousness.

🛍 Ready to buy? Check current prices on Amazon for the picks in this guide.

What Does "Auto Format" Mean in VS Code?

Auto formatting in VS Code automatically cleans up code structure—adjusting indentation, bracket positioning, quote styles, and line breaks—every time you trigger a save or shortcut. Instead of fixing spacing manually, the editor relies on configured underlying rules to keep your codebase clean and standard across entire engineering teams instantly.

Formatting code manually is a notorious time sink. It distracts from building features and leads to useless diffs in Git pull requests where team members argue over tabs versus spaces. By offloading layout rules to VS Code, your editor cleans up messy code the second you hit save.

VS Code offers built-in formatting engines for languages like HTML, CSS, and JSON, but complex projects usually require external tools. Prettier and ESLint step in here. Prettier reshapes layout geometry, while ESLint inspects code syntax and execution logic. Understanding how these tools complement each other is key to a frictionless development experience.

Setting Up Prettier for Automatic Formatting

Automated Formatting in VS Code: A Complete Guide
Photo: Software: Alliance for Open Media Screenshot: Veikk0.ma via Wikimedia Commons

Setting up Prettier requires installing its official VS Code extension, selecting it as your default document formatter, and defining your preferences inside a `.prettierrc` configuration file. Once configured, Prettier handles all visual layout mechanics across JavaScript, TypeScript, HTML, CSS, and JSON automatically whenever you save files.

To begin, open the VS Code Extensions panel (`Ctrl+Shift+X` or `Cmd+Shift+X`), search for "Prettier - Code Formatter", and install it. Next, open your editor settings to tell VS Code to use Prettier as its primary formatting engine.

Rather than relying on global settings that might differ from a developer colleague's workstation, create a `.prettierrc` JSON or YAML file in your project root. Here's a standard `.prettierrc` example:

{
  "semi": true,
  "singleQuote": true,
  "tabWidth": 2,
  "trailingComma": "es5",
  "printWidth": 80
}

Adding this file to your Git repository ensures every contributor who opens the project generates identical layout structures without extra onboarding steps.

Leveraging ESLint for Code Style and Linting

ESLint acts as a static analysis engine that checks your code logic and syntax structure against established quality rules. While formatters adjust visual whitespace, ESLint flags buggy syntax patterns, unused variables, improper scope definitions, and unsafe code, catching subtle runtime bugs long before your code reaches production environments.

Where Prettier enforces aesthetics, ESLint protects functionality. It catches undeclared variables, accidental global scope pollution, missing return statements, and dangerous type coercions.

To set it up, install the official ESLint extension in VS Code alongside your project's local ESLint dependency. Add an `.eslintrc.json` config file in your project root to specify your ruleset:

{
  "env": {
    "browser": true,
    "es2021": true
  },
  "extends": "eslint:recommended",
  "rules": {
    "no-unused-vars": "warn",
    "no-console": "off"
  }
}

With the extension running, ESLint highlights problematic logic with red and yellow squiggly underlines directly in your editor workspace as you code.

Combining Prettier and ESLint: Best Practices

The best way to run Prettier and ESLint together is delegating layout formatting to Prettier while letting ESLint manage code logic rules. You can prevent rule collisions by using `eslint-config-prettier`, which disables formatting-related linter checks so both tools run in harmony without throwing conflicting editor warnings.

Without proper isolation, ESLint might complain about single quotes while Prettier changes double quotes to single quotes, leading to infinite saving loops. We resolve this by letting each utility stick to its primary strength.

Install `eslint-config-prettier` via npm or yarn, and update your `.eslintrc.json` file so `prettier` sits at the end of the `extends` array:

{
  "extends": [
    "eslint:recommended",
    "prettier"
  ]
}

This simple configuration disables all ESLint stylistic rules. ESLint focuses on code safety and performance bugs, while Prettier owns bracket spacing, trailing commas, and line wrapping.

Customizing Your Auto-Formatting Workflow

You can customize VS Code formatting by altering settings like `editor.formatOnSave`, setting language-specific overrides in `settings.json`, or assigning custom formatting keyboard shortcuts. These configurations let you control whether formatting triggers on save, paste, or typing, tailoring the environment to your precise developer workflow requirements.

To configure your workspace globally or per-project, open your `settings.json` file in VS Code (`Preferences: Open User Settings (JSON)` from the Command Palette). Add these base configurations:

{
  "editor.formatOnSave": true,
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": "explicit"
  }
}

If you work on polyglot codebases, you can set language-specific formatters. For instance, you might prefer Prettier for JavaScript and HTML, but rely on a specific Python formatter for backend files:

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

Troubleshooting Common Auto-Formatting Issues

When auto-formatting stops working in VS Code, the culprit is usually multiple competing formatter extensions, broken configuration syntax in `.prettierrc` or `.eslintrc`, or an unselected default formatter. Checking the editor’s Output panel and disabling overlapping plugins usually identifies and resolves formatting failures quickly.

If saving a file suddenly stops triggering formatting adjustments, run through this quick troubleshooting checklist:

  • Check the Default Formatter: Right-click inside your editor window, choose Format Document With..., and click Configure Default Formatter... to ensure Prettier or your intended tool is chosen.
  • Inspect Configuration Files: A trailing comma inside a JSON file like `.prettierrc` invalidates the file, causing extensions to silently fail.
  • Review Output Logs: Open the Output tab (`Ctrl+Shift+U` or `Cmd+Shift+U`) and switch the dropdown menu from "Tasks" to "Prettier" or "ESLint" to view error stack traces.
  • Restart Extension Host: Run `Developer: Restart Extension Host` from the VS Code Command Palette to reload unresponsive background extension processes.

Comparison: Prettier vs. ESLint vs. Stylelint

Choosing between Prettier, ESLint, and Stylelint comes down to their core function: Prettier handles general code layout, ESLint analyzes JavaScript and TypeScript logic, and Stylelint enforces CSS and SCSS rules. Most modern frontend setups use Prettier alongside ESLint or Stylelint for complete codebase quality coverage.

FAQ

How do I trigger the auto format command in VS Code?

You can use the keyboard shortcut Shift+Alt+F (Windows/Linux) or Shift+Option+F (macOS). You can also right-click in the editor and select "Format Document".

What languages does VS Code auto format?

VS Code auto formats a wide range of languages, including JavaScript, Python, HTML, CSS, JSON, and many more, based on installed extensions.

Can I customize the auto format behavior?

Yes! You can configure formatting options in VS Code's settings, including which formatter to use and specific formatting rules for each language.

🛍 See today's best prices on Amazon and grab the option that fits you.

Editorial Team Author & reviewer

Hands-on reviewers testing tools, apps and services so you do not have to. Every article here is hands-on tested and human-reviewed before publishing.

Tool Primary Role Pricing Tier Key Feature
Prettier Opinionated code layout & formatting Free & Open Source Zero-config options, broad language support