Adding Comments To Our Code

We may want to write something in the code of our web page that acts as a comment to ourselves – or to other web designers involved in creating our website. We would not want this comment to be shown in the browser, but simply to remain in the code as a note to ourselves, ignored by the browser. Some examples are: a note about a future change that we wish to make to the page, a comment about what the section of code near the comment is for so that we can remember its importance, to temporarily prevent a section of code being displayed by the browser while we are writing and testing our page.

We add a comment, or by putting <!– in front of the text we wish to comment and putting –> after it.

For example:
<!– I must remember to add my new track to the music download page –>
If you want to, you can <a>download my music</a> for free.

When we look at CSS stylesheets, we’ll see a different method for adding comments to the CSS code. In CSS, we can put a /* before the comment text and */ after the text.

No Double Dashes Within Comments
It is invalid code to use double dashes, i.e. two successive hyphens („–„), within a comment. The following examples are invalid:

<!– This comment — is — invalid –>
However, you could separate the two dashes with a space to make it valid:
<!– This comment – – is – – valid –>
<!– ===== – – – ===== – – – ===== –>