HTML Comment Out: Syntax of How To Comment Out in HTML

  • Post category:HTML
  • Post author:
  • Post last modified:April 10, 2022
  • Reading time:7 mins read
You are currently viewing HTML Comment Out: Syntax of How To Comment Out in HTML

HTML comment out allows developers to leave notes or add important reminders about their code. HTML comments are used for different purposes. A very popular use case of HTML comments is finding bugs in code. Using HTML comment you can make a block of code into a comment.

HTML comments are used by developers to make clean their code. And add some hints about their code. If a new developer work on this project he/she easily understands the code.

HTML Comment Out

Comments are ignored by any web browser. It is not visible to the user side, only source code readers can see this. It is a good practice to use comments in codes. It is very useful for developers and source code readers to clearly understand the document structure.

Purpose Of HTML Comment

HTML comment out

Basically, HTML comment out is used for three to four reasons. Leave notes and reminders, when a developer writes a thousand lines of codes they go notes because if they come back again the codes they can easily understand their codes.

Secondly, comments are very helpful for finding errors in codes. Convert pieces of code into comments that you think may cause an error in your codes.

And developers commenting out in HTML if the new developer works on this project they can easily understand these codes. Basically, comments in HTML are four types.

HTML Comment Out- Syntax

Let me clear one doubt, HTML comments are not any kind of HTML tag.

An HTML comment tag starts with “<!–” this and closed with “–>” this. Write the text between them on which one you want to make comment.

<!-- HTML Comment-->

How To Comment In HTML – Example

Bellow’s example covers all four HTML comments.

<!DOCTYPE html>
<html>
<head>
<title>HTML Comment</title>
</head>
<body>
<h1>Hello World! <!--Hello inline commemt--><h1>
<!-- This is a single line comment-->
<p>Hello World!</p>
<!-- This is multi-line a comment
<p>Hello World 2</p>
-->
<p> This is a conditional comment</p>
<!--[if IE 6]>
 Special Instructions For IE
<![endif]-->
</body>

Type Of HTML Comment

types of html comment

Basically, HTML comments are four types. Here is a list of all four types of comments.

  • Inline Comment
  • Single line Comment
  • Multiline Comment
  • Conditional Comment

Inline Comment

Basically, Inline comments are started and closed within an HTML tag. this comment is used to leave a short note within a line. developers use this type of comment to leave a short note within a tag. Here is an example of an inline comment.

<p> this is a inline comment.<!-- Inline Comment --> </p>

Single line comment

Single line comments are those comments which start and close in one line. These comments are used by developers to leave notes or reminders and single-line comments are basically used to denote a block of code what it is. Here is an example of single-line comments.

<!DOCTYPE html>
<html>
<head>
<title>HTML Comment</title>
</head>
<body>
<!-- This is a single line comment-->
<p>Hello World!</p>
<!-- This is also a single line comment-->
</body>

Multi-Line Comment

Multi-line comments are those comments which do not start and are closed in one line. These comments are used by developers for finding errors in their code. The convert piece of codes in HTML comments, and browsers treated these codes as comments and ignored them. So developers easily find the bugs. Here is an example of a multiline comment.

<!DOCTYPE html>
<html>
<head>
<title>HTML Comment</title>
</head>
<body>
<p>Hello World!</p>
<!-- This is also a multi-line comment
<p>paragraph 1</p>
<img src="pictire.png">
-->
</body>

Conditional Comments

Conditional comment only works with Internet Explorer it is supported from Explorer 5 and upper versions. The conditional comment is used by developers to give some special instruction to Internet Explorer. The conditional comment was ignored by all other browsers. It only works on Internet Explorer. Here is an example of a conditional comment.

<!DOCTYPE html>
<html>
<head>
<!--[if IE 6]>
 Special Instructions For IE
<![endif]-->
<title>page title</title>]
<style>
</style>
</head>
<body>
<h1>Hello World!</h1>
<p>Hello World!</p>
</body>
</html>

Chapter Summary

  • HTML comments starts with “<!–” and closed with “–>” this characters.
  • HTML Comments are generally used to leave notes and find bugs in codes.
  • Four types of HTML comments you have learned inline comments, single-line comments, Multiline comments, and the fourth is Conditional comments.
  • Generally, Comments are ignoring Web browsers. It is visible only on the source code.

Ashim Khatua

Professionally Web Developer since 2015, And also a Blogger. I am the founder of SiteCodings.com. I love to share my knowledge, which I earned the past few years. I want to share my knowledge with you through my Blog. Keep Reading.

Leave a Reply