HTML Comments: How To Create and Use In HTML Code? – POFTUT

HTML Comments: How To Create and Use In HTML Code?

HTML is a very popular scripting or coding language used to create web pages. HTML provides different tags in order to create different units like textbox, color, paragraph, list, etc. While using HTML we may need to put some information about the code and tags. In this tutorial, we will learn how to create comments.

Single Line Comment

HTML comments are created with the <!-- and --> tags. <!-- is used to specify the start of the comment. --> is used to specify the end of the comment. The content between start and end tags of comment will be omitted by the browser and they will not show to the browser tab to the user. We can create a single line comment by using comment tags in the same line.

Multiline Comment

We can use HTML comment in a multiline way. If we have a lot of information to write into comment we can use HTML multiline comment. The start tag <!-- and end tag --> will surround multiple lines like below. We will see that we can use comment tags in the same line of the comment text or in a new line too.

Conditional HTML Comment

Conditional HTML comments are only supported y the Microsoft Internet Explorer and Edge. They are supported from version 5 of the Internet Explorer and all versions of the Edge. Conditional HTML comment will only exist if the running browser is Microsoft Internet Explorer. If not there will be no comment in the HTML code. We will put [if IE 6] after HTML comment the start tag.

Invalid Comment Examples

Up to now, we have learned different type of comments. But while using comments we may create invalid or error-prone comments. In this part, we will list some generally error-prone comment examples.

Comment Tag

Up to now, we have used <!-- and --> as comment start and end. HTML supports and as comment tag. But this support is dropped with the HTML version 5. So using this type of comment is very error-prone.

Comment Tag

Comment Tag

Comment HTML Tag/Code

We generally assume that comment should contain human-readable or normal language text. But we can use comments to comment normal HTML code or tags too. This can be useful if we want to try some HTML elements and tags by enabling and disabling the element and tag. In this following example, we will comment on the button HTML tag.

Comment JavaScript Code/Script

JavaScript is a defacto web scripting language where the code is executed on the client browser. While developing JavaScript code we may want to comment the code in order to make some tests and checks. We can use HTML Comment tags to JavaScript code like below.

Comment CSS Code

Cascading Style Sheet or CSS can be commented with the HTML comment tags too. This will disable the CSS code effect on the HTML code and can be useful to test some CSS code easily without coding again and again.

Leave a Reply

Your email address will not be published. Required fields are marked *

Enjoy this blog? Please spread the word :)