Sub topic 9
Controlling link previews with Open Graph
This chapter assumes you can write basic HTML and know what a <head> element is. It also assumes you have a press release page with a stable, public URL. You will learn how Open Graph and Twitter card tags control the preview that appears when someone shares a newsroom link, and how to find the usual errors.
What a link preview is
When someone pastes a URL into a chat app, social network, or email client, the app often shows a card with a title, a short description, and an image. The app builds that card by fetching your page and reading <meta> tags in the <head>. This work is done by a crawler (an automated program that requests pages), not by a person's browser.
Open Graph is a convention that Facebook introduced. Most platforms now read it, including LinkedIn, Slack, WhatsApp, and Discord. Without Open Graph tags, each platform guesses. It may pick the wrong image, truncate the page title, or show a navigation menu as the description.
For a newsroom this matters because journalists, partners, and employees share release links constantly. The preview is often the first thing a reader sees.
The core tags
Open Graph tags use the property attribute, not name. Each tag has a content value.
<head>
<meta charset="utf-8">
<title>Acme launches Widget 2 | Acme Newsroom</title>
<meta name="description" content="Widget 2 cuts setup time for small teams.">
<link rel="canonical" href="https://example.com/newsroom/acme-launches-widget-2">
<link rel="alternate" type="application/rss+xml" title="Acme Newsroom" href="/newsroom/feed.xml">
<meta property="og:type" content="article">
<meta property="og:title" content="Acme launches Widget 2">
<meta property="og:description" content="Widget 2 cuts setup time for small teams.">
<meta property="og:url" content="https://example.com/newsroom/acme-launches-widget-2">
<meta property="og:image" content="https://example.com/img/widget-2-1200x630.jpg">
<meta name="twitter:card" content="summary_large_image">
</head>The four tags that Open Graph treats as required are:
| Tag | Purpose | Notes |
|---|---|---|
| `og:title` | Headline on the card | Keep it under about 60 characters. It can differ from `<title>`, which usually carries the site name. |
| `og:type` | Kind of content | Use `article` for releases and `website` for the newsroom index. |
| `og:image` | Preview image | Must be an absolute URL. |
| `og:url` | The preferred address | Should match your canonical URL. |
og:description is technically optional, but you should always set it. Write one or two sentences, up to roughly 150 to 200 characters, because platforms cut off longer text at different points.
How the pieces relate
Several tags look alike and overlap. The page has one title and one description for search engines, and a separate pair for social cards. The following diagram shows which tag feeds which consumer.
Choosing the image
The image is the part of the preview people notice most, and it is the part that most often goes wrong.
- Size. Use 1200 by 630 pixels, an aspect ratio of about 1.91:1. Most platforms crop to this ratio for large cards.
- File size. Keep it well under 1 MB. Some crawlers give up on large files, and Facebook documents a limit of 8 MB.
- Format. Use JPEG or PNG. Avoid SVG and WebP for previews, because some crawlers do not render them.
- Absolute, public URL. A relative path like
/img/a.jpgfails, and so does an image behind a login or a signed URL that expires. - Safe area. Keep text and faces away from the edges. Some apps crop to a square or add rounded corners.
- Text in images. Any words in the image should be short and large. Previews are often displayed at thumbnail size.
You can add og:image:width, og:image:height, and og:image:alt to help crawlers and screen readers.
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:image:alt" content="Acme Widget 2 on a desk next to a laptop">Declaring width and height lets some platforms render the card on the first share. Without them, a platform may need to download the image first, and the first preview can come out without a picture.
Twitter card tags
X (formerly Twitter) reads its own twitter: tags and falls back to Open Graph when they are missing. The one tag you usually need is the card type, because there is no fallback for it.
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@acme">Twitter tags use name, not property. Use summary_large_image for a wide image above the text and summary for a small square thumbnail. twitter:site is optional and names the account that owns the site.
Article-specific properties
When og:type is article, you can add properties in the article: namespace. They describe publication details and are useful for press releases.
<meta property="article:published_time" content="2026-03-12T09:00:00Z">
<meta property="article:modified_time" content="2026-03-12T09:00:00Z">
<meta property="article:section" content="Press releases">Use ISO 8601 dates, the same format you use in the datetime attribute of a <time> element and in structured data. Keeping the three consistent avoids confusion about when a release went out.
Generating tags from a template
A newsroom with more than a few releases should not hand-write these tags. Generate them from the same fields that produce the page body, so title, description, and URL cannot drift apart. The following Python function builds the block and escapes values, which matters because a quotation mark in a headline would otherwise break the attribute.
from html import escape
def social_tags(title, description, url, image, published, image_alt=""):
pairs = [
("property", "og:type", "article"),
("property", "og:title", title),
("property", "og:description", description),
("property", "og:url", url),
("property", "og:image", image),
("property", "og:image:alt", image_alt),
("property", "article:published_time", published),
("name", "twitter:card", "summary_large_image"),
]
lines = []
for attr, key, value in pairs:
if value:
lines.append(
f'<meta {attr}="{key}" content="{escape(value, quote=True)}">'
)
return "\n".join(lines)
print(
social_tags(
'Acme launches "Widget 2"',
"Widget 2 cuts setup time for small teams.",
"https://example.com/newsroom/acme-launches-widget-2",
"https://example.com/img/widget-2-1200x630.jpg",
"2026-03-12T09:00:00Z",
"Acme Widget 2 on a desk",
)
)The function skips empty values, so an optional field such as the image description does not produce an empty tag.
Common errors
- Relative image URLs. The crawler does not know your domain. Always write
https://and the full host. - Tags rendered by JavaScript. Most preview crawlers do not run scripts. If a single-page app inserts the tags after load, the crawler sees none. Put the tags in the HTML the server sends.
- Blocked crawlers. A
robots.txtrule, a login wall, or a firewall rule that blocks bots will stop previews. Facebook's crawler identifies asfacebookexternalhit, and Slack's asSlackbot. Allow them. - Stale cache. Platforms store the card after the first fetch. If you fix a tag and the old preview persists, the platform is serving its cache. Re-scrape the URL with the platform's debugger, or change the image file name when you replace the image.
- Mismatched URLs. If
og:urlpoints to a different address than the canonical link, platforms may merge or split share counts and show the wrong page. Make them identical. - Same image everywhere. Using the logo on every release makes shared links look alike. Give each major release its own image and keep the logo as a fallback.
- Unescaped characters. An unescaped
"or&in a headline breaks the markup. Escape values as the template above does.
Testing your previews
Check each template before you rely on it.
- View the page source (not the browser's inspector, which shows the page after scripts run) and confirm the tags are there.
- Request the page without a browser, for example with
curl -s URL, and search the output forog:. - Run the URL through the platform debuggers. Facebook has a Sharing Debugger, LinkedIn has a Post Inspector, and X and Slack show cards when you paste a link into a draft or a private channel.
- Test one release with a long headline and one with a very short one, to see how truncation behaves.
What to remember
Set the six tags that matter (og:title, og:type, og:image, og:url, og:description, and twitter:card). Use an absolute 1200 by 630 image. Serve the tags in the initial HTML. Make og:url match the canonical link. Generate tags from the same data as the page, and test with the platform debuggers.
Exercise
A release page has correct og:title, og:description and og:image tags in the HTML source. A teammate shares the link in Slack and sees a card with no image. The image URL is "/img/widget-2-1200x630.jpg". Give the most likely cause and the fix.
Show answer
The og:image value is a relative path. Crawlers need an absolute URL, so they cannot find the file. Change it to "https://example.com/img/widget-2-1200x630.jpg". Then re-scrape the page with the platform's debugger or share a link with a changed image file name, because the platform may have cached the card without an image.
Exercise
Your newsroom is a single-page app that sets og:title and og:image with JavaScript after the page loads. Browsers show the right tags in the inspector, but shared links show a generic card. Why, and what are two ways to fix it?
Show answer
Most preview crawlers fetch the HTML and do not run JavaScript, so they never see the tags. Fix it by rendering the tags on the server (server-side rendering), or by generating static HTML pages for each release at build time. A third option is to serve a pre-rendered version to known crawlers.
Exercise
Write the meta tag that makes X show a large image card for a release, and say what happens if you leave it out while og:image is set.
Show answer
<meta name="twitter:card" content="summarylargeimage">. Without it X has no card type to fall back on, so it may show a plain link or a small summary card instead of the large image, even though og:image is present.