HTML Comments
HTML comments allow you to add notes or explanations inside your code. They are ignored by the browser and do not appear on the webpage. Comments are useful for documentation, reminders, and making your code easier to understand.
Single-Line Comment
Syntax:
<!-- This is a single-line comment -->Example:
<p>Hello World!</p><!-- This is a comment that will not show in the browser -->
Output:
Hello World!
Multi-Line Comment
You can write comments spanning multiple lines using the same syntax.
Syntax:
<!-- This is a multi-line comment. <br>You can write as many lines as needed here. -->
Example:
<!-- Below is a heading element.This comment explains what it does. -->
<h2>Welcome to ByteAcademy</h2>
Output:
Welcome to ByteAcademy
Comments to Hide Code
You can disable code by wrapping it inside a comment. This is useful for testing or fixing layout issues.
Example:
<!-- <p>This paragraph is hidden by a comment.</p> --><p>This paragraph is visible.</p>
Output:
This paragraph is visible.