Right-click in your text editing area and choose Format Document With.... A popup will appear on top then choose Choose default formatter and then choose Prettier
Right-click in your text editing area and choose Format Document With.... A popup will appear on top then choose Choose default formatter and then choose Prettier
You can trigger suggestions at any time by pressing
Ctrl+Space.To improve the formatting of your HTML source code, you can use the
Format Document commandCtrl+Shift+Ito format the entire file or
Format SelectionCtrl+KCtrl+Fto just format the selected text.
Read this: https://code.visualstudio.com/docs/languages/html
Videos
Hey guys, do you know any good extensions for auto-formatting html? I am getting kinda tired of doing it manually...
So I keep seeing Prettier come up when I look for an auto-formatter but I'm a little worried as it says that it's opinionated.
My workplace has very specific coding standards and I'd prefer one that is configurable as possible.
Also preferably with the ability to share those settings with other members of my team.
I'm using HookyQR's "Beautify" extension right now, but it doesn't work with XML or LESS. (Maybe SCSS, but I haven't tried yet.)
I could just install other extensions that support those other languages, but I'd rather use a single extension.
There are tons of beautifiers in the marketplace, but I'm hoping to take advantage of everyone's expertise here so I don't have to manually try a bunch. (Also, there are usually some good ones out there with unusual names or bad SEO that are hard to find.)
Thanks!
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
Open command palette (Win: F1 or Ctrl + Shift + P)
Find "Change Language Mode"
Select language e.g.
json. By now, the syntax should be highlighted.Format document (e.g. Open Command Palette -> "Format Document")
Unformat
- Select text
- Command Palette -> Join Lines
'Show the pics'


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.
Starting with the 1.33 release (March 2019), attempting to format a file for which there are multiple formatters registered results in a popup like this:

Note that the notification is "silent" if formatting happened implicitly via "format on save" or "format on paste", meaning that you need to click the bell in the lower right for it to show up:

The Configure... menu then lists all the formatters available for the current language. One of them can be selected as a default formatter for Format Document and Format Selection:

Picking for instance "Prettier" here results in this being added to the global settings.json:
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
There are also two new commands for formatting a file with a specific formatter, Format Document With... and Format Selection With.... This can be useful for formatting a specific file with a formatter that's not set as the default formatter. The former is also available from the context menu:

In addition to the answer given by Gama11
You can got to settings.json on below given path
C:\Users\<username>\AppData\Roaming\Code\User\settings.json
I am using "prettier" formatter for my html files,
also you can find the formatter been used for other extensions if configured.

When formatting with vscode, all the html attributes are surrounded with double quotes by default
How do I change it so that only those attributes that I have quoted must be retained, but those I’ve not surrounded with quotes must remain as such ?
Reason : we have an internal framework which takes non string arguments for passing props down to child component (sort of like react). But when I pass such props, they always get formatted as string. No ones bothered to write a custom formatted or something for this(I should be possible to write one right?)
Edit: added reason