Comments

Sometimes web developers want to write notes to themselves in the code. They can write these notes, and keep them invisible from the user, by writing these notes in "comments." Anything included in comment elements will remain hidden, unless the user decides to look at the source code. Here is how you write a comment:

<!-- I don't want anyone to read this 
unless they look at the source code -->

Everything inside the beginning <!-- and the closing --> will remain hidden.

Why would you want to hide content from users? Some developers use comments to help them remember things about the design. They might write "start main content here" or "don't forget to include the alt text in any images inserted here" or anything else that they feel like writing. Comments can be a useful way to check pages for errors too. If part of a page isn't working, you can comment out different parts of it and see how the page renders in the browser. Sometimes this can help you pinpoint errors. It can also be a quick way of removing visible content from a page if you think you may want to keep the content for later. Here's another example:

<p>Here's a paragraph.</p>
<!-- I want to hide the next paragraph
<p>Here's another paragraph, but you can't see it.</p>
end hidden content here -->
<p>Here's a third paragraph</p>

Here's what this looks like in a browser:

Here's a paragraph.

Here's a third paragraph

The middle paragraph is gone, and the comments around the paragraph are gone because all of that is included within the comment tags.

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License.