Skip to content

Add Open Graph tags to create a social card #124

Description

@ebouchut

Once the app has a public (absolute) canonical URL, add an og:image and other Open Graph-related meta tags to create a social card.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">

  <!-- ============ Core Open Graph ============ -->
  <meta property="og:type"        content="website">
  <meta property="og:site_name"   content="Learn-Dev">
  <meta property="og:title"       content="Learn-Dev — Learn programming">
  <meta property="og:description" content="A hands-on playground for learning programming.">
  <meta property="og:url"         content="https://learn-dev.ericbouchut.com/">
  <meta property="og:locale"      content="en_US">

  <!-- ============ The image itself ============ -->
  <!-- MUST be an absolute URL. PNG/JPG, not SVG. -->
  <meta property="og:image"            content="https://learn-dev.ericbouchut.com/card.png">
  <!-- HTTPS variant (some crawlers check it explicitly) -->
  <meta property="og:image:secure_url" content="https://learn-dev.ericbouchut.com/card.png">
  <!-- MIME type, so the crawler doesn't have to sniff it -->
  <meta property="og:image:type"       content="image/png">
  <!-- Dimensions: lets platforms lay out the card before download -->
  <meta property="og:image:width"      content="1200">
  <meta property="og:image:height"     content="630">
  <!-- Accessibility text for the image -->
  <meta property="og:image:alt"        content="Learn-Dev logo on a dark gradient background">

  <!-- ============ Twitter/X extension ============ -->
  <!-- X reads og:* as a fallback, but these give a bigger card -->
  <meta name="twitter:card"        content="summary_large_image">
  <meta name="twitter:site"        content="@ericbouchut">
  <meta name="twitter:title"       content="learn-dev — Build in Public">
  <meta name="twitter:description" content="A hands-on playground for learning programming.">
  <meta name="twitter:image"       content="https://learn-dev.ericbouchut.com/card.png">
  <meta name="twitter:image:alt"   content="learn-dev logo on a dark gradient background">

  <title>Learn-Dev - Learn programming </title>
</head>
<body>
  <!-- page content -->
</body>
</html>

Open Graph requires an absolute URL, and link crawlers do not render SVG.

Here is some more context about this topic.

Note

When you share a link to your app on Slack, iMessage, LinkedIn, X, etc., those platforms generate a preview “card”.
This is usually a title, description, and a thumbnail image.
That image comes from a ‎**<meta property="og:image">** tag in your page’s HTML (part of the Open Graph protocol).

You need a public, canonical URL first.
Open Graph image URLs must be absolute (e.g. ‎https://learn-dev.ericbouchut.com/card.png), not relative (‎/card.png). Crawlers fetch the image from their own servers, so they can’t resolve a relative path — they have no base domain to attach it to. Until your app is deployed at a stable public address, you don’t have that absolute URL to point to.

Important

The image can’t be an SVG.
Most social/link crawlers (Facebook, LinkedIn, Slack, etc.) don’t render SVG for preview cards.
You’d need a raster format like PNG or JPG (recommended size ~1200×630px).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions