Ad space (banner)
🎨HTML & CSS Lessons
Lesson 14 / 50

How to Write Comments

In this lesson you'll learn how to write comments in HTML and CSS so you can write code that's easy to understand even when you come back to it later. This is for people searching "HTML how to comment out."

A comment is a "note for humans" that has no effect on how the page displays. In HTML, wrapping something in <!-- --> makes it a comment; in CSS, it's /* */. This is useful as an explanation for yourself when you look back later, or for anyone working alongside you.

The sample code uses an HTML comment to mark a section boundary, and a CSS comment to note the intent behind a style. You can also confirm, from the fact that the commented-out <p> tag isn't actually displayed, that a comment is a mechanism for skipping processing.

A common beginner stumbling block is that HTML and CSS use different comment syntax. Using HTML's <!-- --> inside CSS, or CSS's /* */ inside HTML, won't be correctly recognized as a comment. You need to remember the right syntax for each language.

Leaving notes like "what is this section for" or "why does this style use this value" lets you grasp the code without confusion even as it grows long. This is also used to temporarily disable code (commenting it out), a way of writing that's essential in real work too.

HTML & CSS
OUTPUT

💡 The preview runs entirely on this page — nothing is sent externally.

Ad space (banner)
Ad space (in-article)