skip to Main Content

I’m encountering an issue in Visual Studio Code when pasting HTML code, where an extra closing tag is automatically inserted, messing up the structure of my code. This happens with even the simplest HTML snippets.

Example:
When I copy and paste this simple HTML:

<footer>
    <p>Hi</p>
</footer>

It pastes as:

<footer></footer>
    <p>Hi</p>
</footer>

An unexpected closing tag is added at the top, which is incorrect and breaks my code.

What I’ve tried

  1. Disabled auto-formatting settings:
"editor.formatOnPaste": false
"editor.formatOnSave": false
"editor.defaultFormatter": null
  1. Disabled Emmet:
"emmet.triggerExpansionOnTab": false
  1. Disabled extensions:
    Auto Close Tag, Auto Rename Tag, Prettier.

  2. Tried setting Prettier as the default formatter, but no change.

  3. Checked the Problems Panel, but there are no errors reported.

  4. I’ve also reset all settings to default and even reinstalled VS Code, but the issue still occurs.

Environment:
Visual Studio Code version: 1.93
OS: Windows
HTML-related extensions installed: Prettier, Auto Close Tag, Auto Rename Tag, Live Server.

I can’t find a solution to prevent this auto-insertion of an extra closing tag. Any help would be appreciated!

2

Answers


  1. I have had the same issue, very annoying. What helped it for me (and still keeping the functionality when writing new tags) was installing the extension "Paste and Indent". However, it still works a little bit strangely, but that may be because of me having vim as an extension, so that I cannot paste when in insert mode (then it still gets the extra closing tag), and I must use the right click menu to paste, keyboard shortcut not working.

    Login or Signup to reply.
  2. I ran into this after adding the Prettier extension for the first time yesterday. I was able to fix it by changing the default html formatter in settings.json:

    "[html]": {
     "editor.defaultFormatter": "vscode.html-language-features"
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search