HTML: How to Comment With Example

Originally: HTML How to Comment With Example — PHPCODER.TECH

In this article HTML How to Comment we discussed How to comment out in HTML?, HTML comment syntax, and two or more examples where we use HTML comment in the document.

Basically, comments are helpful for web developers or designers to know about source code working which is encapsulated with some information about code using Comment Tag by any developer.

Here are the details which we discuss in this article,

Major points about HTML Comment Tag

Also Read: How to Include Comments in CSS

HTML: How to Comment with Example

The HTML comment encapsulate the piece of information by using comment tag.

Syntax

Single Line Comment

<! — This is a comment. Comments are not displayed in the browser →

<p>This is a paragraph.</p>

Multiline Comment

Sometimes we need to comment out multiple lines or some lines of code, then we use multiline comment.

<div>

<p>This text is visible. Check the source code for multi-line comment.</p>

<! —

Hello, world! I am a comment and I am

displayed in multiple lines!

</div>

You can also comment out or hide script code which is define inside <script> tag.

<! — <script type=”text/javascript”>

function displayMsg() {

alert(“Hello World!”)

}

</script> →

OR

<script type=”text/javascript”>

// function displayMsg() {

// alert(“Hello World!”)

// }

</script>

Note: You may also see <comment> tag somewhere but that comment tag is not supported by modern browsers.

Supported Browsers

Chrome (1+)

Edge (All)

Firefox (1+)

IE (All)

Opera (All)

Safari (All)

Here is the complete explanation HTML Comment.

Also, Read

Happy Coding..!

I am a web application developer. FB Community: @mrpandatech, Twitter: @phpcodertech My PHP problem-solving site http://phpcoder.tech