Sub topic 3
The Open Graph protocol and the property attribute
This chapter assumes you know basic HTML structure (the head and body elements), the difference between absolute and relative URLs, and how an HTTP request returns an HTML document. It builds on the previous chapter, where you saw that meta tags in the head carry information about a page.
What the protocol is
The Open Graph protocol is a set of conventions for describing a web page as a "graph object": a thing with a title, a type, an image, and a canonical address. Facebook created it, and many other platforms now read it, including messaging apps, workplace chat tools, and social networks.
The protocol does not add new HTML elements. It reuses the <meta> element and gives each tag a namespaced name that starts with og:. A crawler fetches your page, scans the head for these tags, and builds a preview card from the values it finds.
The property attribute
A regular meta tag, such as the description tag used by search engines, identifies itself with the name attribute:
<meta name="description" content="A simple method for smooth cold-brew coffee.">Open Graph tags use the property attribute instead:
<meta property="og:title" content="How to Brew Cold Coffee">Each tag has two parts:
propertyholds the name of the Open Graph property, such asog:title.contentholds its value, always as a string.
The Open Graph specification is based on RDFa, a way to embed structured data in HTML, and property is the RDFa attribute for naming a value. This is why property is the documented form.
Name versus property in practice
Many crawlers are forgiving and accept name="og:title". Do not rely on that. Some parsers read only property, and a page that works in one app can show a blank card in another.
| Tag family | Attribute | Example |
|---|---|---|
| Search engine meta tags | `name` | `<meta name="description" ...>` |
| Open Graph | `property` | `<meta property="og:title" ...>` |
| Twitter/X cards | `name` | `<meta name="twitter:card" ...>` |
The Twitter/X row is an exception that surprises people. Twitter's own tags are conventionally written with name, while Open Graph tags use property. A later chapter covers Twitter/X cards in detail.
A minimal example
This is a valid set of tags. Every URL is absolute, because a crawler reads the tag out of context and cannot resolve a relative path against your site.
<head>
<meta charset="utf-8">
<title>How to Brew Cold Coffee</title>
<meta property="og:title" content="How to Brew Cold Coffee">
<meta property="og:type" content="website">
<meta property="og:url" content="https://example.com/cold-coffee">
<meta property="og:image" content="https://example.com/images/cold-coffee-1200x630.jpg">
<meta property="og:description" content="A simple method for smooth cold-brew coffee at home.">
</head>The next chapter explains what each of the first four properties does and why they are called core properties.
How the crawler reads the tags
The crawler works only with the HTML it receives. Tags added later by JavaScript in the browser are usually invisible to it.
Common errors
- Using
name="og:title"and testing in only one app. - Writing
contentvalues with unescaped quotes, which ends the attribute early and truncates the value. - Placing the tags in the
body. Put them in thehead. - Using relative URLs such as
/images/cover.jpginog:imageorog:url. - Repeating a single-value property, such as two
og:titletags, and getting an unpredictable pick.
Exercise
A teammate wrote <meta name="og:title" content="Cold Brew Guide">. It previews correctly in one chat app but shows no title in another. What is wrong, and what is the fix?
Show answer
The tag uses the name attribute, which only some crawlers accept for Open Graph tags. The documented form uses property, so change it to <meta property="og:title" content="Cold Brew Guide">.
Exercise
Why must the og:image value be an absolute URL such as https://example.com/images/cover.jpg?
Show answer
The crawler reads the tag outside the context of your site, so it cannot reliably resolve a relative path like /images/cover.jpg. An absolute URL tells it exactly where to fetch the image.