Search code examples
htmlvisual-studio-codeprettier

How to enable auto close tag with prettier in vs code?


I want to enable auto close empty tag with Prettier in Visual Studio Code v 1.37.1.

I want this:

<img src='/logo.svg' alt='' />
<div />

from this:

<img src='/logo.svg' alt=''>
<div></div>

Anyone knows where to enable it in Prettier or with any other extension ??


Solution

  • I had problem with emmet from vs code. When I set this to html my img tags were looking like this:

    <img src='' alt=''> 
    

    And I couldn't save document without having a prettier error.

    After set this in setting.json in vscode:

    "emmet.includeLanguages": {
            "javascript": "javascriptreact"
        },
    

    When I write img and press tab, I'm getting this:

    <img src='' alt='' />
    

    And divs stays like they should look like:

    <div></div>