Open Graph for Lazy Developers

Published - 2 min read

Open Graph is a protocol that allows you to control how your website appears when shared on social media through html meta tags. This guide will list down the necessary meta tags, what images to use, and how to test your website’s Open Graph data.

Meta Tags

The following meta tags are “required”, meaning you should always include them in your public website.

Here’s an example of how to include these meta tags in your website’s <head> section:

html
<head>
  <meta property="og:title" content="My Website" />
  <meta property="og:type" content="website" />
  <meta property="og:image" content="https://example.com/image.jpg" />
  <meta property="og:url" content="https://example.com" />
</head>

You can also include the following optional meta tags:

Image Requirements

These requirements come from the Facebook Sharing Best Practices as of February 2024.

But, in practice, you should aim for a 1200x630px image, following popular sites’ approach.

You should also include an og:image:witdh and og:image:height meta tags to specify the image’s dimensions. This makes the image load faster on social media platforms.

html
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />

Testing

You can test your website’s Open Graph data using the Facebook Sharing Debugger. Just enter your website’s URL and click “Debug”. If there are any issues, the tool will tell you what’s wrong.

FAQ

You can use a default image for your website. This can be your website’s logo, or a generic image that represents your website.

Do I need a open graph at all?

If you want your website to look good when shared on social media and messaging apps, then yes, you should include Open Graph meta tags.

Do I need Twitter/X meta tags?

No, unless you want to optimize how your website looks when shared on X. X has its own set of meta tags, but they will fall back to Open Graph meta tags if they are not present.

Resources