HTML5 Intermediate Document Structure · 7 min read

Open Graph Meta Tags

Lesson 23 of 36 in the HTML5 learning path.

Which meta tags control a link preview title and image?

Open Graph tags tell a chat app, a social site, or a messaging client what to show when someone pastes your URL. og:title is the preview title. og:image is the preview picture. og:description is the sentence under the title. They are meta elements with a property attribute, and they belong in the head of the first HTML response.

The document title and the meta description used for search are separate. Crawlers that build link cards usually do not run your scripts, so tags inserted after load are invisible to them. Image and page URLs in these tags need to be absolute.

Syntax & Parameters

Syntax
<meta property="og:title" content="Bench hours"><meta property="og:image" content="https://studio.example/images/bench-hours.jpg">

Example

Interactive preview available
index.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Bench hours for March</title>
  <link rel="canonical" href="https://studio.example/lab/hours">
  <meta name="description" content="Weekday hours for the electronics bench, including the first demo.">
  <meta property="og:title" content="Bench hours for March">
  <meta property="og:description" content="Weekday hours for the electronics bench, including the first demo.">
  <meta property="og:type" content="article">
  <meta property="og:url" content="https://studio.example/lab/hours">
  <meta property="og:site_name" content="Studio Lab">
  <meta property="og:image" content="https://studio.example/images/bench-hours.jpg">
  <meta property="og:image:alt" content="Wooden electronics bench with labeled drawers">
  <meta property="og:image:width" content="1200">
  <meta property="og:image:height" content="630">
  <meta property="og:locale" content="en_US">
</head>
<body>
  <main>
    <h1>Bench hours for March</h1>
    <p>Weekday hours for the electronics bench, including the first demo.</p>
  </main>
</body>
</html>

Expected Output

A document whose head advertises the preview title "Bench hours for March" and the image URL https://studio.example/images/bench-hours.jpg, along with the description, type, canonical URL, site name, image alt text, pixel size, and locale.

Line-by-Line Walkthrough

  1. The title element is the browser tab. og:title is a separate string for the link preview, and the two can match on purpose.
  2. meta name="description" feeds search snippets. og:description feeds the sentence under the preview title.
  3. og:type article tells consumers this URL is an article rather than a generic website.
  4. og:url is the canonical preview URL. It is absolute and matches the canonical link.
  5. og:site_name is the publisher label some chats show above the title.
  6. og:image is an absolute https URL. A root-relative path is not reliable for a crawler on another host.
  7. og:image:alt, og:image:width, and og:image:height describe the picture so a platform can reserve space and offer a text alternative.
  8. og:locale states the language of the preview copy. It does not translate the page.
  9. These tags are in the initial head. A script that adds them after load is invisible to most link-preview crawlers.

Common Pitfalls & Security

Link previews are built from the raw HTML your server sends. Treat every content value as public copy, and escape quotes so a title cannot break out of the attribute.

  • og:image="/images/bench-hours.jpg" drops the host. Crawlers resolve that path against the wrong site or reject it.
  • A private, expiring, or login-gated image URL produces a blank preview, and it can also leak a signed query string into someone else's cache.
  • Putting the only tags in client-side script means Slack, iMessage, and similar fetchers never see them.
  • og:title and og:description that disagree with the page h1 surprise people who click through. Keep them honest.
  • Forgetting to escape a user-supplied title lets a quote close the attribute and inject another meta element.
  • Platforms cache cards. Changing the file at the same image URL may not refresh the card until the cache expires or you use a new URL.

Best Practices & Modern Standards

Set og:title, og:description, og:url, og:type, and og:image on every public page that can be shared. Use an https image at least 1200 by 630 pixels, plus og:image:alt. Match og:url to the canonical link so shares do not split across duplicate addresses.

Generate the tags on the server from the same fields you show on the page. Escape attribute text. Do not point og:image at an admin-only asset or at a photograph the page itself would not show a visitor.

Real-World Use

A student pastes the lab hours URL into a class chat. The card title comes from og:title, the sentence from og:description, and the picture from the absolute og:image of the electronics bench. The page h1 matches that title, so the click lands on the same topic the card promised.

Frequently Asked Questions

Which tags set the preview title and image?

og:title sets the title and og:image sets the picture. og:description supplies the supporting sentence. Use the property attribute on those meta elements.

Why must og:image be absolute?

The crawler runs on another host. It cannot use your site root as the base the way a browser on your page can. Give a full https URL.

Do link-preview crawlers run page scripts?

Most do not. Tags must be present in the HTML response. Adding them after load leaves the card untitled.

Does meta name description set the preview image?

No. name="description" is a text snippet. The picture comes from og:image, and the card title comes from og:title.

Need more coins?

You do not have enough coins for this action.

Your balance: 0 coins

Share

Reactions

Loading reactions…