Click to skip over navigation

Web Design

   

comments



main menus


help pages


Valid XHTML 1.0!

 

These are completely optional and make no difference to how your web page works. But there are reasons why you may want to put comments or notes in your HTML. Perhaps you are writing the page for an organisation, or society, and know that in the future, other people might have to maintain or update the site. Perhaps you want to leave a note or two for yourself as a reminder that you've not quite finished a particular section, or that you need to come back to it in a couple of weeks when you've worked something out. Sometimes people "comment out" actual tags because they are not needed yet.

What it basically means is that anything inbetween comment tags is completely ignored by the browser. To put a comment in the code you need an opening and closing tag, just as with everything else in HTML. The tags look like this:

    <!--

        Place your comment(s) here

    -->

Bingo: you have a comment in the code. As ever, you need to be precise: so that's two hyphens at each end, always, not one, or three.

Comments do have uses beyond this in some cases. When working with certain more advanced techniques, for instance, <script> tags, you may need to surround the relevant HTML with comment tags, to ensure that they do not cause older browsers to foul up. Newer browsers, which can recognise the advanced tags, are programmed to ignore comment tags in these circumstances. Older browsers just see the comment and breeze past the futuristic tag, unaffected. As with every other piece of cross-browser compatibility, it's a good, indeed necessary, habit to get into.

Back to the top

Back to the menu for lesson 1



Material on this site is © Drew Whitworth, 2005 Permission will usually be given to reproduce material from this site for non-commercial purposes, if credit is given. For enquiries, e-mail Drew at andrew [dot] whitworth [at] manchester [dot] ac [dot] uk.