1

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

Freestyle09
  • 4,894
  • 8
  • 52
  • 83
  • 2
    i know… it's not answer, but do you really need it? Because then it's not valid html5 … element div must be closed with `` – iiic Aug 29 '19 at 12:06
  • Why it's not valid ? – Freestyle09 Aug 29 '19 at 12:07
  • 3
    Per HTML 5 specifications the div element will need a closing tag. See [this Stackoverflow post](https://stackoverflow.com/questions/3558119/are-non-void-self-closing-tags-valid-in-html5) for example – Zephire Aug 29 '19 at 12:36

1 Answers1

1

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>
Freestyle09
  • 4,894
  • 8
  • 52
  • 83