HTML Comment <!-- --> Element
I'm not actually sure if it's really called an element. I've heard these referred to as tags. Anyway, this is how commenting works in HTML. It's actually pretty simple. Open a comment with
<!-- and close it with
-->. The stuff in between the opening and closing tags gets commented out. Also useful for adding comments to code, which then won't be visible when the page renders, but will be visible when viewing the html -- the page source, if you will -- in a text editor.
<html> <head> <title>Example</title> </head> <body> <!--<p>An example paragraph used as an example in this example <abbr title="Hypertext Markup Language">HTML</abbr> document as an example of using comments.</p>--> <p>This paragraph will render. The paragraph above will be hidden when the page is displayed in a browser because it's been commented out.</p> </body> </html>
In this example the entire paragraph and the text within the paragraph is commented out and will not be rendered. Whether it's a single line of text or a whole block of code, the comment tags don't change.
<!-- opens the comment and --> closes the comment. Placing the comments inside the
<p> tags would render an empty paragraph.
<p><!--This text won't show up because it is commented out. The paragraph element will still render, but it will be empty.--></p>
The text in this paragraph is commented out and won't be displayed, however, because the comments are within the paragraph tags, an empty paragraph will still render.
Also, I think it's probably a good idea to avoid using
-- within a comment.
See also Complete List of HTML Tags