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

What is the best way to implement an HTML anchor in VisualForce?

I would like to automatically scroll down to a specific section upon load of the page.

Ideally by going to something like

It should automatically scroll down to the part where it has the anchor name of "documentsSection"

I've already tried both of these but no luck so far:

<a id="documentsSection" name="documentsSection">Documents</a>

<a name="documentsSection">Documents</a>

Any ideas?

share|improve this question

If this is not natively supported in Visualforce, you could work around with javascript as illustrated here.

i.e. invoke a javascript function on load which sets window.location.hash to the anchor element grabbed from the URL.

Here is another related post.

share|improve this answer
up vote 2 down vote accepted

I found the answer! It works just fine when not in development mode.

For some reason I guess there are problems with the footer for the code but this solution now works for me!

share|improve this answer
Consider accepting your own answer as solution so community members know your question is resolved. – Samuel De Rycke Jan 10 '13 at 14:05

If the anchor passed through URL is dynamic, the traditional way to pass anchor via hash might not work.

One workaround is to pass the anchor via parameter, and on page load, use javascript to scroll into the correct view.


jQuery(window).load(function() {

Element to be displayed:

<a id="{!myId}"></a>
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.