HTML Social Metadata and Open Graph
Open Graph essentials
Open Graph is an external protocol used by some link-preview consumers, not a native HTML visual component. Its basic fields are og:title, og:type, og:image and og:url. The property attribute identifies a vocabulary term and content gives its value.
<!doctype html><html lang="en" prefix="og: https://ogp.me/ns#"> <head> <meta charset="utf-8"> <title>Metadata practice</title> <meta property="og:title" content="Library guide"> <meta property="og:type" content="website"> <meta property="og:image" content="https://example.com/library.jpg"> <meta property="og:url" content="https://example.com/guide"> </head> <body> <h1>Library guide</h1> </body></html>Four metadata properties are present. Image and platform access are illustrative.
Add description and image alternative
og:description provides a concise summary and og:image:alt describes the image for consumers that support it. Keep information consistent with the actual page. Include the image URL before its structured properties.
<!doctype html><html lang="en" prefix="og: https://ogp.me/ns#"> <head> <meta charset="utf-8"> <title>Metadata practice</title> <meta property="og:title" content="Library guide"> <meta property="og:type" content="website"> <meta property="og:url" content="https://example.com/guide"> <meta property="og:image" content="https://example.com/library.jpg"> <meta property="og:image:alt" content="Library entrance"> <meta property="og:description" content="Find opening hours and services."> </head> <body> <h1>Library guide</h1> </body></html>The image description and page summary are separate properties.
Keep ordinary metadata too
The document title, ordinary description and Open Graph title can coexist. Social services can cache previews, crop images, or choose not to display a field. Test with the intended service after deployment; do not treat DOM presence as preview success.
<!doctype html><html lang="en" prefix="og: https://ogp.me/ns#"> <head> <meta charset="utf-8"> <title>Hours | City Library</title> <meta name="description" content="Find current library hours."> <meta property="og:title" content="Visit the library"> <meta property="og:type" content="website"> <meta property="og:image" content="https://example.com/library.jpg"> <meta property="og:url" content="https://example.com/hours"> </head> <body> <h1>Library hours</h1> </body></html>The ordinary title differs from the sharing title.
Common mistakes and practice
The example URLs are reserved demonstration addresses, not usable preview assets. In production provide a reachable image, accurate description and URL. For RDFa-aware markup, declare the og prefix on html using https://ogp.me/ns# as documented by the protocol.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTML Social Metadata and Open Graph — Knowledge Check
Apply the metadata concepts taught in this lesson.
What is Open Graph?
Which property names the shared title?
Which field describes the shared image?
Does a meta tag guarantee a social preview?
What should a production image URL provide?