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.
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.
HTML comments syntax
Example of comment tag
Example of double line comment
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.