Scobly

Guides · 2026-11-29 · 10

HTML Meta Tags and Open Graph Guide for SEO

Configure HTML meta tags, viewport rules, canonical URLs, and Open Graph metadata in post templates so pages render cleanly in search and social previews.

TL;DR

  • Place meta charset and viewport tags at the very top of your HTML head so browsers and crawlers decode and scale pages properly.
  • Bind dynamic title tags under 60 characters and meta descriptions between 70 and 160 characters with HTML entities stripped at build time.
  • Generate self-referencing canonical URLs from your production base domain rather than echoing raw request URLs with query strings.
  • Include absolute HTTPS URLs for 1200x630 Open Graph images and set og:type to article so social platforms render full preview cards.
  • Verify that every head tag renders server-side in raw HTML because social scrapers and many AI crawlers do not execute client JavaScript.

What you need

You publish a new blog post, paste the link into Slack, and see a blank preview box with a truncated URL. A week later, you check search results and find your brand name appended twice to the title while mobile visitors pinch and zoom to read the text. Broken document head templates ruin click-through rates before readers ever see your writing.

Before you edit your blog or documentation layout file, gather these prerequisites so you can test and deploy your template changes cleanly:

  • Template repository access: Write permissions for your framework layout or server-rendered head partial.
  • CMS field mappings: Exact variable names for your post title, summary, slug, hero image URL, and timestamps.
  • Default fallback image: A static 1200x630 brand image hosted on a public CDN for posts without custom art.
  • Search Console access: Verified domain properties in Google Search Console and Bing Webmaster Tools to inspect rendered HTML.
  • 15 minutes of build time: Enough time to update the head layout, compile a preview build, and run curl checks.

What you need before editing your post template

Every HTML document head serves three distinct audiences at once: web browsers parsing layout rules, search engine and AI crawlers indexing your topic, and social platforms fetching link preview cards. If your template leaves out required attributes or renders tags only via client-side JavaScript, link unfurlers that do not execute scripts will see an empty shell.

A clean post template separates global static declarations from dynamic post variables. You define character encoding and mobile scaling once across the entire site, while titles, descriptions, canonical addresses, and social images populate dynamically from your content database or Markdown frontmatter on every build.

When building templates in component frameworks like Next.js, Nuxt, Astro, or Remix, make sure child page layouts replace parent fallback tags rather than appending duplicate tags to the bottom of ``.

Search crawlers and social bots handle duplicate meta tags inconsistently: some read only the first declaration while others overwrite it with the last one. Assign a unique key or use your framework's built-in head manager so each route outputs exactly one , one , and one ``.

Make sure your rendering pipeline escapes double quotes and HTML entities inside dynamic strings before injecting them into attribute values. An unescaped quote inside a post summary breaks the closing delimiter of a meta tag and corrupts the rest of the document head.

Post template head tags

Head ElementPrimary PurposeOutput ConstraintTemplate Source
meta charsetCharacter encodingUTF-8, first 1024 bytesStatic constant
meta viewportMobile layout scalingwidth=device-width, initial-scale=1Static constant
titleSERP headline and tab label50–60 characterspost.seoTitle or post.title
meta descriptionSearch snippet summary70–160 characterspost.excerpt or post.summary
meta robotsCrawler indexing directiveindex, follow on public postspost.noindex boolean flag
link canonicalPrimary page addressAbsolute HTTPS URLsite.url + post.path
meta og:titleSocial card headlineUnder 65 characterspost.socialTitle or post.title
meta og:descriptionSocial card summary2–3 concise sentencespost.excerpt
meta og:urlCanonical social share URLMatches link canonicalsite.url + post.path
meta og:imageSocial preview graphicAbsolute URL, 1200x630 pxpost.coverImage or fallback
meta og:typeObject classificationarticle for blog postsTemplate route constant
meta twitter:cardX card layout formatsummary_large_imageStatic constant

1. Set character encoding and the viewport tag at the top of the head

Tag ordering inside the document head is not purely cosmetic. Place immediately after the opening tag, before any comments, stylesheets, or tracking scripts.

If an oversized inline script or CSS block pushes the character encoding declaration past that initial 1024-byte buffer, browsers may have to re-parse the document head from scratch or render curly apostrophes and non-ASCII characters as garbled symbols in search snippets. Keeping on the very first line inside prevents encoding mismatches across every parser.

Right below the character set, declare the responsive viewport configuration: ``. This single line tells mobile browsers and mobile-first search crawlers to match the layout width to the device screen rather than rendering a miniature 980-pixel desktop canvas.

Follow three strict rules when configuring your top-of-head foundation tags:

  • Never block user zooming: Omit maximum-scale=1 and user-scalable=no from your viewport tag so visually impaired readers can enlarge text.
  • Keep analytics scripts lower: Never inject bulky third-party inline scripts above your charset, viewport, and title tags.
  • Declare the document language: Add the lang attribute to your root `` tag (such as lang="en") to aid screen readers and translation parsers.

2. Configure dynamic title tags and meta descriptions for organic search

Your `` element is the strongest on-page headline signal for search engines and the clickable link text shown on search result pages. Structure your template variable so the specific post title comes first, followed by a clean separator and your brand name only if character space allows. Keep the rendered output under 60 characters so desktop and mobile displays do not cut off the value proposition.

Write a fallback rule in your template logic that suppresses the trailing brand suffix whenever post.title already exceeds 52 characters.

Pair the title with a dynamic `` tag between 70 and 160 characters.

Use this variable pattern in your post layout:

  1. Primary SEO title: Pull from a dedicated post.seoTitle field first, falling back to the main post.title H1 string.
  2. Primary description: Pull from post.metaDescription, falling back to a plain-text, whitespace-trimmed slice of the opening paragraph.
  3. HTML sanitization: Strip all Markdown formatting, line breaks, and HTML tags from dynamic description strings at build time.
  4. Category and paginated archives: Append page numbers or topic qualifiers dynamically on archive routes so paginated listings never share identical titles and descriptions.
Drop the trailing brand suffix from the title tag whenever post.title exceeds 52 characters.

<strong>Tip:</strong> Test your live post URL with curl before sharing it on social platforms, because link preview caches hold onto broken Open Graph tags for hours.

3. Add canonical URLs and robots indexing directives

Every public blog post template needs a self-referencing canonical tag: ``. Build the href attribute in your server template by combining your production base origin with the clean route pathname, never by echoing the raw incoming request URL. Echoing the request URL causes query parameters like ?utm_source=newsletter or ?page=2 to become accidental canonical targets.

Enforce strict formatting consistency in your canonical generator so your sitemap, internal links, and canonical tags agree on the exact same character string.

In particular, normalize three URL traits inside the helper function that builds your canonical string:

  • Case sensitivity: Force lowercase characters on all path slugs so /Guides/Post-Slug and /guides/post-slug never split signals.
  • Trailing slash policy: Strip or append the trailing slash consistently to match your framework router and XML sitemap output.

Next, bind your `` directive to an environment and post-level condition:

  • Production published posts: Output content="index, follow, max-image-preview:large" so search engines index the article and display full-width thumbnail previews in Discover and search results.
  • Staging and preview deployments: Check your deployment environment variable and force content="noindex, nofollow" on every non-production hostname.

Watch out: Never combine a noindex meta tag with a Disallow rule for that same URL in robots.txt. If crawlers are blocked from fetching the page by robots.txt, they can never read the HTML `` to see the noindex directive.

4. Implement Open Graph and social card tags for link previews

When someone shares your article in Slack, iMessage, LinkedIn, Discord, or X, the platform dispatches a lightweight scraper to read your Open Graph metadata. According to the Open Graph protocol specification, every page must declare four foundational properties (og:title, og:type, og:image, and og:url) using the property attribute on `` elements rather than the standard name attribute.

For blog posts and technical guides, set og:type to article instead of website. Using the article classification unlocks structured namespace properties like article:published_time and article:modified_time, formatted in ISO 8601 UTC strings (such as 2026-11-20T09:00:00Z). Both social parsers and AI search optimization crawlers read these timestamps to verify content freshness.

Social image tags fail more often than any other template field because developers pass relative paths like /images/cover.png. Avoid SVG files for og:image, as major social platforms refuse to rasterize vector images in link cards.

Alongside your Open Graph property tags, include X card directives and accessibility metadata using these rules:

  • Twitter card layout: Add `` (using name rather than property) so X renders a full-width visual banner above the headline while reading og:title, og:description, and og:image as automatic fallbacks.
  • Image alt text: Include `` populated from your cover image caption or post title so screen readers describe the social card accurately.
  • Site name: Set `` once in your base layout so messaging apps label the publisher clearly without needing the brand name inside og:title.

Open Graph property specifications

Open Graph PropertyExpected ValueTemplate Binding Rule
og:typearticleHardcode on post layout templates
og:titlePlain text under 65 charsOmit brand suffix to prevent truncation
og:descriptionPlain text, 100–160 charsReuse sanitized meta description
og:urlAbsolute HTTPS canonical URLMust match link rel=canonical exactly
og:imageAbsolute HTTPS URL, 1200x630 px1.91:1 ratio; fallback to default brand card
og:image:width1200Speeds up first-share card rendering
og:image:height630Pairs with og:image:width
article:published_timeISO 8601 datetime stringpost.publishedAt in UTC format
article:modified_timeISO 8601 datetime stringpost.updatedAt in UTC format

5. Validate rendered HTML markup and automate site health checks

Inspecting your page inside Chrome DevTools is not enough to verify your template. Browser developer tools display the live DOM after client-side JavaScript runs, whereas many AI crawlers and social link preview bots only read the initial server-rendered HTML response.

Once a template goes live, regressions still happen when CMS fields change, framework upgrades alter head injection order, or a new route overrides global defaults.

Crawlers and social bots read the initial server response, not the live browser DOM after JavaScript runs.

FAQ

Why do Slack and LinkedIn fail to show my Open Graph image when the tag looks right in Chrome DevTools?

Social link preview bots do not run client-side JavaScript when fetching a URL, so tags injected purely in the browser by single-page frameworks never appear in the initial HTTP response. They also reject relative image paths like /img/cover.png, oversized files, or non-standard image formats.

Should og:title and the HTML `` tag use the exact same template variable?

They can share the same base headline, but your Open Graph title should usually omit the trailing brand suffix. Social preview cards already display your domain name right above or below the headline on LinkedIn, X, and Slack. Leaving the brand suffix out of og:title gives your article headline an extra 10 to 15 characters before social cards truncate it.

Do I need duplicate twitter:title and twitter:description tags if I already have Open Graph tags?

No, X automatically falls back to og:title, og:description, and og:image when specific Twitter properties are absent. You only need to include `` alongside your standard Open Graph properties to trigger the large image layout without bloating your document head.

Meet yours today.

Today is the least it will ever know about your site.