Sub topic 7
Twitter/X Cards and Fallback to Open Graph
This chapter assumes you can write Open Graph tags in a page's <head> and know the four core properties (og:title, og:type, og:image, og:url). It also assumes you know the difference between the property and name attributes on a meta tag. Here you will learn what Twitter/X cards add, which tags you can leave out, and how to choose a card type.
What a Twitter/X card is
A Twitter/X card is a preview that X renders under a link in a post. Like an Open Graph preview, it is built from meta tags that X's crawler reads from your HTML. Twitter defined its own tag set, prefixed with twitter:, before Open Graph was widely used. When Twitter later added support for Open Graph, it kept its own tags as optional overrides.
The result is a layered system:
- X looks for a
twitter:*tag. - If that tag is missing, X looks for the matching Open Graph tag.
- If neither exists, X falls back to other page data, such as the
<title>element, or shows a bare link.
The one tag with no Open Graph equivalent is twitter:card. It selects the card layout. Without it, X may show only a plain link, even if your Open Graph tags are complete.
The minimal setup
Because of the fallback, you do not need to duplicate your Open Graph data. Add twitter:card and let the rest fall through:
<meta name="twitter:card" content="summary_large_image">
<meta property="og:title" content="How to Brew Cold Coffee">
<meta property="og:description" content="A simple method for smooth cold-brew coffee at home.">
<meta property="og:image" content="https://example.com/images/cold-coffee-1200x630.jpg">This produces a large-image card on X and a standard preview on platforms that read only Open Graph. You maintain one set of title, description, and image values, and they cannot drift apart.
Note the attribute difference. Open Graph tags use property, as the protocol's RDFa heritage requires. Twitter tags use name. In practice, many crawlers accept either attribute for both families, but you should not depend on that. Write name for twitter:* and property for og:*, as the specifications show.
Card types
The twitter:card value chooses the layout. The two you will use most are below.
| Value | Layout | Typical use |
|---|---|---|
| `summary` | Small square thumbnail beside the title and description | Pages with a logo, avatar, or small image |
| `summary_large_image` | Large image above the title and description | Articles, product pages, and any page with a good hero image |
Other card types existed in the past, such as app and player. X has reduced or removed support for some of them over the years, so check the current X developer documentation before relying on them. For most sites, the choice is between the first two.
Choosing between them
Use summary_large_image when you have a purpose-made image of at least 1200×630 pixels. It takes more space in the timeline and usually gets more attention. Use summary when the image is square, such as a logo, because a large card would crop it awkwardly. If you have no image at all, summary degrades more gracefully, since the layout does not reserve an empty banner.
Image rules differ by card type. For summary, X expects a roughly square image with a 1:1 ratio, and it crops other shapes. For summary_large_image, X expects a 2:1 ratio and crops other shapes to fit. A 1200×630 Open Graph image is about 1.91:1, which X displays acceptably on a large card with minor cropping at the edges. Keep important content, such as text and faces, away from the outer edges so cropping does not cut it off.
When to add twitter-specific tags
The fallback covers title, description, and image. You add twitter:* tags only when X should show something different from other platforms, or to supply data that Open Graph lacks. The common cases are listed here.
| Tag | Purpose |
|---|---|
| `twitter:title` | Override the title when X's layout truncates it earlier than other platforms |
| `twitter:description` | Provide a shorter description for X |
| `twitter:image` | Use a different crop, such as a square image for a `summary` card |
| `twitter:image:alt` | Alt text for the image, up to 420 characters |
| `twitter:site` | The `@username` of the site's account, for attribution |
| `twitter:creator` | The `@username` of the content author |
Here is an example that overrides only what needs to differ:
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@examplecoffee">
<meta name="twitter:creator" content="@janebrews">
<meta name="twitter:image:alt" content="A glass of cold brew coffee with ice on a wooden table">
<meta property="og:title" content="How to Brew Cold Coffee">
<meta property="og:description" content="A simple method for smooth cold-brew coffee at home.">
<meta property="og:image" content="https://example.com/images/cold-coffee-1200x630.jpg">The title, description, and image come from Open Graph. The four twitter:* tags add the card type, the two account handles, and the alt text. Because those handles and the card type have no Open Graph equivalent, they must be written explicitly.
A related point on alt text: the fallback to og:image:alt is less consistently documented than the fallback for title, description, and image. If accessible previews on X matter to you, set twitter:image:alt explicitly instead of relying on a fallback.
Fallback rules and edge cases
The fallback is simple in principle, but several details cause trouble in practice.
- Per-field fallback. The fallback applies to each field independently. You can set
twitter:titleand still inherit the description and image from Open Graph. - Empty values. A tag that is present but has an empty
contentattribute may count as present, so the fallback does not run. Omit the tag instead of emitting it empty. This matters in templates that print every tag whether or not data exists. - Relative URLs.
twitter:imageandog:imageshould both be absolute URLs, including the scheme. A relative path such as/images/cover.jpgoften fails to resolve in a crawler. - Duplicates. If a page contains two
twitter:cardtags or twoog:titletags with different values, the crawler picks one, and the choice is not guaranteed. This often happens when both a theme and an SEO plugin emit tags. Check the final rendered HTML, not just your template. twitter:url. You do not need it. X usesog:url, or the shared URL, to identify the page.- Different image for X. If
twitter:imagediffers fromog:image, X uses the Twitter one and every other platform uses the Open Graph one. This is the supported way to serve a square image to asummarycard while others get the wide image.
Verifying what X will see
The X crawler identifies itself as Twitterbot. As with other crawlers, it reads the HTML it receives and does not run your JavaScript, so tags added only by client-side code will not appear. To inspect your tags from the server's point of view, request the page with a crawler user agent:
curl -s -A "Twitterbot/1.0" https://example.com/cold-coffee | grep -iE 'name="twitter:|property="og:'The output should list your twitter:card tag and each Open Graph tag once. If a tag appears twice or not at all, fix the template before you test on X.
Two cautions about testing on X itself:
- X has changed its card validation tooling several times, and a dedicated public validator is not guaranteed to be available. The reliable test is to compose a post containing the URL and look at the preview before publishing.
- X caches card data. After you change tags, an already-shared URL may continue to show old data for some time. A common workaround while testing is to add a throwaway query string, such as
?v=2, so X treats the URL as new. Do not use that URL in production, because it splits the page's shares across two URLs and may conflict with yourog:url.
Decision checklist
Use this order when adding X support to a page:
- Write complete Open Graph tags first, including
og:title,og:type,og:url,og:image, andog:description. - Add
twitter:cardwithsummary_large_imageorsummary. - Add
twitter:siteif the site has an account, andtwitter:creatorfor bylined content. - Add
twitter:image:altto make the image accessible. - Add
twitter:title,twitter:description, ortwitter:imageonly if X needs a different value. - Fetch the page with
curland a crawler user agent and confirm there are no duplicates or empty tags.
Exercises
Exercise
A page has complete Open Graph tags (og:title, og:description, og:image with an absolute URL) but no twitter:* tags. Links to it appear on X as a plain link with no card. What is the most likely fix, and why does it work?
Show answer
Add <meta name="twitter:card" content="summary_large_image"> (or summary). The card type has no Open Graph equivalent, so X cannot infer a layout. Once it is present, X takes the title, description, and image from the Open Graph tags through the fallback.
Exercise
Your site template prints <meta name="twitter:description" content=""> for pages that have no custom X description. The pages have good og:description values, yet cards on X show no description. Explain the cause and give the fix.
Show answer
The empty twitter:description tag is present, so X does not fall back to og:description. The fix is to change the template so it omits the tag when no value exists, which lets the fallback supply the Open Graph description.
Exercise
You want X to show a square logo in a small summary card while Facebook and LinkedIn keep showing the 1200x630 image. Which tags do you write?
Show answer
Set twitter:card to summary and add twitter:image pointing to the absolute URL of the square logo. Keep og:image pointing at the 1200x630 image. X uses twitter:image when present, and the other platforms read only og:image.