Comment Tag Example


Although they are not visible in the browser, HTML comments might be
useful for describing your HTML source code.

Comment Tag in HTML

The following syntax can be used to add comments to your HTML source:

Example:

<!– Write your comments here –>

You’ll see that the start tag has an exclamation point (!) while the end
tag does not.

Note : Although the browser does not display comments, they can aid in the
documentation of your HTML source code.

Comment Add

You can add alerts and reminders using comments in your HTML code:

Example:

<!DOCTYPE html>
<html>
<head>
    <meta charset=“utf-8”>
    <meta name=“viewport” content=“width=device-width, initial-scale=1”>
    <title>HTML comments</title>
</head>
<body>
    <!– This is a comment –>
    <p>This is a paragraph.</p>
    <!– The browser does not display comments –>
</body>
</html>

Content Hide

It is possible to hide content using comments.

If you want to momentarily obscure material, this can be useful:


Example:

<!DOCTYPE html>
<html>
<head>
    <meta charset=“utf-8”>
    <meta name=“viewport” content=“width=device-width, initial-scale=1”>
    <title>HTML hide comments</title>
</head>
<body>
    <p>The following paragraph. </p>
    <p>This is yet another paragraph.</p>
    <!– <p>This is yet another paragraph.</p> –>
    <p>This is also a paragraph.</p>
</body>
</html>


Beat Mark Project (download)



Additionally, you can conceal many lines. The text between the <!–
and the –> will be obscured on the screen.

Example:

<!DOCTYPE html>
<html>
<head>
    <meta charset=“utf-8”>
    <meta name=“viewport” content=“width=device-width, initial-scale=1”>
    <title>HTML comments</title>
</head>
<body>
    <p>The following paragraph. </p>
    <!– 
    <p>This is yet another paragraph.</p> 
    <img border=”0″ src=”demo.jpg” alt=”demo”>
    –>

    <p>This is also a paragraph.</p>
</body>
</html>

Because each line of HTML code may be individually commented out to check
for flaws, comments are also excellent for debugging HTML.


Example:

<!DOCTYPE html>
<html>
<head>
    <meta charset=“utf-8”>
    <meta name=“viewport” content=“width=device-width, initial-scale=1”>
    <title>HTML comments</title>
</head>
<body>
    <div>
        <p>This <!– great paragraph –> is a paragraph.</p>
    </div>
</body>
</html>

All Material (download)

Rate this post

Categorized in: