/ factorpad.com / tech / html5 / reference / html-comment-tag.html
An ad-free and cookie-free website.
Beginner
The <!-- comment ->
tag is
essential to document your code with notes for later reference.
Comments act a helpful reminders for anyone reviewing the HTML markup.
Comments also help with debugging. Here you can add and remove lines by placing a comment around it, instead of deleting it.
The <!-- comment ->
tag can
be used for single line and multiline comments. The commented lines
will be skipped over by the program and not executed.
The <!-- comment ->
tag follows
an easy to forget pattern that must be followed strictly.
The <!-- comment ->
tag is
actually bordered by two strings. On the left is the text string
<!--
and on the right is
-->
. So all of the comment-specific
text between these two text strings is off limits to the browser.
In three scenarios below, the interior text string cannot form certain patterns because it would close out a comment tag. So these rules apply.
The interior text string:
>
or
->
.<--
or
-->
or
--!>
.<!-
.
So it is best to summarize by saying, avoid making comments with these characters.
So a basic HTML document might look like this, with the second line blocked off as a comment.
In some circumstances conditions are added to comments to tell the browser to use a specific code for a specific browser. This however is rare.
Unlike most tags, attributes do not apply.
Attribute | Purpose |
---|---|
-- |
-- |
In this example, we have three "work in progress" page
title
tags and commented out two of
them.
Here, we have the same scenario except we added a comment to
the end of the working title
tag.
Here, the first part of the line
<title>Page Title 2</title>
will be interpreted by the browser, but the second part will not.
Here, we use a multi-line comment to block out the first two
title
tags.
Only the third
<title>Page Title 3</title>
will be interpreted by the browser.
The following are essential tags that should be included in every HTML document.
We also have a YouTube Channel for those who like to watch. Subscribe there and follow @factorpad on Twitter for updates.
DOCTYPE
declaration, click Back.a
tag,
click Next./ factorpad.com / tech / html5 / reference / html-comment-tag.html
A newly-updated free resource. Connect and refer a friend today.