In HTML, the comment tag, denoted as `<!– Comment –>`, serves as a valuable tool for adding comments within your code. This practice is highly recommended because it aids both the coder and anyone reading the code in comprehending its purpose. Comments are particularly beneficial when dealing with intricate or complex code sequences, as they provide insight into the steps involved. Additionally, comments prove invaluable during the debugging process.
This simple piece of code holds the unique property of being ignored or “hidden” by web browsers, meaning it does not appear in the browser’s display. Instead, it functions as a form of internal documentation for those working on the code.
The syntax for a comment is straightforward: `<!– Your comments here –>`.
There are three main types of HTML comments:
2.Multi-line comment: Multi-line comments are used when more extensive commentary is needed and are also enclosed within `<!–` and `–>` tags. They can span multiple lines.
3.Using `<comment>` tag: Although less common, you can also use the `<comment>` tag to insert comments within your HTML code.
In summary, HTML comments, whether single-line or multi-line, are essential for enhancing code clarity and assisting in understanding complex code structures. They are an indispensable aid during the coding and debugging processes.
Implementation of the above concept is shown below:
<!DOCTYPE html>
<html>
<body>
<!–This is heading Tag, It wont be displayed by the browser –>
<h1>GeeksforGeeks</h1>
<!–This is single line comment,It wont be displayed by the browser –>
<h2>This is single line comment</h2>
</body>
</html>
Multi-line comment: Multiple lines can be given by the syntax (<!– –>), Basically it’s the same as we used in single line comment, difference is half part of the comment (” –> “), is appended where the intended comment line ends.
Implementation of the above concept is shown below:
<!DOCTYPE html>
<html>
<body>
<!– This is
heading tag –>
<h1>MurmuSoftware Infotech</h1>
<!– This is
multi-line
comment –>
<h2>This is multi-line comment</h2>
</body>
</html>
Using <comment> tag: There used to be an HTML <comment> tag, but currently it is not supported by any modern browser.
Implementation of the above browser is shown below:
<!DOCTYPE html>
<html>
<body>
<comment>This is heading tag</comment>
<h1>GeeksforGeeks</h1>
<comment>This is multi-line
comment
</comment>
<h2>This is a comment using</h2>
</body>
</html>
Note: The <comment> tag is not supported by modern browsers.
Not a member yet? Register now
Are you a member? Login now