Text Lesson 10 of 42
HTML Comments — Notes in Your Code
Learn how to write HTML comments, use them to organize code and temporarily hide parts of a page, and why you should never put secrets in comments.
Comments are notes you leave inside your code. The browser skips them completely, so visitors don't see them on the page. They are for you and for anyone else who reads your code later — your groupmates, your teacher, or yourself three months from now when you've forgotten everything.
How to write a comment
A comment starts with <!-- and ends with -->. Anything in between is ignored by the browser.
<!-- This is a comment. You won't see it in the result. -->
<p>This paragraph is visible.</p>
<!-- TODO: add our group photo here -->
Comments can span many lines
A single comment can cover several lines. This is useful for longer notes at the top of a file.
<!--
Project: Grade 10 Personal Website
Author: Maria Santos, 10-Mabini
Teacher: Sir Reyes
Date: September 2026
-->
<h1>Maria's Homepage</h1>
<p>Welcome to my website!</p>
Many teachers ask for a header comment like this in every project file. It's a good professional habit too.
Use 1: label the sections of your page
As your page grows, comments make it easy to find things.
<!-- ========== HEADER ========== -->
<h1>Barangay Sta. Cruz Youth Council</h1>
<!-- ========== ANNOUNCEMENTS ========== -->
<h2>Announcements</h2>
<p>Basketball league registration is now open.</p>
<!-- ========== FOOTER ========== -->
<p><small>Contact us at the barangay hall.</small></p>
Use 2: hide code temporarily ("commenting out")
Want to see how your page looks without a certain part, but don't want to delete it? Wrap it in a comment. This is called commenting out code. To bring it back, just remove the comment markers.
<p>Class picture day is on Monday.</p>
<!--
<p>Bring ₱100 for the class picture.</p>
-->
<p>Wear your complete uniform.</p>
Open the editor and delete the <!-- and --> lines. The hidden paragraph appears.
Use 3: explain tricky parts
If you did something unusual, leave a short note explaining why. Good comments explain the reason, not the obvious.
<!-- Bad: says what the code already says -->
<!-- This is a paragraph -->
<p>Hello</p>
<!-- Good: explains why -->
<!-- Phone number is shown as an image because the client asked for it -->
<img src="images/phone.png" alt="Phone: 0917 123 4567">
Comments are not secret!
This is very important. The browser doesn't display comments, but they are still downloaded with the page. Anyone can see them by choosing View Page Source.
Rules and pitfalls
- Don't nest comments. A comment inside a comment ends early at the first
-->, and the rest spills onto the page. - Avoid writing
--(two hyphens) inside a comment. Some tools treat it as an error. - Don't overdo it. A comment on every line makes code harder to read.
Quick Quiz
Check what you learned. Walang grade ito, practice lang. 🙂
By Sir Reyel · Last updated 2026-12-04