Discover how a few lines of metadata can make your website shine on every social feed!
Why Open Graph and social metadata in Astro? - Purpose & Use Cases
Imagine sharing your website link on social media, but the preview shows a random image or no description at all.
This makes your site look unprofessional and less inviting to click.
Manually adding social metadata means editing HTML meta tags for every page.
This is slow, easy to forget, and inconsistent across pages.
It also requires remembering many tag formats for different platforms.
Open Graph and social metadata frameworks automate adding the right tags.
They ensure your pages always have correct titles, images, and descriptions for social sharing.
This saves time and makes your site look polished everywhere.
<meta property="og:title" content="My Site"> <meta property="og:image" content="image.jpg"> <meta name="twitter:card" content="summary_large_image">
--- import { SocialMetadata } from 'astro-framework'; --- <SocialMetadata title="My Site" image="image.jpg" description="Welcome to my site!" />
You can easily control how your site looks when shared on social media, boosting clicks and engagement.
A blogger uses Open Graph metadata to show a beautiful preview with their post's image and summary on Facebook and Twitter automatically.
Manual social metadata is tedious and error-prone.
Open Graph frameworks automate and standardize metadata.
This improves your site's appearance on social platforms and saves time.
Practice
og: tags in an Astro page's <head> section?Solution
Step 1: Understand the role of
og:tagsog:tags are Open Graph tags used to define how content is displayed on social media.Step 2: Identify their placement and effect
These tags go inside the<head>and control preview title, image, and description on social platforms.Final Answer:
To control how the page appears when shared on social media platforms -> Option AQuick Check:
Open Graph tags = social media preview control [OK]
og: tags shape social media previews [OK]- Confusing
og:tags with CSS or fonts - Thinking they improve page speed
- Placing tags outside the
<head>section
<head> section?Solution
Step 1: Recall Twitter card meta tag syntax
Twitter card tags usename="twitter:..."attribute, notproperty.Step 2: Check attribute order and correctness
The correct syntax is<meta name="twitter:title" content="..." />. Attribute order does not affect validity but standard is name then content.Final Answer:
<meta name="twitter:title" content="My Page Title" /> -> Option DQuick Check:
Twitter card title uses name="twitter:title" [OK]
- Using property instead of name for Twitter tags
- Mixing Open Graph and Twitter tag syntax
- Incorrect attribute order causing confusion
<head> snippet:<meta property="og:title" content="Welcome" /> <meta property="og:description" content="Best site" /> <meta name="twitter:card" content="summary_large_image" /> <meta name="twitter:title" content="Welcome" />
What will be the title shown when this page is shared on Twitter?
Solution
Step 1: Identify Twitter title meta tag
The tag<meta name="twitter:title" content="Welcome" />sets the Twitter card title.Step 2: Understand Twitter card behavior
Twitter uses its owntwitter:titletag over Open Graphog:titleif present.Final Answer:
Welcome -> Option AQuick Check:
Twitter title = twitter:title content [OK]
- Assuming Twitter uses og:title instead of twitter:title
- Confusing description or card type as title
- Ignoring the presence of twitter:title tag
<head>:<meta property="og:image" content="/images/preview.png">
But the image does not show on social shares. What is the likely problem?
Solution
Step 1: Check the image URL format
Open Graph requires absolute URLs for images to display correctly on social platforms.Step 2: Verify tag correctness
The tag uses correctpropertyattribute and closing is optional in HTML5; the main issue is the relative URL.Final Answer:
ThecontentURL is relative; it should be an absolute URL -> Option CQuick Check:
OG image URL must be absolute [OK]
- Using relative paths for og:image content
- Confusing property and name attributes
- Worrying about self-closing slash in HTML5
- Facebook uses Open Graph tags
- Twitter uses Twitter card tags
- Both show the same title and description
Which is the best way to write these tags inside
<head>?Solution
Step 1: Use correct attributes for Open Graph and Twitter tags
Open Graph tags useproperty="og:...", Twitter tags usename="twitter:...".Step 2: Ensure matching titles and descriptions for both
Set the same content values for both sets of tags to keep consistency.Final Answer:
Usepropertyfor og tags andnamefor twitter tags with matching content -> Option BQuick Check:
OG = property, Twitter = name, same content [OK]
- Mixing property and name attributes between OG and Twitter
- Using different content values causing inconsistent previews
- Omitting either OG or Twitter tags
Ready to prove it?
Pass the test and this pattern moves unknown
