Skip to content

Metadata and SEO

Search engines and social media rely on metadata—information about your page. Well-crafted metadata improves search rankings, click-through rates, and how your content appears when shared. This tutorial covers essential meta tags and structured data.

What you’ll learn:

  • The <meta> tag and common attributes
  • Open Graph tags for social media sharing
  • Twitter Card tags for Twitter
  • Structured data and JSON-LD
  • Basic SEO principles
  • Canonical tags and robots directives
  • Schema.org markup for rich results

Prerequisites:


The <meta> tag provides metadata about your HTML document. It’s in the <head>, not the body.

Always declare UTF-8 as your character encoding:

<meta charset="UTF-8">

This must be within the first 1024 bytes of your document and should be the first meta tag.

Make your page responsive:

<meta name="viewport" content="width=device-width, initial-scale=1.0">

This tells browsers:

  • width=device-width — Page width matches device width
  • initial-scale=1.0 — Initial zoom level is 100%

Your page description appears in search results:

<meta name="description" content="Learn HTML from beginner to advanced. Free tutorials and reference guide.">

Best practices:

  • 150-160 characters for optimal display
  • Include relevant keywords naturally
  • Make it compelling—it’s the first impression
  • Be specific to each page, not generic

Though less important now, keywords help search engines:

<meta name="keywords" content="HTML, tutorials, web development, learning">

Note: Keyword stuffing doesn’t work. Search engines ignore irrelevant keywords.


Open Graph tags control how your content appears when shared on Facebook, LinkedIn, Pinterest, and other platforms.

Result

Key Open Graph tags:

  • og:title — Title when shared (different from page title)
  • og:description — Description when shared
  • og:image — Image URL (minimum 1200x630 pixels)
  • og:url — Canonical URL of the content
  • og:type — Type of content: website, article, profile, etc.

For articles, add publication metadata:

<meta property="article:published_time" content="2024-12-10T14:30:00Z">
<meta property="article:modified_time" content="2024-12-11T10:00:00Z">
<meta property="article:author" content="https://example.com/author/john">
<meta property="article:section" content="Technology">
<meta property="article:tag" content="HTML">
<meta property="article:tag" content="Web Development">

Control how your content appears on Twitter:

Result

Twitter Card types:

  • summary — Title, description, thumbnail
  • summary_large_image — Same as summary but with large image
  • player — For video/audio content
  • app — For mobile app promotion

JSON-LD (JSON for Linking Data) helps search engines understand your content. It’s the recommended format by Google and other search engines.

Result
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Organization",
"name": "Example Company",
"url": "https://example.com",
"logo": "https://example.com/logo.png",
"sameAs": [
"https://www.facebook.com/example",
"https://www.twitter.com/example",
"https://www.linkedin.com/company/example"
],
"contactPoint": {
"@type": "ContactPoint",
"contactType": "Customer Service",
"telephone": "+1-555-123-4567",
"email": "[email protected]"
}
}
</script>
<script type="application/ld+json">
{
"@context": "https://schema.org/",
"@type": "Product",
"name": "Widget XL",
"image": "https://example.com/widget.jpg",
"description": "An excellent widget",
"brand": {
"@type": "Brand",
"name": "Widget Corp"
},
"offers": {
"@type": "Offer",
"price": "29.99",
"priceCurrency": "USD"
},
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "4.5",
"reviewCount": "89"
}
}
</script>

Control how search engines handle your page:

<!-- Index this page, follow links -->
<meta name="robots" content="index, follow">
<!-- Don't index this page -->
<meta name="robots" content="noindex, nofollow">
<!-- Index but don't follow external links -->
<meta name="robots" content="index, nofollow">
<!-- Don't show in search snippets longer than 160 chars -->
<meta name="robots" content="max-snippet:-1, max-image-preview:large">

Specify the page language:

<html lang="en">
<meta http-equiv="Content-Language" content="en-US">

Tell search engines this is the preferred version of a page:

<link rel="canonical" href="https://example.com/page">

Use this when you have similar content at multiple URLs.

Redirect after a delay (use sparingly):

<!-- Redirect after 5 seconds -->
<meta http-equiv="refresh" content="5; url=https://example.com/new-location">

Result

  • Keep under 60 characters
  • Include primary keyword
  • Make it compelling and unique
  • Front-load important keywords
<!-- Good -->
<title>HTML Tutorial for Beginners - Learn Web Development</title>
<!-- Bad -->
<title>Page</title>
  • Use descriptive, hyphenated URLs
  • Keep URLs short
  • Use HTTPS
  • Avoid parameters when possible
Good: https://example.com/tutorials/html/basics
Bad: https://example.com/page.php?id=123
  • Use only one <h1> per page
  • Follow hierarchy: h1 > h2 > h3, etc.
  • Include keywords naturally
  • Make headings descriptive
<h1>Learning HTML: A Beginner's Guide</h1>
<h2>Getting Started</h2>
<h3>Installing a Text Editor</h3>
  • Link to related pages
  • Use descriptive anchor text
  • Focus on user experience
  • Don’t overdo it
<!-- Good -->
<a href="/tutorials/css">Learn CSS after HTML</a>
<!-- Bad -->
<a href="/tutorials/css">click here</a>

Create a complete meta tag setup:

Result

  • Google PageSpeed Insights — Analyzes performance and SEO
  • Google Search Console — Monitor search visibility
  • Structured Data Testing Tool — Validate JSON-LD
  • Meta Tags Preview — See how pages appear when shared
  • Lighthouse — Audit page quality


  • Charset: Always use UTF-8
  • Viewport: Essential for mobile responsiveness
  • Description: 150-160 characters, unique per page
  • Open Graph: Control social media sharing
  • Twitter Cards: Optimize for Twitter sharing
  • JSON-LD: Structured data for search engines
  • Canonical tags: For duplicate content
  • Robots: Control search engine behavior
  • SEO-friendly URLs, titles, and headings

Accessibility Deep Dive

Master WCAG compliance and ARIA attributes. Continue →

SEO Optimization

Advanced technical SEO with HTML. Continue →