Sub topic 3
The Open Graph Protocol and the property Attribute
This chapter explains what the Open Graph protocol is, why its tags use a property attribute instead of the usual name, and how crawlers parse those tags. It assumes you can read basic HTML, know that meta tags live in the document <head>, and understand the difference between absolute and relative URLs.
What the Open Graph protocol is
The Open Graph protocol is a small vocabulary for describing a web page as a "rich object". Facebook introduced it in 2010. Today many platforms read it, including Facebook, LinkedIn, Slack, Discord, WhatsApp, iMessage, and Telegram. Twitter/X reads it as a fallback, which a later chapter covers.
The protocol does not define a new file format or an API. It reuses the <meta> element you already know and gives a fixed meaning to a set of names. Each name starts with the prefix og:. When a crawler fetches your page, it collects every tag with that prefix and builds a preview card from them.
The protocol answers one question: what should a platform show when someone shares this URL? Without Open Graph tags, a crawler has to guess. It might use the <title> element, the first paragraph, or an arbitrary image. With the tags, you decide.
Why `property` and not `name`
Most meta tags you have seen use the name attribute:
<meta name="description" content="A simple method for smooth cold-brew coffee at home.">
<meta name="viewport" content="width=device-width, initial-scale=1">Open Graph tags use property:
<meta property="og:title" content="How to Brew Cold Coffee">The reason is historical. Open Graph was designed on top of RDFa, a W3C standard for embedding structured data in HTML. In RDFa, the property attribute names a relationship, and content holds its value. Open Graph borrowed that syntax so that its tags could be read as structured data.
The og: prefix is a namespace. The protocol's documentation declares it on the <html> or <head> element:
<head prefix="og: https://ogp.me/ns#">In practice, almost no site needs this declaration. Crawlers recognize the og: prefix without it. You may see it in older templates, and it is harmless to include. It matters only if you use an RDFa parser that insists on namespace declarations.
The attribute pair
Every Open Graph tag has exactly two attributes that matter:
| Attribute | Role | Example |
|---|---|---|
| `property` | Names the Open Graph property | `og:title` |
| `content` | Holds the value for that property | `How to Brew Cold Coffee` |
The content value is always a string. Numbers such as og:image:width are written as text ("1200"). Booleans and lists do not exist as separate types, so repeated properties express lists, as shown later.
A first complete example
This is the minimal set from the chapter plan. It covers the four core properties plus a description:
<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>Notes on this example:
- The tags sit inside
<head>. Crawlers generally stop reading after the head, so tags in<body>may be missed. - Every URL is absolute, with scheme and host. Crawlers fetch your HTML without the context of your site, so a relative path such as
/images/cold-coffee.jpgcannot be resolved reliably. - The
<title>element andog:titleare separate. The first is for the browser tab and search results. The second is for the preview card. They are often identical, but they do not have to be.
How a crawler reads these tags
A crawler is a program that requests your URL, much as a browser does, and then parses the response. The process looks like this:
Several details follow from this flow:
- The crawler reads the HTML the server returns. It usually does not run JavaScript. If your tags are injected by a client-side script, the crawler sees none of them.
- The result is cached on the platform side. Editing your tags does not change cards that already exist. A later chapter covers refreshing caches.
- The crawler identifies itself with a user agent string, such as
facebookexternalhit/1.1. You can imitate it to see what it receives.
Inspecting the tags with curl
You can check what a crawler gets by requesting the page with a crawler-like user agent and filtering for Open Graph lines:
curl -s -A "facebookexternalhit/1.1" https://example.com/cold-coffee | grep -i 'property="og:'The -s flag silences the progress meter. The -A flag sets the user agent. grep -i matches case-insensitively. If the output is empty, either the tags are missing from the server response or they use a different quoting style, such as single quotes. Run the command without grep to look at the raw HTML.
This test matters because it shows the HTML before any JavaScript runs, which is exactly what most crawlers see.
Structured properties and repeated tags
Some Open Graph properties have sub-properties. They use a colon to extend the name. The main property holds the primary value, and the sub-properties describe it:
<meta property="og:image" content="https://example.com/images/cold-coffee-1200x630.jpg">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:image:alt" content="A glass of cold brew coffee with ice on a wooden table">Order matters here. The sub-properties apply to the og:image tag that comes immediately before them. If you list several images, put each image's sub-properties directly after it:
<meta property="og:image" content="https://example.com/images/a.jpg">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:image" content="https://example.com/images/b.jpg">
<meta property="og:image:width" content="800">
<meta property="og:image:height" content="800">This is how the protocol expresses arrays: by repeating the main property. The first one listed is generally treated as the primary. A later chapter on preview images covers dimensions and formats in detail.
The four core properties
The protocol names four properties as required. A page without all four is not a complete Open Graph object, although platforms often cope with missing ones.
| Property | Meaning | Common mistake |
|---|---|---|
| `og:title` | The title as it should appear on the card, without the site name | Appending " - Site Name" out of habit |
| `og:type` | The kind of object, such as `website` or `article` | Omitting it, or inventing a value |
| `og:image` | An image URL representing the page | Using a relative URL |
| `og:url` | The canonical URL of the page | Leaving off a tracking-free canonical form |
What `og:url` does
og:url is the permanent address for the object. When people share many variants of a link, such as https://example.com/cold-coffee?utm_source=newsletter, the platform can use og:url to treat them as the same page. Likes and share counts then attach to one address instead of many.
Set og:url to the same value as your <link rel="canonical"> tag when you have one. A mismatch confuses both search engines and social platforms. Some crawlers follow og:url and fetch that address instead of the one that was shared, so a wrong value can produce a preview for the wrong page.
What `og:type` does
og:type selects the category of the object. The value website is the right default for a home page or a general page. article suits a blog post or news story and unlocks extra properties. The next chapters cover the types in detail. If you omit og:type, the protocol says to treat the page as website, but explicit is better.
Property names are case-sensitive and exact
A crawler matches property names as strings. Small differences cause silent failures:
og:Titleis notog:title. Use lowercase.og:image:urlis a valid alias forog:image, butog:imgdoes not exist.name="og:title"instead ofproperty="og:title"often works in practice, because many parsers are lenient. Some strict parsers ignore it. Useproperty.- A missing closing quote can swallow the rest of the tag and the tags after it.
The last point may surprise you: Twitter/X card tags conventionally use name, for example <meta name="twitter:card" content="summary_large_image">. Open Graph uses property. Both are written as <meta> elements, but they come from different traditions. Many parsers accept either attribute for both, but following each convention avoids trouble.
Putting `name` and `property` together
A page typically carries both kinds of tags. Here is a head that uses each attribute where it belongs:
<head>
<meta charset="utf-8">
<title>How to Brew Cold Coffee</title>
<meta name="description" content="A simple method for smooth cold-brew coffee at home.">
<link rel="canonical" href="https://example.com/cold-coffee">
<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.">
<meta name="twitter:card" content="summary_large_image">
</head>The description meta tag is for search engines. The og:description tag is for social cards. Duplicating the text is fine and common.
Escaping values
The content attribute is an HTML attribute, so its value must be escaped. A title that contains a double quote ends the attribute early and corrupts the tag:
<meta property="og:title" content="The "Best" Cold Brew">The correct form uses entities:
<meta property="og:title" content="The "Best" Cold Brew">Also escape &, <, and >. When you build tags from data, do this in code rather than by hand. A later chapter shows a helper function for it.
Common errors at this level
| Symptom | Likely cause | Fix |
|---|---|---|
| No preview card at all | Tags are injected by JavaScript | Render tags in the server's HTML |
| Preview shows the wrong title | `og:title` missing, so the crawler fell back to `<title>` | Add `og:title` |
| Image missing | Relative `og:image` URL | Use an absolute URL |
| Preview ignores edits | Platform cache | Refresh through the platform's debugger |
| Tag ignored | `name` used instead of `property`, or a typo in the property name | Check spelling and attribute |
| Card shows an unexpected page | `og:url` points elsewhere | Match `og:url` to the canonical URL |
Exercises
Exercise
A teammate wrote <meta name="og:title" content="Cold Brew Guide"> and the preview works on Slack but not on another platform. What is the likely cause, and how do you fix it?
Show answer
Open Graph tags should use the property attribute, not name. Slack's parser is lenient and accepts name, but the other platform's parser is stricter and ignores the tag. Change it to <meta property="og:title" content="Cold Brew Guide">.
Exercise
You list two og:image tags, then add og:image:width and og:image:height after the second one only. Which image do those dimensions describe, and what does the first image have?
Show answer
The dimensions describe the second image, because sub-properties apply to the nearest preceding og:image tag. The first image has no declared dimensions. Put each image's width and height directly after that image's og:image tag.
Exercise
Write a curl command that shows only the Open Graph tags in the HTML a crawler receives from https://example.com/cold-coffee, and explain why this can differ from what you see in browser developer tools.
Show answer
Use curl -s -A "facebookexternalhit/1.1" https://example.com/cold-coffee | grep -i 'property="og:'. Developer tools show the page after JavaScript has run, so they can include tags that scripts added. Curl shows the raw server response, which is what most crawlers read.