Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

At least in my experience, most of my web applications are not static web pages but dynamic from a scripting engine.

Just curious, does anyone use HTML comments aside from for IE fixes anymore?

share|improve this question
2  
Funnily, I read the question as "HTML in comments" (or "comments formatted in HTML"), thinking of /// .NET code documentation and the like. Totally different question. I'm outa here... ;-) – peSHIr Sep 28 '10 at 8:35
This is a poll. – Dynamic May 12 '12 at 18:21

closed as not constructive by Thomas Owens May 13 '12 at 2:38

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or specific expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, see the FAQ for guidance.

15 Answers

up vote 11 down vote accepted

I don't for one reason. It is sent to the client. It may not matter where bandwidth is unlimited but it does matter to people who pay by (M)bytes.

share|improve this answer
2  
Interesting consideration, never really considered the bandwidth aspect of it. – Chris Sep 17 '10 at 18:48

They tend to show up a lot in articles at The Daily WTF. The authors put them in there as jokes for people who know to look at the source...

share|improve this answer

I do... I comment everything - maybe obsesively

share|improve this answer

In large environments even if you do your optimization devices strip them before they reach the client.

share|improve this answer

Yes, I do.

Why? Well, because their content is also dynamic and I use it as debug output!

share|improve this answer

Sometimes I'll "comment stuff out" when using technologies that don't have server-side-directive comments and accidentally leave it in. Also, sometimes it's helpful when setting up a skeletal site layout for someone to point out stuff like "put your menu items here," or "put your page content here."

share|improve this answer

I tend to use server side comments in favour of client-side comments. But that's because my comments can be rather rude and I wouldn't want anyone viewing source and seeing them! :)

share|improve this answer
Ill drink to that, comments can be fun but clients need not be reading my profanity and humor. – Chris Sep 17 '10 at 18:48
3  
Beware those rude comments... we had a menu once that the language we used forced us to use a template to create. Our standard template just tossed an error if you invoked something that wasn't coded yet. It wasn't too brilliant though when someone put in "You forgot the code dips**t" and that made it into the live app. Needless to say , the first person that found it was the person with the least sense of humor. Fortunately, she called me and I could honestly say "B did it." – MIA Sep 17 '10 at 22:33
I enjoy making those comments, especially around a particuar nasty piece of code that frustrated me. I make sure to always make them server side though – WalterJ89 Oct 7 '10 at 15:02

No I try to avoid it. I will often give a div a rather descriptive id so that if someone is looking for some code they can quickly find it.

The main reason why is b/c the comments you write are easily seen by anyone who bothers to view the source. If it's not something the end user should see, don't put it in the HTML comments.

share|improve this answer
Yes this is the sort of thing I was getting at. – Chris Sep 17 '10 at 18:47

Yes, I often use them to mark where, for example, banner ad code should be, or other dynamic content, for use in debugging should things not be showing up correctly. The comments, though, dont look like the ones you'd put in source code. They're usually just markers.

share|improve this answer

I'll often use them when doing a table or something with a small amount of HTML, and a bunch of repetitive PHP, just to quickly say what's in this column. Usually something small, like `

<td><!-- Phone number -->
    <?php echo $user->phone ?>
</td>
<td><!-- Email -->
    <?php echo $user->email ?>
</td>

Bad example, due to just an echo, but it's usually to help visually identify and compartmentalize my code. I have issues reading things if they're too jumbled without something to split them up, like green comments, rather than orange in my PHP :P

share|improve this answer

I'll use them if there's something that is potentially unclear. If I'm closing a tag, and the opening of the tag is several screens of code above the closing, I'll often mark that with a comment. If I've done something weird to work around some obscure browser bug, I'll mark that, too. And I'll often use them to mark large sections of the page. (HTML 5 tags are good mojo, but sometimes a nice syntax-highlighted comment makes your HTML easier to grok.)

I definitely use fewer HTML comments than CSS comments, or comments in whatever language I'm writing the business logic of the site in. And when I'm working with a templating language, I'll often leave comments in the template that don't get rendered to html, especially if the comment only makes sense if you're looking at the template, rather than the rendered code.

share|improve this answer

I might do something like <!-- ID: <?=$Id?> --> which can be handy for debugging all sorts of things. Let's you know which database column you're talking about.

And recently I created a form of which every field was hidden for submitting data to PayPal. Some of the input names are rather odd and non-descriptive, so I included comments which I decided to put as HTML comments so I can read them in either view of the code.

share|improve this answer

I use them for giving credits to icon_packs/jquery_codes/css_frameworks/etc authors, when no visible linking is required.

Otherwise I use PHP comments.

share|improve this answer

I will occasionally use them to indicate the end of a tag:

<div id=main_content>

...zillions of lines of stuff...

</div><!-- #main_content>

That's proven useful on occasion, especially if I'm dealing with a lot of templates-inside-templates. Other than that not really.

share|improve this answer
I can see that being usefull. My IDE usually highlights that end tag for me. – WalterJ89 Oct 7 '10 at 15:05

Yes, to insert scripts in a "Valid XHTML" style.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.