Open Graph validation for HTML5

Scott Greenfield picture Scott Greenfield · Jun 28, 2011 · Viewed 33.6k times · Source

Is there any way to get facebook's crappy Open Graph meta tags to validate if my doctype is <!DOCTYPE html> (HTML5)?

Other than facebook's Open Graph meta tags, my document validates perfectly.

I really don't want to use <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"> as that creates a whole new set of problems.

Here is an example of one of the validation errors in question...

Error Line 11, Column 47: Attribute property not allowed on element meta at this point.

<meta property="og:type" content="website" />

Any help would be appreciated... I have been searching off and on for days to no avail.

Answer

Blaise picture Blaise · Jan 20, 2012

For HTML5, add this to your html element like described on ogp.me and keep your og: prefixed properties:

<!doctype html>
<html prefix="og: http://ogp.me/ns#">
<head>
     <meta property="og:type" content="website" />
     ...

For XHTML (like OP's question), use the name attribute instead of property attribute. Facebook lint will throw a warning, but the meta value will still be recognized and parsed.

<meta name="og:title" content="Hello Facebook" />