HTML comments never display. They are only visible in source code and not visible when viewing a web page in a browser. HTML comments are great for adding notes concerning the code and structure of an HTML page. You can also use HTML comments to ‘disable’ code or sections of your web page.
The following syntax example is a simple HTML comment.
1 2 3 |
<!-- This is an HTML comment --> |
In this HTML example, HTML comments show notes about our code for later review or other developers to read.
1 2 3 4 5 6 7 8 9 10 |
<!-- Here is the title --> <h1>HTML Paragraph Examples</h1> <!-- Here is the first paragraph --> <p>This is the first paragraph. Notice the separation of space between the top of the paragraph as well as the bottom of the heading text. Space is added by default when working with HTML paragraph and heading.</p> <!-- Here is the third paragraph --> <p>This the second paragraph. This text is separated from the first paragraph. Separating text is one of the main reasons to use HTML paragraphs.</p> |
HTML comments can ‘hide’ or ‘disable’ code temporarily while it is in development and then remove the comment tags later to display the HTML in a browser, as shown in the following example.
1 2 3 4 5 6 7 |
<h1>HTML Paragraph Examples</h1> <p>This is the first paragraph. Notice the separation of space between the top of the paragraph as well as the bottom of the heading text. Space is added by default when working with HTML paragraph and heading.</p> <!-- <p>This the second paragraph. This text is separated from the first paragraph. Separating text is one of the main reasons to use HTML paragraphs.</p> --> |
The above HTML code will not display the second paragraph when viewed in a web browser.