AI Workshop: learn to build apps with AI →
HTML Tips: HTML comments

Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.


A comment in an HTML page is a bit of HTML that is not interpreted by the browser.

A comment is included between the <!-- and the --> tags:

<!-- a comment -->

Comments can also span over multiple lines:

<!--
a
comment -->

You can use comments in HTML for yourself to indicate, for example, why some HTML is present.

You can also use them to remove a portion of HTML you wrote but now you don’t want to display. For testing purposes, perhaps.

In both cases, the person visiting the site will not see the text you commented in the rendered page, but comments are still visible if they try to view the source of the page.

So don’t keep anything secret or anything you don’t want users to see there.

Also, remember that page size matters for speed, so you should not have lots of comments in your HTML in production. Small comments are fine; I am more talking about hundreds of lines of commented HTML.

Lessons in this unit:

0: Introduction
1: Preserving white space and line breaks in a string in HTML
2: HTML, avoid displaying a broken image if the image is not found
3: The HTML figure tag
4: Change image source in dark mode
5: Accept only images in file input
6: ▶︎ HTML comments
7: Some useful tricks available in HTML5
8: How to make an hr invisible
9: Conditionally set an HTML attribute
10: An HTML element id is a global variable