Sub topic 1
How a Pasted Link Becomes a Preview Card
Prerequisites
Assume you know basic HTML, URLs, HTTP requests, and the difference between the head and body elements. A crawler is a program that requests a web page and reads its HTML.
How a Pasted Link Becomes a Preview Card
When someone pastes a URL into a social or messaging app, the platform usually:
- Extracts the URL from the message.
- Sends an HTTP request to that URL.
- Reads the returned HTML.
- Finds metadata in the document’s
head. - Builds a card with a title, description, image, and link.
The platform may cache the result. Therefore, changing your page does not always change an existing preview immediately.
Meta Tags in the Document Head
Metadata describes a page without appearing as normal page content. Put social-sharing metadata inside the HTML head. Crawlers often inspect the initial server response, so the tags should be present in server-rendered HTML rather than added only after browser JavaScript runs.
<head>
<title>How to Brew Cold Coffee</title>
<meta property="og:title" content="How to Brew Cold Coffee">
<meta property="og:type" content="website">
<meta property="og:url" content="https://example.com/cold-coffee">
<meta property="og:image" content="https://example.com/images/cold-coffee-1200x630.jpg">
</head>The Open Graph Protocol
The Open Graph protocol is a convention for describing web pages to platforms that create previews. An Open Graph tag uses meta with the property attribute. The property value names the field, and content supplies its value.
Use absolute URLs, including the scheme such as https://. Relative image paths can fail because the crawler may not resolve them as your browser does.
The Four Core Properties
These properties form the minimum useful description:
| Property | Purpose |
|---|---|
| `og:title` | Title displayed in the card |
| `og:type` | Kind of object, commonly `website` |
| `og:image` | Absolute URL of the preview image |
| `og:url` | Canonical URL represented by the card |
Add og:description for a useful summary. Keep each page’s values specific to that page. A valid tag is not enough if it describes the wrong URL or image.
Exercise
Which tag tells a crawler the page represented by the preview?
Show answer
og:url identifies the page URL represented by the preview.