Search code examples
htmlvisual-studio-codeprettier

Prettier does not format HTML


Prettier has just stopped working and is not formatting HTML in my VSCode. In the output I get: ["ERROR" - 5:00:45 PM] Error formatting document. ["ERROR" - 5:00:45 PM] Unexpected closing tag "p". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags (62:90)

Does anyone know what I can do to get working again? Ive checked my various settings and not been able to see anything wrong.


Solution

  • I had the same problem and finally solved it. I have in settings the default formatter as esbenp.prettier-vscode, then what I have done is in the html file, Ctrl+Shift+P --> preferences: configure language specific settings... then you search html and then you should have open the settings.json. in there I just pasted this

    {
        "editor.formatOnSave": true,
        "editor.formatOnPaste": true,
        "editor.formatOnType": true,
        "editor.defaultFormatter": "esbenp.prettier-vscode",
        "[html]": {
            "editor.defaultFormatter": "vscode.html-language-features"
        }
    }
    

    and I don't know why but works