HTML Comments

In HTML, a comment is text that is marked as documentation.

Comments are for developers only. They are not visible to the users.



A comment in HTML.

<!-- A note that documents the code -->


Comments are added with this syntax:  <!--  . . .   --> .
Anything between <!-- and --> is hidden from the user.

<!-- Insert a comment here -->

Note:  Comments explain the functionality of the code. This makes it easier to support and maintain the code at a later stage or by another developer.

Comment Example

The comment is not visible, whereas the paragraph is.

This paragraph is visible.

<!-- This comment is not visible. -->
<p>This paragraph is visible.</p>

Tip:  Although HTML comments are not visible on the page, they do appear in the page source.
Therefore, don't include confidential information in your comments.

Tip:  You can also comment large blocks of code, which is referred to as: commenting out the code. Developers commonly use this technique during early page development.

Code Tags

The comment tag is part of a group of tags that create coding (programming) related features on web pages. This group is referred to as the Code tag group. Together, they allow you to create code-friendly pages.

A list of code tags.

Element Description
<pre> Displays pre-formatted text in fixed-width font -- usually computer code
<code> An element that is used to display computer code
<samp> Displays sample output from a coumputer code
<output> Displays output results of a calculation
<var> Defines its content as a variable
<!--...--> Marks text as comments in the source code. Not visible to users

You may also like

Last updated on Sep 30, 2023