HTML comments are helpful notes you add to your code for yourself or others to understand better. They don’t appear on the actual website because web browsers ignore them.
Key Points About HTML Comments:
- Web browsers don’t display comments.
- Comments improve code readability and documentation.
- HTML comments are written as
<!-- content -->. - The shortcut to comment out code is Ctrl + /.
- HTML supports both single-line and multi-line comments.
Types of Comments in HTML:
Single-line Comments
Single-line comments in HTML are short notes that you can include in your code to provide explanations or reminders. These comments are written on a single line and are useful for adding brief annotations to your code.
To create a single-line comment in HTML, you use the <!-- and --> tags to denote the beginning and end of the comment, respectively. Anything written between these tags is considered a comment and is ignored by web browsers when rendering the webpage.
Example
<!-- This is a single-line comment -->Multi-line Comments
Multi-line comments in HTML allow you to write longer explanations or notes that span across multiple lines. These comments are useful for providing detailed documentation or temporarily disabling blocks of code without deleting them.
To create a multi-line comment in HTML, you use the <!-- at the beginning of the comment and --> at the end. Anything written between these tags, including line breaks, is considered part of the comment and will be ignored by web browsers when rendering the webpage.
Example
<!--
This is a multi-line comment.
It can span across multiple lines,
allowing for detailed explanations or notes.
-->Watch the video below to see how comments are not displayed on the website.