Techguru
Techguru

Reputation: 49

Prettier format on save not working in CSS or HTML files

I recently installed prettier (V9.0.0) in VS Code and enabled format on save.

This is working in CSS files but doesn't work in JS or HTML files. Has anyone had this problem and fixed it?

Not sure what other context to provide but happy to provide anything else that might be helpful.

Thanks.

Upvotes: 3

Views: 10179

Answers (4)

Zakk
Zakk

Reputation: 21

Open the command palette : command + shift + p (Mac) tape : "Preferences : open User Settings (JSON)" add the following line to the json file :

"[css]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }

Upvotes: 2

Angler
Angler

Reputation: 1

For me only html formatting did not work. I just type this in settings:

@id:editor.defaultFormatter @lang:html formatter

and there in list you need to choose prettier.

Upvotes: 0

Avani Joshi
Avani Joshi

Reputation: 81

Try adding this in your vscode's settings.json,

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

Upvotes: 7

Asif Kamran Malick
Asif Kamran Malick

Reputation: 3171

This has been discussed in the past. Few things you can try:

  • set prettier as the Default Formatter in Settings . File -> Preferences -> Settings (for Windows) Code -> Preferences -> Settings (for Mac). Search for "Default Formatter".
  • You can also set default Formatter per language

Upvotes: 2

Related Questions