Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

It appears any HTML comments in a Visualforce page are stripped out before the content reaches the users browser.

Is there a way to render comments?

There are some cases where the comments are useful, such as in debugging and CSS conditional comments.

share|improve this question
up vote 5 down vote accepted

Visualforce definitely strips out the HTML comments and does not render them in the browser as HTML comments. I have observed it, but I don't ever remember reading it in any documentation. Here's the idea to stop that: along with a workaround if you really need it rendered.

share|improve this answer
I see in the idea there is mention that "support for conditional comments is going to be provided" in Winter 13. I couldn't find any reference to this after a quick search. – Daniel Ballinger Aug 28 '12 at 23:35
@DanielBallinger -… (page 180): "Prior to Winter ’13, HTML and XML comments were allowed in Visualforce pages but were automatically removed during page rendering. This included Internet Explorer-specific “conditional comments” that are often used to address browser compatibility issues. In Winter ’13, these comments are recognized by Visualforce and passed through to the browser." [It is just the conditional comments that will be recognized.] – Peter Knolle Aug 28 '12 at 23:46
Looks like I'll need to update the Visualforce pages to the 26.0 API version to get this. Thanks. – Daniel Ballinger Aug 28 '12 at 23:53

Daniel are you referring to comments inside of VF tags?

I have used standard <!-- comment --> in VF pages repeatedly with no problems.

share|improve this answer
I've put a basic plain text comment immediately under the opening <apex:Page> tag. The Visualforce page saves fine, but I can't see the comment in the resulting HTML. There are other comments, such as <!-- Main Body Starts Here --> – Daniel Ballinger Aug 28 '12 at 21:52

This is how we have accomplished this in the past:

<apex:outputText value="<" escape="false" />!-- COMMENT HERE --<apex:outputText value=">" escape="false" />

It's not pretty, by any means, but in our case it was necessary (for compatibility with some JavaScript code). If you absolutely need comments to render in the HTML, then it's at least a working solution.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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