- HTML — Comments
- Example
- Valid vs Invalid Comments
- Example
- Multiline Comments
- Example
- Conditional Comments
- Example
- HTML Comments
- HTML Comment Tag
- Add Comments
- Example
- Hide Content
- Example
- Example
- Hide Inline Content
- Example
- HTML Exercises
- COLOR PICKER
- Report Error
- Thank You For Helping Us!
- HTML Comment – How to Comment Out a Line or Tag in HTML
- The HTML Comment Tag
- When to Use HTML Comments
- How to Write Single-Line Comments in HTML
- How to Write Inline Comments in HTML
- How to Write Multi-Line Comments in HTML
- How to Comment Out a Tag in HTML
- Keyboard Shortcut for Adding HTML Comments
- Conclusion
- HTML Comments: How to Comment Out your HTML Code
- Example
- Conditional Comments
- Example
- IE Conditional Comments
- More info on HTML:
HTML — Comments
Comment is a piece of code which is ignored by any web browser. It is a good practice to add comments into your HTML code, especially in complex documents, to indicate sections of a document, and any other notes to anyone looking at the code. Comments help you and others understand your code and increases code readability.
HTML comments are placed in between tags. So, any content placed with-in tags will be treated as comment and will be completely ignored by the browser.
Example
Document content goes here.
This will produce the following result without displaying the content given as a part of comments −
Valid vs Invalid Comments
Comments do not nest which means a comment cannot be put inside another comment. Second the double-dash sequence «—» may not appear inside a comment except as part of the closing —> tag. You must also make sure that there are no spaces in the start-of comment string.
Example
Here, the given comment is a valid comment and will be wiped off by the browser.
Document content goes here.
This will produce the following result −
But, following line is not a valid comment and will be displayed by the browser. This is because there is a space between the left angle bracket and the exclamation mark.
< !-- This is not a valid comment -->Document content goes here.
This will produce the following result −
Multiline Comments
So far we have seen single line comments, but HTML supports multi-line comments as well.
You can comment multiple lines by the special beginning tag placed before the first line and end of the last line as shown in the given example below.
Example
Document content goes here.
This will produce the following result −
Conditional Comments
Conditional comments only work in Internet Explorer (IE) on Windows but they are ignored by other browsers. They are supported from Explorer 5 onwards, and you can use them to give conditional instructions to different versions of IE.
Example
Hello , World!