Open Graph
Build social share metadata with og:title, og:image, og:type.
What is Open Graph?
When you share a link on social media, you see a card: title, description and a large image. That card is built with the Open Graph protocol.
Open Graph tags use the form <meta property="og:...">. Here you use the property attribute, not name. The three essential tags are og:title, og:image and og:type.
og:title and og:image
og:title is the title of the share card; it can match or differ from the page title. og:image is the URL of the image shown on the card.
Use an absolute URL for og:image: https://site.com/cover.jpg. The image is usually 1200x630 pixels; smaller sizes make the card look broken. Make sure the image is served over https.
og:type and og:url
og:type states the type of the page. Use article for a blog post, product for a product page and website for the home page.
og:url is the canonical URL of the page. When the same content is reachable from several addresses, og:url tells search engines and social platforms the original source.
Exercise Add Open Graph tags for a blog post
Add four Open Graph tags to the head for a blog post: <meta property="og:title" content="...">, <meta property="og:image" content="https://...">, <meta property="og:type" content="article"> and <meta property="og:url" content="https://...">.
Show example solution
<head>
<title>Blog Post</title>
<meta property="og:title" content="Blog Post: Web Design">
<meta property="og:image" content="https://alexblog.com/cover/design.jpg">
<meta property="og:type" content="article">
<meta property="og:url" content="https://alexblog.com/article/web-design">
</head>
Test yourself
-
Which attribute do Open Graph tags use?
<meta ?="og:title" content="...">- name
- id
- property
- class
Show answer
property — Correct. Open Graph tags are written with the property attribute.
-
Match the OG property with its role
- og:title
- Share title
- og:image
- Cover image
- og:type
- Content type
- og:url
- Page URL
-
Complete the og:title tag
<meta property="og:title" content="____">Show answer
<meta property="og:title" content="Blog Post: Web Design">