Using a Custom Doctype
You can specify a different “doctype” (document type, or DTD) for a Visualforce page by using the docType attribute on the <apex:page> tag. This changes the doctype declaration at the beginning of the page. This is particularly useful if you’re working with HTML5, and might also allow you to address browser compatibility issues.
By default, Visualforce pages are served with a doctype of HTML 4.01 Transitional. Specifically, pages begin with this doctype declaration:
You can specify a different doctype for a Visualforce page by using the docType attribute on the <apex:page> tag.
The docType attribute takes a string representing the document type. The format of the string is:
where
-
doctypeis eitherhtmlorxhtml -
versionis a decimal version number valid for thedoctype -
variant, if included, is:strict,transitional, orframesetfor allhtmldocument types and thexhmtl-1.0document type, or- <blank> or
basicfor thexhmtl-1.1document type
If an invalid document type is specified, the default doctype is used. For more information about valid HTML doctypes, see the list at the W3C website.
In API 28.0 and greater, the scope of how the docType is determined for a page depends on the entire page hierarchy, not just the main page. When pages are added to the main page using the <apex:include> tag, if any page in the hierarchy is set to docType="html-5.0", the entire page hierarchy is rendered in that mode.
To create a Visualforce page with an XHTML 1.0 Strict document type, use the docType attribute on the <apex:page> tag, and specify a value of xhtml-1.0-strict:
Visualforce doesn’t alter markup generated by components to match the doctype, nor the markup for standard Salesforce elements such as the header and sidebar. Salesforce elements are valid for most doctypes and function properly with any doctype, but if you choose a strict doctype and wish to pass an HTML validation test, you might need to suppress or replace the standard Salesforce elements.
See Also