Skip to content

[html] VSCode doesn't automatically close HTML tags #2246

Closed

Description

@johnyradio

in html file-type
vscode version 0.10.6

My User Settings config says:
"editor.autoClosingBrackets": true,

but it still doesn't work.

For example, when you type in "<script" the IntelliSense suggestions pops up and you press enter on "script" it doesn't close the tag like this:

<script>
</script>

but it stays like this:

<script>

Activity

  1. added
    bug
    on Jan 27, 2016
  2. changed the title [-]VSCode doesn't automatically close HTML tags[/-] [+][html] VSCode doesn't automatically close HTML tags[/+] on Jan 27, 2016
  3. cindoum commented on Jun 17, 2016

    @cindoum

    any update on it?

  4. aeschli commented on Jun 17, 2016

    @aeschli
    Contributor

    Dominic Lapointe (@cindoum) Sorry, no, we currently have no plans adding this.
    I recommend you using the emmet expansion
    enter script, press tab. This expand to <script></script>

  5. mahomedh commented on Jul 14, 2016

    @mahomedh

    You can use the "Auto Close Tag" extension to replace this behaviour. IMO this is better so that VSCode can stay light and people can "enable" features with the extension of choice.

    https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-close-tag

  6. Peter-Juhasz commented on Aug 7, 2016

    @Peter-Juhasz

    It is so essential that it should be part of the HTML language service.

  7. glen-84 commented on Sep 10, 2016

    @glen-84

    Duplicate of #502 (?)

  8. aeschli commented on Sep 12, 2016

    @aeschli
    Contributor

    Yes, #502 is the same. I'll close #502 as dup.

  9. josemi-ca commented on Dec 18, 2016

    @josemi-ca

    +1 This makes coding faster.

  10. added
    feature-request
    and removed
    bug
    on Feb 22, 2017
  11. richeklein commented on Mar 21, 2017

    @richeklein

    Perhaps this is better as a separate feature request, but it would be useful to integrate auto tag renaming. It's currently available as a popular extension. Thanks.

  12. 1 remaining item

  13. doivosevic commented on May 1, 2017

    @doivosevic

    Can't you use the https://code.visualstudio.com/docs/extensionAPI/extension-points#_contributeslanguages ?

    autoClosingPairs - Defines the open and close symbols for the auto-close functionality. When an open symbol is entered, the editor will insert the close symbol automatically. Auto closing pairs optionally take a notIn parameter to deactivate a pair inside strings or comments.

  14. stofte commented on May 17, 2017

    @stofte

    Feature makes it slightly annoying to add HTML to existing tags as it prefers to close the parent tag, instead of creating a new opening tag (I'll have to untrain hitting enter when writing HTML). Esp common occurence with div soup.

  15. aeschli commented on Aug 28, 2017

    @aeschli
    Contributor

    I added auto-close to the built-in HTML language support:

    • typing the > of <sometag> will add the closing tag </sometag>.
    • typing / of </ will also close the tag.
    • this behaviour is enabled by default and can be turned off with setting html.autoClosingTags

    Thanks Jun Han (@formulahendry) for leading the way with his extension. Note that the auto-close extension has more features, in particular, configurable support for more languages.
    Jun, if you can add a check for the new setting that would be great, so the auto-close extension can co-exist with the new support.

  16. formulahendry commented on Aug 29, 2017

    @formulahendry
    Member

    Thanks Martin Aeschlimann (@aeschli) , that's cool! I will take a look.

  17. rosieks commented on Sep 2, 2017

    @rosieks

    Does it work also with JSX/TSX?

  18. aeschli commented on Sep 4, 2017

    @aeschli
    Contributor

    Sławomir Rosiek (@rosieks) No, this is only for html, handlebars and razor files.

  19. johnyradio commented on Sep 5, 2017

    @johnyradio
    Author
  20. johnyradio commented on Sep 5, 2017

    @johnyradio
    Author

    Jun Han (@formulahendry) , how is Martin Aeschlimann (@aeschli) 's solution different from the Auto Close Tag extension?

  21. formulahendry commented on Sep 5, 2017

    @formulahendry
    Member

    johnyradio

    Martin Aeschlimann (@aeschli) 's solution is leveraging the VSCode built-in HTML extension. It could distinguish HTML and embedded languages well. So when you write embedded languages inside HTML, there will not be improper auto-close if you write generic like formulahendry/vscode-auto-close-tag#17. While the limitation is that it only works on html, handlebars and razor files.

    For Auto Close Tag extension, it is based on regular expression. So it works for any languages, while the limitation is that it could not distinguish HTML and embedded languages.

  22. locked and limited conversation to collaborators on Nov 17, 2017
  23. added a commit that references this issue on Sep 6, 2026
    105e108
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

feature-requesthtmlon-testplan

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions