What is Format on Save in VS Code

The “Format on Save” setting in Visual Studio Code (VS Code) is a built-in feature that automatically cleans up and structures your code every time you save a file. By instantly applying formatting rules—such as adjusting indentation, adding missing semicolons, and wrapping long lines—this setting ensures consistent code style, saves manual editing time, and helps prevent syntax errors before you commit your work.

How Format on Save Works

When you enable Format on Save, pressing the save shortcut (Ctrl + S on Windows/Linux or Cmd + S on macOS) triggers VS Code to run your active code formatter on the active document.

The editor looks at your configured formatting tool for that specific programming language—such as Prettier for JavaScript/HTML/CSS, Black for Python, or the built-in TypeScript formatter—and applies its rules instantly. This happens in milliseconds, right before the file is written to your storage drive.

Key Benefits of Enabling the Setting

How to Enable Format on Save in VS Code

You can activate this feature in two different ways:

Method 1: Using the Settings UI

  1. Open Settings using Ctrl + , (or Cmd + , on macOS).
  2. In the search bar at the top, type Format on Save.
  3. Locate the checkbox labeled Editor: Format On Save.
  4. Check the box to enable it.

Method 2: Editing settings.json

If you prefer configuring VS Code via code, you can add the following line to your user or workspace settings.json file:

"editor.formatOnSave": true

Language-Specific Formatting

If you do not want to format every single language on save, you can configure the setting for specific languages in your settings.json file. For example, to enable it only for Python and disable it for Markdown, you would write:

"[python]": {
    "editor.formatOnSave": true
},
"[markdown]": {
    "editor.formatOnSave": false
}