The code formatting is available in Visual Studio Code through the following shortcuts:

  • On Windows Shift + Alt + F
  • On Mac Shift + Option + F
  • On Linux Ctrl + Shift + I

Alternatively, you can find the shortcut, as well as other shortcuts, through the submenu View / Command Palette, also provided in the editor with Ctrl + Shift + P (or Command + Shift + P on Mac), and then searching for format document.

For unsaved snippets

  1. Open command palette (Win: F1 or Ctrl + Shift + P)

  2. Find "Change Language Mode"

  3. Select language e.g. json. By now, the syntax should be highlighted.

  4. Format document (e.g. Open Command Palette -> "Format Document")

Unformat

  1. Select text
  2. Command Palette -> Join Lines

'Show the pics'

Answer from npc2b on Stack Overflow
๐ŸŒ
Visual Studio Marketplace
marketplace.visualstudio.com โ€บ items
Prettier - Code formatter - Visual Studio Marketplace
January 21, 2026 - Extension for Visual Studio Code - Code formatter using prettier
๐ŸŒ
Visual Studio Code
code.visualstudio.com โ€บ docs โ€บ languages โ€บ javascript
JavaScript in Visual Studio Code
November 3, 2021 - VS Code's built-in JavaScript formatter provides basic code formatting with reasonable defaults.
Discussions

Is there a way for VS Code to format JavaScript the way C# is typically styled? Javascript hurts my eyes and doesn't seem like Prettier's 'bracketSameLine' config option is meant for curly braces.
It's better to get used to the style that is idiomatic for the language of choice. I also prefer opening curly brace on new line, but If I'm writing JavaScript, I'll put it on same line. This is to avoid arguments over something that ultimately does not matter More on reddit.com
๐ŸŒ r/csharp
26
9
February 1, 2025
visual studio code - What is the default javascript formatter plugin for vscode? - Stack Overflow
I don't remember ever installing a javascript formatter with VS code I've just been using the default. From what I can tell this plugin is the actual formatter being used lonefy.vscode-js-css-html- More on stackoverflow.com
๐ŸŒ stackoverflow.com
With Prettier code formatter my JS code breaks
I am creating a react project. If you look at the picture above, you can see the lines inside the if statement and the line inside document.getElementById() gets written into smaller lines. It annoys me and makes code unreadable at glance. Can anyone please help me on how to avoid this or any work around ? Thank you More on reddit.com
๐ŸŒ r/vscode
6
1
November 3, 2022
Best formatter in VScode?

Try language specific subreddits

More on reddit.com
๐ŸŒ r/vscode
2
0
October 12, 2018
Top answer
1 of 16
6008

The code formatting is available in Visual Studio Code through the following shortcuts:

  • On Windows Shift + Alt + F
  • On Mac Shift + Option + F
  • On Linux Ctrl + Shift + I

Alternatively, you can find the shortcut, as well as other shortcuts, through the submenu View / Command Palette, also provided in the editor with Ctrl + Shift + P (or Command + Shift + P on Mac), and then searching for format document.

For unsaved snippets

  1. Open command palette (Win: F1 or Ctrl + Shift + P)

  2. Find "Change Language Mode"

  3. Select language e.g. json. By now, the syntax should be highlighted.

  4. Format document (e.g. Open Command Palette -> "Format Document")

Unformat

  1. Select text
  2. Command Palette -> Join Lines

'Show the pics'

2 of 16
607

Code Formatting Shortcut:

Visual Studio Code on Windows - Shift + Alt + F

Visual Studio Code on MacOS - Shift + Option + F

Visual Studio Code on Ubuntu - Ctrl + Shift + I

You can also customize this shortcut using a preference setting if needed.

Code Formatting While Saving the File:

Visual Studio Code allows the user to customize the default settings.

If you want to auto format your content while saving, add the below code snippet in the work space settings of Visual Studio Code.

Menu File โ†’ Preferences โ†’ Workspace Settings

{
  // Controls if the editor should automatically format the line after typing
  "beautify.onSave": true,

  "editor.formatOnSave": true,

  // You can auto format any files based on the file extensions type.
  "beautify.JSfiles": [
      "js",
      "json",
      "jsbeautifyrc",
      "jshintrc",
      "ts"
  ]
}

Note: now you can auto format TypeScript files. Check my update.

๐ŸŒ
Medium
thiraphat-ps-dev.medium.com โ€บ the-best-code-formatters-for-vs-code-11704e787f92
The Best Code Formatters for VS Code | by Thiraphat Phutson | Medium
June 3, 2024 - Search for โ€œPrettier โ€” Code formatterโ€ and install it. Configure Prettier to format on save by adding the following settings in your settings.json: "editor.formatOnSave": true, "prettier.singleQuote": true, "prettier.trailingComma": "all" ESLint is primarily a linting tool for JavaScript and TypeScript, but it also has powerful formatting capabilities.
๐ŸŒ
Prettier
prettier.io
Prettier ยท Opinionated Code Formatter ยท Prettier
JavaScriptPrettier ยท prettier-vscode ยท Built-in support ยท Got more?Send a PR ยท See others ยท Regularly used by: More than 83% of respondents to State of JS 2021. More than 70% of respondents to State of JS 2020. More than 9.9 million dependent repositories on GitHubCheck Them Out ยท
๐ŸŒ
Beautifier
beautifier.io
Online JavaScript beautifier
Chrome, in case the built-in CSS and javascript formatting isn't enough for you: โ€” Quick source viewer by Tomi Mickelsson (github, blog), โ€” Javascript and CSS Code beautifier by c7sky, โ€” jsbeautify-for-chrome by Tom Rix (github), โ€” Pretty Beautiful JavaScript by Will McSweeney โ€” Stackoverflow Code Beautify by Making Odd Edit Studios (github).
Find elsewhere
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ how-to-format-code-with-prettier-in-visual-studio-code
Format Code with Prettier in Visual Studio Code: Setup Guide | DigitalOcean
August 1, 2025 - Learn how to format code with Prettier in Visual Studio Code. This guide walks you through installing, configuring, and using Prettier for code formatting.
๐ŸŒ
Scott Sauber
scottsauber.com โ€บ 2017 โ€บ 06 โ€บ 10 โ€บ prettier-format-on-save-never-worry-about-formatting-javascript-again
Prettier + Format On Save = Never worry about formatting JavaScript again โ€“ Scott Sauber
June 12, 2021 - In my last post, I mentioned a tip to using the Format on Save option in VS Code. Iโ€™d like to take that one step further and mention how you can combine that with the Prettier โ€“ Javascript Formatter plugin for VS Code to make a really nice editing experience.
๐ŸŒ
DEV Community
dev.to โ€บ robole โ€บ vs-code-you-dont-need-a-formatting-extension-prettier-and-friends-26cm
VS Code - You don't need a formatting extension (Prettier and friends) - DEV Community
June 2, 2022 - ... Yes, that builtin extension formats JavaScript and TypeScript code. If you want to configure the default formatter for a JavaScript file that is open, right-click inside and select the option "Format document with.." from the context menu.
๐ŸŒ
YouTube
youtube.com โ€บ tomasz tarnowski
How to Format Code Automatically with Prettier and VS Code - YouTube
In this video tutorial, I explain step by step how to configure automatic code formatting with Prettier and Visual Studio Code.Commands used in this video:- ...
Published ย  October 14, 2021
Views ย  10K
๐ŸŒ
OpenReplay
blog.openreplay.com โ€บ using-prettier-with-vscode-to-write-javascript
Using Prettier with VSCode to write JavaScript
June 7, 2023 - Prettier is a powerful code formatting tool that can help improve the consistency, readability, and maintainability of your JavaScript codebase. By integrating with VSCode and following best practices, such as customizing settings with a .prettierrc ...
๐ŸŒ
SitePoint
sitepoint.com โ€บ blog โ€บ es6 โ€บ 10 must-have vs code extensions for javascript developers
10 Must-have VS Code Extensions for JavaScript Developers โ€” SitePoint
November 13, 2024 - To beautify JavaScript code in Visual Studio Code, install the Prettier extension from the Extensions Marketplace. Once installed, you can format your code by right-clicking in the editor and selecting โ€œFormat Documentโ€ or using the shortcut ...
๐ŸŒ
Visual Studio Code
code.visualstudio.com โ€บ docs โ€บ editing โ€บ codebasics
Basic editing
November 3, 2021 - VS Code has default formatters for JavaScript, TypeScript, JSON, HTML, and CSS.
๐ŸŒ
YouTube
youtube.com โ€บ the code city
Auto Code Formatting in VSCode | Best Formatter for Visual Studio Code (2023) - YouTube
In this video, I'll show you the best code formatter for vscode. I've been using prettier along with some other code formatter for visual studio code. Pretti...
Published ย  December 2, 2023
Views ย  6K