Programming

How do you change the formatting options in Visual Studio Code

25 September 2026 · 9 min read

How do you change the formatting options in Visual Studio Code

Visual Studio Code (VS Code) is a powerful and versatile code editor favored by developers worldwide for its extensive customization options, robust features, and seamless integration with various programming languages. One of the most crucial aspects of any code editor is its formatting capabilities. Clean, well-formatted code is not only easier to read but also less prone to errors, improving overall code quality and maintainability. Understanding how to change the formatting options in Visual Studio Code is essential for tailoring the editor to your specific coding style and project requirements. This guide will walk you through the various methods to customize VS Code’s formatting features, ensuring your code always looks its best.

Understanding VS Code’s Formatting System

VS Code’s formatting system is built around the concept of formatters. These are language-specific tools that automatically adjust the indentation, spacing, and overall structure of your code to conform to predefined rules. VS Code supports a wide range of formatters, including Prettier, ESLint, and Beautify, each with its own set of configuration options. The editor automatically detects the language of the file you’re working on and attempts to use the appropriate formatter. If no formatter is explicitly configured, VS Code will often fall back to its built-in formatting capabilities, which are based on language-specific settings.

The power of VS Code’s formatting lies in its flexibility. You can configure global formatting settings that apply to all projects, as well as project-specific settings that override the global ones. This allows you to maintain consistent coding styles across different projects, even if they have different formatting requirements. Furthermore, VS Code’s settings are stored in JSON format, making them easy to read and modify. This allows for precise control over every aspect of the formatting process, ensuring that your code always adheres to your preferred style guidelines.

According to a Stack Overflow Developer Survey, over 70% of developers use VS Code as their primary code editor [^1^][(Stack Overflow Developer Survey)](https://survey.stackoverflow.co/2023/most-popular-developer-tools). This widespread adoption highlights the importance of understanding and customizing VS Code’s features, including its formatting capabilities.

Configuring Global Formatting Settings

Global formatting settings affect all projects you open in VS Code. These settings are stored in the settings.json file, which can be accessed through the VS Code settings UI or by directly editing the file. To access the settings UI, go to File > Preferences > Settings (or use the keyboard shortcut Ctrl+,). Here, you can search for formatting-related settings and modify them to your liking.

Some of the most commonly configured global formatting settings include:

  • editor.formatOnSave: Automatically formats the file whenever you save it. This is highly recommended to maintain consistent formatting.
  • editor.defaultFormatter: Specifies the default formatter to use for all languages. If you prefer Prettier over the built-in formatter, you can set this to “esbenp.prettier-vscode”.
  • editor.formatOnType: Formats lines as you type, providing immediate feedback on your code’s formatting.

For example, to enable format on save using Prettier, you would add the following to your settings.json file:

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

Remember to install the Prettier extension if you haven’t already. You can find it in the VS Code Marketplace. By configuring these global settings, you can ensure that all your projects benefit from consistent and automated code formatting.

Setting Up Project-Specific Formatting

While global settings provide a baseline for formatting, project-specific settings allow you to tailor the formatting to the specific needs of each project. These settings are stored in a .vscode folder at the root of your project. This folder contains a settings.json file that overrides the global settings. This is particularly useful when working on projects with different coding style requirements or when using different formatters.

To create project-specific settings, create a .vscode folder at the root of your project and add a settings.json file inside it. You can then add formatting-related settings to this file, just like you would with the global settings file. For instance, if you want to use ESLint for a specific project, you can configure the editor.defaultFormatter setting in the project’s settings.json file.

Here’s an example of a project-specific settings.json file:

{ "editor.formatOnSave": true, "editor.defaultFormatter": "dbaeumer.vscode-eslint", "eslint.alwaysShowStatus": true } 

This configuration tells VS Code to use ESLint as the default formatter for this project and to always show the ESLint status in the status bar. This allows you to easily identify and fix any formatting issues specific to this project. According to a study by Google, consistent code formatting can reduce code review time by up to 15% [^2^][(Google Code Review Research)](https://research.google/pubs/pub45684/). Project-specific formatting ensures that each project adheres to its own unique style guidelines, contributing to improved code quality and efficiency.

Using Formatters Like Prettier and ESLint

Prettier and ESLint are two of the most popular code formatters used in VS Code. Prettier focuses on code aesthetics, automatically formatting your code to adhere to a consistent style guide. ESLint, on the other hand, focuses on code quality, identifying potential errors and enforcing coding standards. Both formatters can be integrated seamlessly into VS Code to provide automated formatting and linting.

To use Prettier, you first need to install the Prettier extension from the VS Code Marketplace. Once installed, you can configure VS Code to use Prettier as the default formatter by setting the editor.defaultFormatter setting to “esbenp.prettier-vscode”. You can also create a .prettierrc.json file in your project to customize Prettier’s behavior. This file allows you to specify rules for indentation, line length, and other formatting options.

Similarly, to use ESLint, you need to install the ESLint extension and configure it to use your project’s ESLint configuration file (.eslintrc.js or .eslintrc.json). You can then set the editor.defaultFormatter setting to “dbaeumer.vscode-eslint” to use ESLint as the default formatter. ESLint can also be configured to automatically fix certain errors, further improving code quality. Here is some helpful information on ESLint and how it can be used to improve your coding workflow.

Here’s how to configure ESLint and Prettier to work together:

  1. Install both the ESLint and Prettier VS Code extensions.
  2. Install ESLint and Prettier as dev dependencies in your project: npm install eslint prettier –save-dev.
  3. Configure ESLint to use Prettier’s formatting rules by extending the eslint-config-prettier configuration.
  4. Create a .prettierrc.json file to customize Prettier’s formatting options.

By combining Prettier and ESLint, you can achieve both consistent code aesthetics and high code quality, leading to more maintainable and error-free code. According to a study by Microsoft, teams that use automated code formatting tools experience a 20% reduction in debugging time [^3^][(Microsoft Research on Code Quality)](https://www.microsoft.com/research/).

Infographic illustrating the configuration steps for Prettier and ESLint in VS Code
Troubleshooting Common Formatting Issues ----------------------------------------

Even with proper configuration, you may encounter formatting issues in VS Code. These issues can range from incorrect indentation to conflicts between different formatters. Troubleshooting these issues often involves checking your settings, verifying your formatter configurations, and resolving any conflicts that may arise.

One common issue is incorrect indentation. This can be caused by incorrect tab size settings or conflicts between different formatters. To fix this, you can adjust the editor.tabSize setting in your settings.json file. You can also try disabling any conflicting formatters or configuring them to work together harmoniously. Another common issue is formatters not working at all. This can be caused by missing dependencies or incorrect file associations. To fix this, you can try reinstalling the formatter extension or checking your file associations to ensure that VS Code is using the correct formatter for each file type.

Here are some tips for troubleshooting formatting issues in VS Code:

  • Check your settings.json file for any conflicting or incorrect settings.
  • Verify that your formatter extensions are installed and enabled.
  • Check your file associations to ensure that VS Code is using the correct formatter for each file type.

If you’re still experiencing issues, you can try searching for solutions online or asking for help in the VS Code community forums. With a little bit of troubleshooting, you can resolve most formatting issues and ensure that your code is always formatted correctly.

FAQ: Formatting in Visual Studio Code

How do I format code on save in VS Code?
Set the `"editor.formatOnSave": true` setting in your `settings.json` file.
How do I set a default formatter for all languages?
Set the `"editor.defaultFormatter": "[formatter.id]"` setting in your `settings.json` file, replacing `[formatter.id]` with the ID of the formatter you want to use (e.g., `"esbenp.prettier-vscode"` for Prettier).
How do I format a specific selection of code?
Select the code you want to format and use the "Format Selection" command (usually Ctrl+K Ctrl+F or Cmd+K Cmd+F).
Why is my formatter not working?
Check that the formatter extension is installed, enabled, and properly configured. Also, ensure that the file type is associated with the correct formatter in your settings.
Customizing the formatting options in Visual Studio Code empowers you to create a coding environment that perfectly aligns with your preferences and project requirements. By understanding the intricacies of VS Code's formatting system, configuring global and project-specific settings, and leveraging powerful formatters like Prettier and ESLint, you can ensure your code is always clean, consistent, and error-free. This not only enhances readability and maintainability but also boosts your productivity and overall coding experience. Take some time to explore the various formatting options available in VS Code and discover how they can transform your workflow. Experiment with different settings, try out different formatters, and find the combination that works best for you. Your coding style is unique, and VS Code provides the tools to make your code reflect that perfectly.

Question & Answer :
I know you can Format Code using Ctrl+F / Cmd+F in Visual Studio Code but how do you change the formatting options for each language?

For example, in Visual Studio 2013 I can choose compact mode for CSS.

Is there another hidden JSON file to do that?

Update

Solution A:

Press Ctrl+Shift+P

Then type Format Document With...

At the end of the list click on Configure Default Formatter...

Now you can choose your favorite code beautifier from the list.

If Format Document With... is not available:

Open a file in Visual Studio Code (the extension of the file is not important can be .js, .html, .txt, etc…) then repeat Solution A again.

Solution B:

Windows: go to file -> preferences -> settings
Mac: go to code -> preferences -> settings

in the search bar tpye format, on the left side, click on Text Editor, the very first item on the right side is Editor: Default Formatter from the dropdown you can pick any document formatter which you’ve installed before.

enter image description here