Skip to main content

Sun, Oct 6, 2013 7:37 PM


What are HTML/CSS comments?

What is a Comment?

A comment is a string of code or text within HTML, XML, CSS, as well as other programming languages that is not viewed or acted upon by the web browser. It is in the code to provide information about the code, to temporarily disable a section, or to provide other feedback from the code developers.

How to Write Comments

Writing comments in HTML and XML is very easy. Simply surround the text you want commented out with:

<!-- This is a comment. Everything between the symbols is considered Comments and they are not displayed in the browser. -->

In CSS, it's a little different, but still very simple. For CSS comments rather than HTML:

/* and&nbsp; */

Traditionally comments in HTML are used for:

  • Describe and explain complicated code.

  • Used to tell other people working on the page information about that page.

  • Provide details about when the code was edited or reviewed (date).

  • Use comments to hide portions of the page that are still in development and are going to be used later.

  • Explanations of complex table structures

  • Commented code makes it easier for code to be transferred from one team member to another.

  • Comments help QA to test the code, because they can tell what the developer intended - even if it wasn't achieved.

  • You can use comments to explain your code, which can help you when you edit the source code at a later date. Even if you're the only person who edits your Web pages, comments can be useful. If you only edit a complicated page once a year, it's easy to forget how you built the table or put together the CSS. With comments, you don't have to remember because it's already explained right there for you.

  • Section Marking - Use it to mark the beginning and end of the section, block, or function.

  • Problem Solving - When building a site it can help with problem solving and to explain to yourself any unfamiliar chunks of code.  If I there is a CSS layout issue you can comment out large/recent sections of code until you eventually identify where the problem lies.

  • Page information – You can put comments at the top of the web page document to include information about that page and what it does. You can include things like the author, developer, date edited, and what was changed. It's very helpful to see at least the last few edits right there at the top of the page.

This conversation is no longer open for comments or replies and is no longer visible to community members.


No Responses!