Mel
Mel

Reputation: 2683

auto close HTML tags is not triggering

According to this update, VS Code is supposed to auto close tags when the closing > of the opening tag is typed. Mine won't seem to do that (I'm on v1.19).

I also tried installing the package Jun Han made which is supposed to do this too, but it doesn't work. Is there a trick to getting this function to work?

Enabled extensions are:

enter image description here

Upvotes: 3

Views: 7198

Answers (2)

Tomas Kohl
Tomas Kohl

Reputation: 1388

I had the same problem. After reviewing the answer above, I noticed that VS Code auto-detected a different language than HTML, even though the file I was editing had the ".html" extension. After selecting HTML as the working language, the editor now auto-closes the tags.

Upvotes: 0

Gino Mempin
Gino Mempin

Reputation: 29608

I've also experienced inconsistencies with this feature.


Tag elements are now automatically closed when > of the opening tag is typed

This only seems to work when the file is detected as plain HTML or JS.

detected as HTML detected as JS

The matching closing tag is inserted when / of the closing tag is entered

This works for HTML and JavaScript, and for other formats that render HTML like Vue or Markdown.


There are some settings you can check if it's not working:

  • Make sure html.autoClosingTags is true
    • It should be true by default
    • Check your user, workspace, and folder settings (maybe one is overriding it)
  • If you still have the Auto Close Tag extension installed:
    • auto-close-tag.excludedTags
    • auto-close-tag.activationOnLanguage
      • If the detected language is not HTML or JavaScript, check that it is on this list
    • auto-close-tag.fullMode
      • The default is false, but setting to true makes it seem more consistent

Upvotes: 6

Related Questions