<!--This is a comment which serves as a note to developers and programmers-->
HTML Comment Tag
You can use HTML Comment tag to explain the code to another designer but not to the end user. You can also refer it during editing source code so basically –
- The comment tag inserts comment inside document code.
- Comments are invisible to the end users, so this also helps in hiding a set of codes.
- Sometimes, you do not want to delete a code but you just want to hide it, then you can use comments.
Note/warning/suggestion: Please provide the comments only when it is necessary.
Suppose, if a code is self-explanatory, then we should avoid proving comments until it is really required to do so. Putting too much of comments are not good. If there is a complex code, then it is a good idea to provide a comment so that another programmer or developer who tries to read your code is able to understand it better from the comments.
You can also use a comment to debug your code. If you feel that some line of code is causing an issue, you can comment them and run the code and see if it works.
Please note that you should not give a space after the opening angular bracket or before the closing angular bracket while coding for comments.
For Example:
Suppose, if a code is self-explanatory, then we should avoid proving comments until it is really required to do so. Putting too much of comments are not good. If there is a complex code, then it is a good idea to provide a comment so that another programmer or developer who tries to read your code is able to understand it better from the comments.
You can also use a comment to debug your code. If you feel that some line of code is causing an issue, you can comment them and run the code and see if it works.
Please note that you should not give a space after the opening angular bracket or before the closing angular bracket while coding for comments.
For Example:
HTML comments syntax
Example of comment tag
<!-- Learn HTML from scratch --> <h4>Example for comment tag</h4> <!-- Comments are invisible to end users. --> <p>Comment tag is used to insert comments inside document code. It is not visible to end users. It is only visible in code area.</p>
Example of double line comment
<p>Example of a double line comment tag.</p> <!--Learn HTML from scratch. If you learn CSS along with HTML, you can enhance the look and feel of your website and if you use Bootstrap then you can easily make your website responsive. This is an example of double line comments--> <p>Use double line comments if your comment does not fit in a line</p>
Comments in Style Sheets
In CSS, on fewer occasions, comments are used to prevent some specific styles. You will understand more about CSS once you learn our CSS tutorial.
/* CSS style properties here */
Sometimes, we require to debug the code to check for some layout errors, then we can comment out the CSS style properties as well to see if the error is due to the style sheet.
Interview Questions & Answer
HTML Comments is a comment which serves as a note to developers and programmers. We can also use HTML comments to leave notes and instructions to other developers who may be working on the files in the future.
Comments in HTML For example: <!-- HTML Comment -->