I'm trying to figure out how to set the "lang" attribute on the HTML element for a Visualforce page without having to manually add the html element or use Javascript. I realize that I can set applyHTMLTag="false" and add the element myself, and have also had success with the following jQuery:

jQuery(document).ready(function(){jQuery("html").attr("lang", "en-US");});

However, both options have drawbacks, the former being that it makes the page difficult to include in other pages, and the second that it does not work with javascript turned off. I was hoping setting the "language" attribute of <apex:page> would also set the page language, but it seems this isn't the case (I'm assuming it's only used to retrieve the internal representation of the page in different languages, however I need the attribute on the page itself to make it more accessible for screen readers). Is there a way to tell Visualforce the attributes I want on the HTML element in markup or codebehind?

  • With javascript turned off even salesforce native functionality would fail .So i guess its ok to assume all browsers will have JS turned on – Mohith Shrivastava Sep 22 '15 at 14:54
  • Is your question with respect to pages viewed by logged in Salesforce Users or by non-secure Guest Users? As in "what kind of content are you trying to show" on the page? – crmprogdev Sep 22 '15 at 14:54
  • @MohithShrivastava That's fair, using Javascript for such a simple thing still seems like overkill though. – IllusiveBrian Sep 22 '15 at 15:01
  • @crmprogdev Technically either, but the point isn't to change what's visually displayed on the page, the point is to add the attribute so screen readers will pick it up. In some of our sites the person is viewing the page outside Salesforce and may have no idea what the underlying system providing the page is, so that's the base case a markup solution should preferably work for. – IllusiveBrian Sep 22 '15 at 15:02
  • Actually, if they're a logged-in user, they'll have a language setting and their browser will also show a default language that Salesforce will pick up. The $Label attribute would be used when serving a VF page to display the correct labels for a User's browser. But with a lot of other text, that wouldn't be very helpful it it wasn't displayed in that kind of context, thus my question. See developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/…. – crmprogdev Sep 22 '15 at 15:23


You can use the HTML pass-through attribute html-lang on apex:page to set the lang attribute on the html element:

<apex:page html-lang="en-US">

In the VF page, for tag add an attribute - applyHtmlTag="false". This simple attribute did the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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