HTML – Comments
In HTML, comments are used to add notes or explanations within the code that are not displayed on the web page. They are helpful for developers to provide additional information or to temporarily disable specific parts of the code without deleting them.
To create a comment in HTML, you can use the following syntax:
1 |
<!-- This is a comment --> |
Comments in HTML start with <!--
and end with -->
. Everything between these delimiters is treated as a comment and is ignored by the web browser when rendering the page.
Here’s an example of how comments can be used in an HTML document:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<!DOCTYPE html> <html> <head> <title>My Web Page</title> </head> <body> <!-- This is the header section --> <header> <h1>Welcome to my website!</h1> <!-- <p>This paragraph is temporarily disabled</p> --> </header> <!-- This is the main content section --> <section> <h2>About Me</h2> <p>Here is some information about myself...</p> </section> <!-- This is the footer section --> <footer> <p>© 2023 My Web Page. All rights reserved.</p> </footer> </body> </html> |
In the above example, you can see how comments are used to provide descriptions for different sections of the HTML document and to temporarily disable a paragraph within the header.
Remember that comments are not visible on the rendered web page and are only meant for developers to read and understand the code.