Skip to main content

HTML Comments

HTML comments are not shown in the browser, but they help you document your HTML source code with notes and reminders.


HTML Comment Tag

You add a comment with this syntax: <!-- Write your comments here -->. Notice the exclamation point (!) is in the start tag but not in the end tag.

Note: Comments are not displayed by the browser, but they help document your code.

Comment syntax

The shape of an HTML comment.

index.html
<!-- Write your comments here -->

Add Comments

You can place notes and reminders in your code with comments.

Example

Comments used as notes around a paragraph.

Prompt
A page that uses HTML comments as notes and reminders around a paragraph, showing that comments do not appear in the browser.
Output: complete HTML page

Hide Content

Comments can hide content, which is handy when you want to take something out temporarily. Everything between <!-- and --> is hidden from view, whether it is one line or many.

Comments are also great for debugging: you can comment out lines one at a time to find errors.

Hide one paragraph

A single paragraph commented out so it does not show.

Prompt
A page with three short paragraphs where the middle paragraph is commented out, so only two are shown.
Output: complete HTML page

Hide a section

A whole block of HTML hidden inside a multi-line comment.

Prompt
A page where a whole block of HTML (a heading and an image) is hidden inside a multi-line comment between two visible paragraphs.
Output: complete HTML page

Hide Inline Content

Comments can also hide a part in the middle of a line of HTML.

Example

A comment hiding part of a paragraph's text.

Prompt
A page with a single paragraph that has a comment in the middle of the text, hiding that inline part: "This is a paragraph." with a hidden comment between This and is.
Output: complete HTML page