+ Start a Discussion

Structural elements in VF pages (title, body etc.)

Hello all:


I'm struggling to define some basic HTML elements in my VF pages. Note that all my pages are showHeader=false.


The first of these is "title". Though I have added a "title" attribute to my apex:page element, no <title> tags appear in the page when I view it in a browser, and the displayed page title is just the URL.


Secondly, <body>. VF doesn't seem to be emitting <body> tags. Is that my responsibility? I can include them in my site template, just wondered if this is a known issue. Wondering whose job this is, in effect.


Similar issue for <head> tags. Here VF DOES emit these. This perpetuates my confusion about who's on the hook for outputting these basic elements, me or VF. If VF will construct the <head> that's great, but then my question is, how do I insert my own elements in the <head>?


No doubt this is straightforward, but I haven't spotted the answer yet. 




The title attribute of the page element confuses me too.. although I did notice this caveat in the component reference, 'Note, when you are editing a page in developer mode, the page title will not be displayed.'.


You shouldn't include <head> or <body> tags within your pages. Salesforce parses the visualforce code and generates all of this for you. You might say that this is quite irritating, because you need to include things like JavaScript libraries, or CSS files, but there are VF tags that allow you to do this. All you need to do is use the VF components and all the HTML will be generated for you. That said, you can mix VF and almost any HTML that you usually find between the <body> tags.


Hope this helps,



if you are using showHeader="false" you are free to write HTML as you wish.  We try to inject the head tags in the right place but you are welcome to supply them yourself.  This is totally valid:



<apex:page showHeader="false"> <html> <head></head> <body></body> </html> </apex:page>


You can still use <apex:includeScript> and <apex:stylesheet> which should still keep your head tags intact.


You should of course avoid using these tags if you are using the header though, because head and body tags will be generated for you and having dupes of these will definitely have side effects.


What Wes says about the title is correct.  If you're not using developer mode the title will show up for you.  Behind the scenes developer mode is a page that displays your page in an iframe, so that is why the title is not showing up in your browser.



Thanks for the replies. It does appear that title is not working for me, even though I'm not in dev mode.


Jill, is there a way to learn more about exactly which tags will try to emit <head> and <body>? Clearly showHeader=true, but as  I wrote, I think I'm still seeing them in places. I wonder if the apex:composition constructs are doing that. I'll dig further.


Thanks for the insights.


you can always set the title yourself in HTML.  probably because you're taking over the head tag, you need to also specify the title yourself.


I am not sure about the body tags but for head tags, if you include any components on your page that pull in stylesheets or javascript (inputfield is an example but several of our components do)  then we will automatically generate a head tag for you.  However this should not matter, if you've specified a head tag it should not generate a duplicate.


I think the bottom line is, use your own html/head/body tags, and use our components the way you're hoping to.  I don't expect that it will have any ill effects (famous last words, right?)