Forum Moderators: open

Message Too Old, No Replies

Comments in HTML code

How to put in quick comments and remarks

         

Digmen1

8:36 pm on Sep 11, 2007 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi Guys

I am new to HTML (six months) but used to using Basic (way back) and Microsoft Access (10 years)

With these two programs it is very easy to insert remarks and comments to your code.

But with HTML and CSS it is very tedious.

With Basic you just typed in the word REM and with Access you just typed an apostrophe ' followed by your remarks or comments.

This made it very easy to disable code whilst testing you just put a REM or ' in front of the line of code.

With HTML you have to type in a tag <!--comment--> etc.

Does anyone know of a quick way to do this? in HTML and CSS?

Kind Regards

Digby

penders

9:43 pm on Sep 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



But REM or ' as you describe can only be used for single line comments. Unless you have an editor/macro that can comment out multiple lines in this way, and uncomment them again, its usefulness for commenting out large blocks is limited.

The HTML comment can span many lines...

<!-- 
line 1
line 2
etc.
-->

As can the CSS comment...

/* 
blah
blah
etc.
*/

But they can't themselves contain other comments, which can be a problem - there is no single line comment, such as a double slash (this would indeed be handy). I find this particularly troublesome with CSS.

If you are using a server-side script such as PHP, then you could comment out large sections of your HTML, JS (or even CSS) using server-side code, such as...

<?php /*
Any HTML, JS or whatever...
etc. etc.
*/?>

This then won't even appear in the output.

penders

12:16 pm on Sep 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This made it very easy to disable code whilst testing you just put a REM or ' in front of the line of code.

Just to add, I believe you can use a single apostrophe (') to comment out a single line of VBScript, which might be contained within a SCRIPT section in your HTML.

...there is no single line comment (in HTML)

Since HTML is a markup language (as opposed to a programming language) and sequences of white space are collapsed, it would not make much sense to have single line comments, as the opening comment marker would result in the rest of the document being commented out...

For instance, if you tried to make "//" as a single line comment marker, then if you had the following markup...

<p>This is a paragraph 
with some lines
//of text, although
it is really just one
line.</p>

Is the same as...

<p>This is a paragraph with some lines //of text, although it is really just one line.</p>

Which clearly will not work as intended.