OpenGraph-Net 4.0.1

.NET 6.0 .NET Standard 2.1
NuGet\Install-Package OpenGraph-Net -Version 4.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
dotnet add package OpenGraph-Net --version 4.0.1
<PackageReference Include="OpenGraph-Net" Version="4.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OpenGraph-Net --version 4.0.1
#r "nuget: OpenGraph-Net, 4.0.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install OpenGraph-Net as a Cake Addin
#addin nuget:?package=OpenGraph-Net&version=4.0.1

// Install OpenGraph-Net as a Cake Tool
#tool nuget:?package=OpenGraph-Net&version=4.0.1


Build Nuget V Nuget dl License Contributor Covenant gitter

A simple .net assembly to use to parse Open Graph information from either a URL or an HTML snippet. You can read more about the Open Graph protocol @

Support the library

If you find this library useful, buy me a coffee!


These are the basic operations of the OpenGraphNet parser.

Parsing from a URL

Use async/await to parse a URL:

OpenGraph graph = await OpenGraph.ParseUrlAsync("");

Accessing Values

Accessing Metadata

Each metadata element is stored as an array. Additionally, each element's properties are also stored as an array.

<meta property="og:image" content="">
<meta property="og:image:width" content="30">
<meta property="og:image" content="">
<meta property="og:image:width" content="60">
<meta property="og:locale" content="en">
<meta property="og:locale:alternate" content="en_US">
<meta property="og:locale:alternate" content="en_GB">

You would access the values from the sample HTML above as:

graph.Metadata["og:image"].First().Value; // ""
graph.Metadata["og:image"].First().Properties["width"].Value(); // "30"
graph.Metadata["og:image"][1].Value; // ""
graph.Metadata["og:image"][1].Properties["width"].Value(); // "30"
graph.Metadata["og:locale"].Value(); // "en"
graph.Metadata["og:locale"].First().Properties["alternate"][0].Value; // "en_US"
graph.Metadata["og:locale"].First().Properties["alternate"][1].Value; // "en_GB"
Basic Metadata

The four required Open Graph properties for all pages are available as direct properties on the OpenGraph object.

  • graph.Type is a shortcut for graph.Metadata["og:type"].Value()
  • graph.Title is a shortcut for graph.Metadata["og:title"].Value()
  • graph.Image is a shortcut for graph.Metadata["og:image"].Value()
  • Note: since there can be multiple images, this helper returns the URI of the first image. If you want to access images or child properties like og:image:width then you should instead use the graph.Metadata dictionary.*
  • graph.Url is a shortcut for graph.Metadata["og:url"].Value()

The original URL used to generate the OpenGraph data is available from the OriginalUrl property graph.OriginalUrl.

Creating OpenGraph Data

To create OpenGraph data in memory use the following code:

var graph = OpenGraph.MakeGraph(
    title: "My Title", 
    type: "website", 
    image: "", 
    url: "", 
    description: "My Description", 
    siteName: "");
graph.AddMetadata("og", "image", "");
graph.Metadata["og:image"][0].AddProperty("width", "30");
graph.Metadata["og:image"][1].AddProperty("width", "60");

The previous System.Console.Write(graph.ToString()); will produce the following HTML (formatting added for legibility):

<meta property="og:title" content="My Title">
<meta property="og:type" content="website">
<meta property="og:image" content="">
<meta property="og:image:width" content="30">
<meta property="og:image" content="">
<meta property="og:image:width" content="60">
<meta property="og:url" content="">
<meta property="og:description" content="My Description">
<meta property="og:site_name" content="">

Parsing Namespaces

The component now knows about the 13 namespaces listed below. When parsing a url or a HTML document, OpenGraph.Net will now read and use those namespaces from either the <html> or <head> tags. The parser is now smart enough to include the namespaces when none are included in those tags by extracting it from the meta[property] value directly.

If there are any additional standard/supported namespaces that I am missing, please shoot me a comment or a pull request with the missing items.

Adding Custom Namespaces

You can now add custom namespaces to the parser. Simply make the following call:

    prefix: "gah",
    schemaUri: "",
    requiredElements: new[] { "brain" });

Doing the above will allow the parser to understand the following HTML snippet:

<meta property="gah:brain" content="">
<meta property="gah:brain:size" content="tiny">

and the graph:

graph.Metadata["gah:brain"].Value() // ""
graph.Metadata["gah:brain"].First().Properties["size"].Value() // "tiny"

Writing out OpenGraph Namespaces

In the wild web sites seem to add their OpenGraph namespaces in one of 2 ways. They either write the namespaces in the html as xmlns attributes or within the head tag in the prefix attribute.

  • <html xmlns:og="" xmlns:product="">
  • <head prefix="og: product:">

xmlns: version in the html tag

To create the html version in an cshtml page after creating a new graph, use the following code:

<html @graph.HtmlXmlnsValues>

Would produce the following:

<html xmlns:og="" xmlns:product="">
prefix version in the <head> tag

To create the head version in a cshtml page, after create a new graph, use the following code:

<head prefix="@graph.HeadPrefixAttributeValue">

Would produce the following:

<head prefix="og: product:">

Writing out OpenGraph Metadata to the head tag

Below is a complete example to write out a OpenGraph metadata to a page:

    var graph = OpenGraph.MakeGraph(
        title: "My Title", 
        type: "website", 
        image: "", 
        url: "", 
        description: "My Description", 
        siteName: "");
<head prefix="@graph.HeadPrefixAttributeValue">

will produce the following HTML:

<head prefix="og:">
    <meta property="og:title" content="My Title">
    <meta property="og:type" content="website">
    <meta property="og:image" content="">
    <meta property="og:url" content="">
    <meta property="og:description" content="My Description">
    <meta property="og:site_name" content="">


So please don't be afraid to fork me.

Contribution Guide

  1. Fork the OpenGraph-Net repository
  2. Create a feature branch for the item you are going to add.
  3. Add your awesome code and your unit tests to cover the new feature
  4. Run all of the tests to ensure everything is still passing.
  5. Create a pull request to our develop branch.
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.1
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on OpenGraph-Net:

Package Downloads

This is the main REST CMS API package. This package contains initialization code, controllers, filters and core middleware required to run the REST CMS client API.


dotnet wechaty


Image processing middleware based on ASP.NET and ImageSharp / SkiaSharp / SvgNet.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.0.1 2,792 8/12/2022
4.0.1-alpha.0.3 54 8/12/2022
4.0.1-alpha.0.2 58 8/12/2022
4.0.1-alpha.0.1 54 8/12/2022
4.0.0 58 8/12/2022
3.2.9-alpha.0.21 49 8/12/2022
3.2.9-alpha.0.20 50 8/12/2022
3.2.9-alpha.0.16 54 8/12/2022
3.2.9-alpha.0.15 50 8/12/2022
3.2.9-alpha.0.14 51 8/12/2022
3.2.9-alpha.0.10 53 8/12/2022
3.2.9-alpha.0.4 703 7/27/2021
3.2.9-alpha.0.3 159 7/27/2021
3.2.9-alpha.0.2 164 7/27/2021
3.2.8 49,991 7/27/2021
3.2.7 3,779 6/8/2021
3.2.7-alpha.0.40 104 6/8/2021
3.2.7-alpha.0.39 104 6/8/2021
3.2.7-alpha.0.38 106 6/8/2021
3.2.7-alpha.0.37 104 6/8/2021
3.2.7-alpha.0.35 112 6/8/2021
3.2.7-alpha.0.34 112 6/8/2021
3.2.6 19,319 1/28/2021
3.2.5 230 1/28/2021
3.2.4 54,678 3/24/2020
3.2.3 1,506 2/26/2020
3.2.2 375 2/26/2020
3.2.1 8,522 2/7/2020
3.2.0 11,150 6/15/2019
3.1.2 36,967 3/16/2019
3.1.1 667 2/28/2019
3.1.0 1,719 1/18/2019
3.0.0 10,220 12/5/2018
2.2.0 24,240 5/10/2018
2.0.0 1,068 5/2/2018
1.3.4 33,936 8/17/2016
1.3.3 911 8/16/2016
1.3.2 1,018 8/15/2016
1.3.1 1,012 8/15/2016 4,517 6/30/2016 7,641 4/2/2013

Added back NetStandard 2.1.