Ways to Comment in HTML
There are two ways to comment in HTML. Each type of comment can be used to add comments in HTML.
Comment | Descriptions | Syntax |
---|---|---|
Single-line | The single-line comment is given inside the ( <!– comment –> ) tag. | <!– comment –> |
Multi-line | It follows the syntax of a single-line comment by adding multiple lines in the comment. | <!– Multi |
Note: The shortcut for adding the comment through the keyboard is by typing Ctrl + / in Windows, and Command + / for Mac users.
HTML Comments Example
- Single Line Comment in HTML
- Multiline Comment in HTML
Example 1: This HTML code shows how to write single-line comments and how to write an inline comment in HTML.
<!DOCTYPE html>
<html>
<body>
<!--This is heading Tag-->
<h1>w3wiki</h1>
<!--This is single line comment-->
<h2>This is <!--given for--> single line comment</h2>
</body>
</html>
Output: None of the comment will render on the browsers.
Example 2: The following HTML code shows how to write multi-line comments and how to write hidden HTML code sections.
<!DOCTYPE html>
<html>
<body>
<!-- This is
heading tag -->
<h1>w3wiki</h1>
<!-- This is
multi-line
comment -->
<h2>This is multi-line comment</h2>
<!-- <button style="font-family: Sans-serif;">
Click Me
</button> -->
</body>
</html>
Output: None of the comment will render on the browsers.
HTML Comments
HTML comments are an very important for developers, providing a way to annotate code without affecting the rendered webpage. HTML Comments enhance code readability, facilitate collaboration, and can be used to temporarily disable code segments. Enclosed within <!–
and –>
, HTML comments serve as invisible notes within the code.
Contact Us