Everyday Toolkit

Auto Format VS Code: How to Enable and Customize Automatic Styling

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
  • Enables instant formatting on save
  • Standardizes team codebases
  • Supports top languages via extensions
  • Fixes common setup conflicts
Auto Format VS Code: How to Enable and Customize Automatic Styling
Photo: saarav242 (BY-SA) via Openverse

Auto Format VS Code: How to Enable and Customize Automatic Styling

To enable auto format in VS Code, open Settings using Ctrl+, on Windows/Linux or Cmd+, on macOS, search for "Format On Save", and check the box to automatically format files whenever you save them.

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

Why Auto Formatting in VS Code Matters

Auto formatting in VS Code eliminates manual code cleanup, enforces a unified style guide across dev teams, and prevents minor formatting disagreements during pull request reviews. By delegating indentation, line wraps, and quote choices to an automated tool, developers reduce cognitive fatigue and keep their pull requests focused entirely on application logic.

When multiple engineers contribute to a single repository, inconsistent spacing, mixed tabs and spaces, and mismatched trailing commas can pollute Git diffs. A diff filled with hundreds of line-ending fixes hides the actual code logic you need to review. Setting up automated formatting ensures that every developer on your team submits clean, standard code without spending manual effort tweaking whitespace.

Configuring VS Code's Built-in Formatting

Auto Format VS Code: How to Enable and Customize Automatic Styling
Photo: Software: Alliance for Open Media Screenshot: Veikk0.ma via Wikimedia Commons

VS Code includes native formatting support for languages like HTML, CSS, JavaScript, and JSON out of the box without requiring external extensions. You can manually format any open document by pressing Shift+Alt+F on Windows and Linux or Shift+Option+F on macOS, or by triggering the Format Document command via the Command Palette.

To access the Command Palette, press Ctrl+Shift+P (or Cmd+Shift+P on macOS), type "Format Document", and press Enter. If you have multiple formatters installed for the same file type, VS Code prompts you to choose a default formatter. Picking a default formatter stores your preference in your configuration, so subsequent commands run instantly without nagging you again.

Understanding Format Settings

VS Code's format settings control global and workspace-level preferences like tab width, space insertion, and line length rules across all editor languages. Accessing these options through the Settings UI or settings.json allows developers to override default behaviors and maintain strict consistency across team environments.

You can manage these choices visually via File > Preferences > Settings or by editing settings.json directly. Key keys include:

  • editor.tabSize: Defines the number of spaces corresponding to a tab (typically 2 or 4).
  • editor.insertSpaces: When set to true, pressing Tab inserts spaces instead of tab characters.
  • editor.detectIndentation: When active, VS Code overrides your settings by guessing indentation based on the opened file's existing structure. Turning this off ensures your preferred rules apply universally.

Language-specific extensions enhance VS Code's baseline capabilities by providing deeper, highly customized formatting rules for specific stacks. Tools such as Prettier for web development, ESLint for JavaScript code quality, and Black for Python extend the editor's core engine, giving engineering teams precise control over syntax and layout.

While the internal engine handles basic tasks well, specialized languages often require rigid formatting rules defined by community conventions. Installing third-party formatters from the Visual Studio Marketplace allows projects to enforce rules via config files checked directly into source control.

Prettier: The Opinionated Choice

Prettier is an opinionated code formatter that enforces a consistent style by parsing your code and re-printing it according to strict formatting rules. It supports languages including JavaScript, TypeScript, HTML, CSS, and JSON, removing nearly all subjective debates about code layout across team codebases.

Because Prettier rewrites code from scratch based on its own AST (Abstract Syntax Tree) parsing, developers don't have to spend time arguing over bracket positioning or single versus double quotes. You configure Prettier via a .prettierrc file in your repository root. Once set up, everyone working on the project gets identical formatting output regardless of their local editor setups.

ESLint: Code Quality and Style Enforcement

ESLint acts as both a linter and a code style enforcer, detecting logical bugs alongside syntactic inconsistencies in JavaScript and TypeScript applications. While primarily designed for static analysis, ESLint can automatically fix formatting errors and code smells when paired with VS Code's format-on-save functionality.

Unlike standard formatters that only care about layout, ESLint catches unused variables, unreachable code, and dangerous type coercions. Configuring ESLint requires an .eslintrc or eslint.config.js file. Many teams combine Prettier and ESLint, letting Prettier handle code formatting while ESLint focuses on code quality checks.

Black: Python's Uncompromising Formatter

Black is an uncompromising Python code formatter that rewraps lines and standardizes quotes with minimal configuration options, ensuring total stylistic uniformness. By adhering to a rigid internal specification, Black eliminates heated code review discussions while maintaining compliance with Python community standards like PEP 8.

Black gives developers very few options to adjust, deliberately limiting configuration to prevent endless customization debates. It standardizes double quotes, fixes trailing commas, and wraps lines cleanly at 88 characters by default. Integrating Black into VS Code gives Python developers instant formatting that matches production-grade open-source repositories.

Setting Up Auto Format on Save

Setting up auto format on save requires enabling the `editor.formatOnSave` setting in VS Code, which automatically cleans your document every time you hit save. You can activate this via the Settings UI or by adding `"editor.formatOnSave": true` directly into your global or workspace `settings.json` file.

To configure format-on-save via the graphical interface:

  1. Open Settings (Ctrl+, / Cmd+,).
  2. Search for Format On Save in the top search bar.
  3. Check the box next to Editor: Format On Save.

For fine-grained control, open settings.json and define language-specific behavior. For instance, you might want format-on-save enabled for TypeScript files but disabled for Markdown files:

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

Troubleshooting Formatting Issues

Troubleshooting VS Code formatting issues usually involves resolving conflicts between multiple installed formatters, setting an explicit default formatter, or verifying language-specific configurations. Developers can resolve most broken formatting by inspecting the Output channel, ensuring extension active states, or updating workspace settings to point to a specific extension.

When auto-formatting fails to trigger on save, walk through these troubleshooting steps:

  • Check Default Formatter: Open the Command Palette, run "Format Document", and ensure VS Code isn't prompting you to select a default formatter. If it is, select your preferred extension.
  • Inspect the Output Panel: Open the Output tab (Ctrl+Shift+U / Cmd+Shift+U) and select your formatter (e.g., Prettier) from the drop-down menu on the right to read detailed error logs. Syntax errors in your source code often prevent formatters from running.
  • Verify Extension Status: Ensure the extension is enabled in your current workspace and isn't disabled globally.
  • Check Workspace Override: A local .vscode/settings.json file in your repo might be overriding your global editor preferences.

Selecting the right formatting tool depends on your primary programming language, project complexity, and team preferences regarding custom rules versus strict defaults. Prettier offers multi-language support, ESLint excels at JavaScript analysis, Black specializes in Python codebases, and EditorConfig manages baseline file configurations across different code editors.

FAQ

How do I enable auto format in VS Code?

Go to File > Preferences > Settings. Search for "format on save" and check the box. Alternatively, use the command palette (Ctrl+Shift+P or Cmd+Shift+P) and type "Format Document With..."

Why isn't auto format working?

Ensure the correct language mode is selected. Check for conflicting extensions. Verify your settings haven't been overridden by workspace or user settings.

Can I auto format on save for specific file types?

Yes! In VS Code settings, you can configure "Format On Save" per language. Search for "format on save" and expand the options to customize by file type.

🛍 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 Best for Pricing Tier Standout Feature
Prettier JavaScript, TypeScript, HTML, CSS, JSON Free (Open Source) Multi-language support with opinionated defaults
ESLint JavaScript, TypeScript Free (Open Source)