VSCode not auto completing HTML
Asked Answered
C

17

126

I'm having trouble with my new installed Visual Studio Code on Windows 7. On Mac the editor automatically closes html tags but on my Win7 not. I assume there must be some option to turn it on but I can't find any.

I'm talking about when eg. writing <html the intelliSense pops up and you click enter, usually it automatically puts in the </html> mine's not working. (The IntelliSense pops up but when you select one of the options it doesn't auto close the tag: <h1> -> </h1>)

Cupreous answered 7/6, 2015 at 18:14 Comment(3)
1.you can use Auto Close Tag ,it can fullfill your requirement.Leguminous
2.enter a tagname such as div ,then enter tab key twice ,it will autocomplete the whoe tag ----- > <div></div>Leguminous
you can also create <div> elements with class or id names automatically. in you editor type .someclassname and press tab. you will get <div class"someclassname"></div>. or just put a # instead of the period and press tab after the name and it will give you a <div> with a id attached.Big
N
52

From the 0.3.0 release notes

HTML auto closing of tags has now been removed and replaced with smarter IntelliSense on </.

Noranorah answered 8/6, 2015 at 1:32 Comment(8)
Oh, that's not something I hoped for. Is there any way to bring it back? Modify some files or download something? I'd like to use VSCode but with auto completion. Thanks.Cupreous
you can always add a request on their site with uservoiceNoranorah
Did that, hopefully they bring it back. Thanks for the help. I'm doing Angular development in VSCode. Seems to work well with it so far.Cupreous
I was looking for this as well, but I do notice using tab works for me in 0.10.6. E.g. type div (without the <>) then press tab straight away, and it enters <div></div>. Not exactly the same, but may be of use. Doco for these shortcuts (emmet) hereSalient
yes, that is due to Emmet. Emmet let's us type element names without the braces and it will add what is needed. It's really powerful.Noranorah
This does not work for me on VS Code 1.5.3. If I type <div> then </ it does not close / complete the tag. Anything I'm missing here?Bainbridge
Just typing div without <> and then pressing tab doesn't work anymore after the latest updates. Is there a way to re-enable this?Marcie
@Salient that by itself should be an answer. thats so usefulCardamom
H
216

Type the tag name (without starting <) then press Tab

for example type div then press tab and VS will convert it to <div></div>

Or type the opening tag then press Tab twice

for example :

  1. type <div
  2. press Tab
  3. press Tab

it will add the closing tag

Hollins answered 5/6, 2016 at 5:2 Comment(10)
What about self closing tags (e.g. <input />)?Cocci
just type input and press Tab twice, VS Code will auto complete it to <input type="text">Italianism
Just want to add that this is part of Emmet functionality, which allows you to easily generate more complex HTML structure, not only tag pairs. For examples you can read this, or just google for Emmet.Twinflower
@Rabolf can you mention some other cool HMTL shortcuts for VS Code?Jessiejessika
@eMAD unfortunately I did not continue using VS CodeHollins
First suggestion works excellently - thanks! Second suggestion doesn't really work anymore, as you end up with <<div></div> after the first tab. So just continue typing div and then Tab :)Rhesus
It works perfectly ! No need of installing extensions ! But the thing is you have to change your habit while using other editors.Mustachio
It is not working for me. Is there anything else I need to check?Alcides
The answer below solved it for me. I am editing a .HTML file but VS Code was in the language mode for Nunjucks.Supinate
Thank you. That was the quickest and most helpful answer I've had to a question in ages. I was adding the opening bracket which kills the autocomplete.Brevet
S
212

I was experiencing the same problem, then i saw something on my bottom right of vs code.. instead of using HTML, i was using Django-HTML, so i changed the language to html, Boom everything is working fine again.see image

Schulte answered 20/12, 2018 at 23:3 Comment(8)
Had a similar problem, but in my case I realised I was writing HTML into a PHP file. Suppose I won't be able to make use of autoclosing tags for as long as I am.Oliy
is not necesary to change language, only add to settings.json "emmet.includeLanguages": { "django-html": "html"}Epicycloid
I fixed my Twig templates not intellisensing HTML thanks to @Epicycloid comment above. Ctrl+Shift+p -> open Perferences: Open Settings (UI) -> search for includedLanguages -> found Emmet Included Languages -> input Item: twig; Value: html -> press Add item -> enjoy.Shuma
You just saved me, I've been stuck with these for months, until I had the time today of looking into it, I was totally going to reinstall vs and start again when I came into your answer. Awesome.Miticide
Mine was on a go html template. This saved me a bunch of time. Thanks!Phyllode
I had this same issue too, checked the screenshot you sent and I was able to resolve mine the same way. I was using django_html too instead of html, thanksDirection
I have writing Django, so the problem you mentioned happens. This works for me.Rescript
Thanks @Siphamandla Ngwenya. How can I get both HTML and Django features in a file ?Bobcat
N
52

From the 0.3.0 release notes

HTML auto closing of tags has now been removed and replaced with smarter IntelliSense on </.

Noranorah answered 8/6, 2015 at 1:32 Comment(8)
Oh, that's not something I hoped for. Is there any way to bring it back? Modify some files or download something? I'd like to use VSCode but with auto completion. Thanks.Cupreous
you can always add a request on their site with uservoiceNoranorah
Did that, hopefully they bring it back. Thanks for the help. I'm doing Angular development in VSCode. Seems to work well with it so far.Cupreous
I was looking for this as well, but I do notice using tab works for me in 0.10.6. E.g. type div (without the <>) then press tab straight away, and it enters <div></div>. Not exactly the same, but may be of use. Doco for these shortcuts (emmet) hereSalient
yes, that is due to Emmet. Emmet let's us type element names without the braces and it will add what is needed. It's really powerful.Noranorah
This does not work for me on VS Code 1.5.3. If I type <div> then </ it does not close / complete the tag. Anything I'm missing here?Bainbridge
Just typing div without <> and then pressing tab doesn't work anymore after the latest updates. Is there a way to re-enable this?Marcie
@Salient that by itself should be an answer. thats so usefulCardamom
E
32

Here is a cool trick (actually an Emmet abbreviation) :

  • write the tag name ­ | e.g. h1
  • add an asterisk after that ­ | e.g. h1*
  • press Tab ­ | (will result in <h1></h1>)

­

PS: This also works for self-closing tags, such as - input , img etc.

Eryneryngo answered 12/8, 2017 at 15:44 Comment(7)
@Marcie Yes it does :PGrettagreuze
That's so weird..... I'm not sure what setting to change to re-enable it...Marcie
@Marcie you should have the emmet extension installed.Radtke
This works, but there's no need to include the *. 1.21.0Pinko
this doesn't work. @Radtke there are thousands of extensions with the name emmetReiners
@BlueClouds yes and any of them that provides html abbreviation support, should work. By a generic rule, I use the one with max installs.Radtke
No asterisk required here in Nov.2019. just tag name and tab is enoughDignity
M
24

Change from Django-html to html .enter image description here

Muscolo answered 21/3, 2021 at 11:35 Comment(0)
K
19
  1. Press Ctrl + Shift + P to open the command palette.
  2. Type 'Change Language Mode' in the searcher.
  3. Select 'Change Language Mode'.
  4. Type 'HTML' in the searcher.
  5. And select 'HTML' (it was probably set to 'django-html)
Kermie answered 5/4, 2020 at 17:56 Comment(0)
C
9

I've encountered same problem on Mac Sierra (10.12.6) with VSCode (1.30.2), while editing an HTML file. According to the vscode documentations https://code.visualstudio.com/docs/languages/html, the intellisense should work out of box.

Turned out that the "Language Detection" (on the right corner of editor status bar at the bottom of screen) is set to Automatic Detection, and recognized the file as django-html. When manually switched back to plain Html, everything works.

Chaplet answered 25/1, 2019 at 18:30 Comment(0)
E
6

Press 𝐜𝐭𝐫𝐥+𝐬𝐡𝐢𝐟𝐭+𝐏 --> type in 𝐂𝐡𝐚𝐧𝐠𝐞 𝐋𝐚𝐧𝐠𝐮𝐚𝐠𝐞 𝐌𝐨𝐝𝐞 --> then select 𝐀𝐮𝐭𝐨 𝐃𝐞𝐭𝐞𝐜𝐭

It works for me.

Edulcorate answered 26/8, 2020 at 17:20 Comment(3)
I don't see anything new in this answerAbutment
@Abutment I think this is still helpful for the new VSCode user like me.Embrocation
Have you checked that this is not be already said in other answers?Abutment
M
5
  1. List item Goto Settings: File -> Preferences -> Settings (CTRL + COMMA shortkey in Ubuntu).
  2. In Search Bar type Emmet.
  3. Find Trigger Expansion On Tab and check it.
Myrilla answered 11/3, 2021 at 13:48 Comment(1)
Thank you... Who knew that this would be a problem in this day and age. The folding stopped working in the <script> in the most recent update.Osrock
F
4

If you want to keep "Django HTML" as the file language and still have auto-closing tags, just add the following to settings.json (provided you have the auto close tag extension installed):

  "auto-close-tag.activationOnLanguage": [
    "django-html",
    (...other languages if needed)
  ],
Fleam answered 10/9, 2021 at 7:28 Comment(0)
M
2

File > Preferences > Keymaps, Search 'Auto close' and click on install. If it doesn't work, reload the plugin.

Medieval answered 13/9, 2018 at 18:36 Comment(0)
K
2

Press Ctrl + Shift + P to open the command. Then, type Change Language Mode an select HTML or any other desired language.

Kokoruda answered 15/5, 2020 at 22:11 Comment(0)
B
2

If you type

div.class

and then press TAB, VS code will automatically close the DIV tag with the given CLASS

But I think you want to do this operation by pressing the ENTER key.

In that case, go to your VS Code user setting & paste the following code:

"emmet.includeLanguages": {
    "javascript": "javascriptreact",
    "vue-html": "html",
    "razor": "html",
    "plaintext": "jade"
}

Now if you type

div.class

& then press the ENTER key, you can see the magic.

However, the above code will make your VS Code auto-completion with ENTER key not only for normal HTML but also the JSX of React, Vue.js snippets will also cover by this.

But If you want to do it only for HTML file, just the following line is enough:

"emmet.includeLanguages": { "javascript": "html" }

Cheers..

Bluenose answered 19/11, 2020 at 5:54 Comment(0)
U
2

If HTML tags autocompleting issue is on JavaScript files, then you just need to change "select language mode" from "JavaScript" to "JavaScript React".

Unconscious answered 5/6, 2022 at 11:56 Comment(0)
H
1

I was suffering from the same problem,then I uninstalled unnecessary extensions from VS Code along with JavaScript (SE) extension and it worked for me.

Hollie answered 25/7, 2019 at 23:32 Comment(0)
R
1

Just check the bottom of your vscode and change the language mode to HTML It might have been showing django-html or click ctrl + shift + p to change the language mode Screenshot

Now click [!] + TAB voila it's done!!!

Roddy answered 28/7, 2020 at 14:24 Comment(0)
H
0

Goto Settings cmd+,

find Emmet: Included Languages add

add Item django-html Value html

django-html

Holothurian answered 6/11, 2023 at 16:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.