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 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 Brandon Clapp on Stack Overflow
๐ŸŒ
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.
Top answer
1 of 16
5995

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 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
606

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:
๐ŸŒ
OpenReplay
blog.openreplay.com โ€บ using-prettier-with-vscode-to-write-javascript
Using Prettier with VSCode to write JavaScript
This will ensure your code is automatically formatted whenever you save your file. Thatโ€™s it! After installing and configuring it in VSCode, you can easily format your code to maintain consistency and readability throughout your project. To customize Prettier settings in VSCode, you can use a .prettierrc file or configure Prettier in your VSCode settings. ... Create a new file called .prettierrc in your projectโ€™s root directory. Add your desired configuration options in JSON ...
๐ŸŒ
Visual Studio Marketplace
marketplace.visualstudio.com โ€บ items
JS-CSS-HTML Formatter - Visual Studio Marketplace
Extension for Visual Studio Code - Format ,prettify and beautify JS, CSS, HTML code by using shortcuts, context menu or CLI
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 - To make sure Visual Studio Code uses Prettier for all formatting operations: Open Settings (JSON) via the Command Palette. ... You can apply this setting globally or in a workspace-specific .vscode/settings.json file.
๐ŸŒ
Carl de Souza
carldesouza.com โ€บ home โ€บ posts โ€บ how to beautify a javascript file in visual studio code
How to Beautify a JavaScript File in Visual Studio Code - Carl de Souza
September 11, 2020 - In this post, we will look at how to beautify a JavaScript file in Visual Studio Code using the Beautify extension. First, letโ€™s create a really simple JavaScript file. We can see the function is on one line: Search for and select Beautify: ...
๐ŸŒ
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 - For us, its a pre-commit hook to format with pretty-quick on all staged files. Use whatever IDE you want (although I recommend VScode for the team), but our code will be formatted the same regardless. ... Web Dev full-stack [LAMP] since 2005, but much heavier on the JS stuff these days.
๐ŸŒ
Robe Lee
roboleary.net โ€บ tools โ€บ 2022 โ€บ 05 โ€บ 18 โ€บ vscode-you-dont-need-a-formatting-extension-prettier-and-friends
VS Code - You don't need a formatting extension (Prettier and friends)
May 18, 2022 - VS Code has builtin formatters for HTML, JavaScript, TypeScript, and JSON. This is a decent basis for frontend developers and JavaScript-oriented backend developers. However, there was nothing for CSS and CSS-like syntaxes.
๐ŸŒ
DEV Community
dev.to โ€บ nabbisen โ€บ vs-code-built-in-formatter-for-js-ts-json-html-1lhk
VS Code: Built-in Formatter for .js / .ts / .json / .html - DEV Community
December 26, 2021 - #vscode #formatter #text #manipulation ยท As Visual Studio Code says in its website: VS Code has has default formatters for JavaScript, TypeScript, JSON, and HTML. The keyboard shortcut: [Ctrl] + [Shift] + i ยท brings formatted text. Like this ...
๐ŸŒ
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 - This is the most popular extension that supports formatting of JavaScript, TypeScript and CSS using Prettier. It has over 5.7 million installs to date. Itโ€™s recommended you install prettier locally as a dev dependency. Beautify, by HookyQR. A jsBeautifier extension that supports JavaScript, JSON, CSS and HTML.