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.

3 Answers 3


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: http://success.salesforce.com/ideaView?id=08730000000iEyFAAU along with a workaround if you really need it rendered.

  • 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. Aug 28, 2012 at 23:35
  • 3
    @DanielBallinger - na14.salesforce.com/help/doc/en/… (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.] Aug 28, 2012 at 23:46
  • Looks like I'll need to update the Visualforce pages to the 26.0 API version to get this. Thanks. Aug 28, 2012 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.

  • 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 --> Aug 28, 2012 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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .