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?
Best Answer
html-lang
You can use the HTML pass-through attribute
html-lang
onapex:page
to set thelang
attribute on thehtml
element: