HTML Comments

Last Updated on

HTML comments are a piece of code that is written in the HTML document but ignored by the web browsers. It has been frequently used by many developers when working on the new experiment scripts. By using the HTML comments, you don’t have to remove the specific HMTL code. The code is still existing there, but it won’t display out to the web browser. Sometimes, we want to experiment on a new piece of code but never want to be removed. We might comment it out for temporary without remove the code, in case we need it again.

We may also use it to help us understand the code better. For example, we will place the HTML comments to leave a small message or information of what and how that specific part of code is doing for the next developer. As we said, the web browsers won’t display it out. But when you check the source code, you will able to see the code comment.

To add the HTML comment, we use <!-- ... --> to comment out the code. Anything placed inside the <!-- and --> will not been shown.

Single Line Comment

<!-- This is a HTML comment, visitors won't see this-->

<p>Hello World! Welcome to Jorcus.com</p>

<!-- Another comment here, visitors won't see this too. Unless they check the source code -->

Multiline Comments

<!-- 
    This is a HTML comment, visitors won't see this.
    Sometimes, we might need long multiline comments. 
    You can accomplish it in this way too.
-->
<p>Hello World! Welcome to Jorcus.com</p>

Comment Out Source Code

<!-- 
    <p>Hello World! Welcome to Jorcus.com</p>
-->

Conditional Comments

<!--[if IE 6]>
    Special instructions for IE 6 here
<![endif]-->

Comment Tag (Deprecated) 👎

We don’t recommend using <comment> tag anymore. It’s deprecated in HTML 5.

<p>Comment tag is <comment>deprecated</comment>in HTML 5. /p>

Spread Your Love By Sharing It On:
Write With ❤️ By Jorcus

Leave a Comment