Home > Back-end >  Why are there two ways to comment code in HTML and which way to use?
Why are there two ways to comment code in HTML and which way to use?

Time:10-28

I am new to HTML. I'm learning HTML from this YouTube video. When I'm going to comment code in VS Code (using Command /), this is by no means the way to show comments taught in the YouTube video, but a different way Ways to annotate code.

Sample code:

<!DOCTYPE html>
<html>
  <body>
    <h1>My First Heading</h1>

    <p>My first paragraph.</p>
  </body>
</html>

When using Command / in VS Code, the result is as follows:

{% comment %} <!DOCTYPE html>
<html>
  <body>
    <h1>My First Heading</h1>

    <p>My first paragraph.</p>
  </body>
</html> {% endcomment %}

When using the way taught in this YouTube video, the results are as follows:

<!--
<!DOCTYPE html>
<html>
  <body>
    <h1>My First Heading</h1>

    <p>My first paragraph.</p>
  </body>
</html>
-->

Why are there two ways to comment code in HTML and which way to use? I would appreciate any help. Thank you in advance!

CodePudding user response:

The HTML comment is <!-- your comment -->. You should use this one.

{% comment %} seems like a framework template. If you save your file to HTML, this syntax appears in your documents.

CodePudding user response:

maybe your vs code version are different

  • Related