Thuta Learning
HTML
AdvancedWeb DevelopmentBeginner

SEO & Meta Tags

HTMLLesson 2820 min

What you'll walk away with

  • Write a unique, concise <title> and meta description for every page
  • Explain what goes wrong without the viewport and charset meta tags
  • Use rel="canonical" for duplicate URLs and a robots noindex for pages that should stay out of search
  • Add Open Graph tags for share previews, knowing metadata never replaces good content

Explain it simply

Explain it simply

Think of <head> as a book's cover and back-cover blurb. None of it shows on the page itself, yet the text in the browser tab, the headline and summary in Google results, and the card that appears when a link is shared on Facebook or Telegram all come from here.

The title and description act like a short advert that decides whether people click your link. The viewport tag tells a phone "show this page at the phone's own width"; without it, the phone shrinks a desktop-sized layout until the text is too small to read.

Problem → Why → Solution

The problem: the same title everywhere and stuffed keywords

A website uses one template for every page, so every title reads "Home" and every description is identical. In search results all ten pages of the site appear as "Home" and cannot be told apart, and a user with ten tabs open has the same problem. The developer also crammed dozens of words into meta keywords hoping to rank higher, but Google does not use that tag for ranking at all.

every-page-head.html
<head>
  <title>Home</title>
  <meta name="description" content="Welcome to our website.">
  <meta name="keywords" content="html, html tutorial, learn html, free html,
        best html, html course, web, website, coding, programming">
</head>

Why doesn't this work?

Search engines understand each page from its title, headings and visible content, so identical titles remove the signal that tells pages apart. Meta keywords were abused for spam so heavily, more than a decade ago, that Google ignores them for ranking. Giving each page its own title and description is what actually helps.

Core concept: who each piece of head metadata talks to

<meta charset="utf-8"> tells the browser how to turn bytes into characters; without it, Myanmar text, emoji and © can turn into garbage. It must appear within the first 1024 bytes of the document, so put it first in <head>. <meta name="viewport" content="width=device-width, initial-scale=1"> tells mobile browsers to lay the page out at the device's width; without it, most phones render a desktop-width layout of about 980px and shrink it down.

<title> is used mainly as the browser tab text, the bookmark name and the search result headline. Make every title unique, put the important words first and the site name last: "Input Types - HTML Tutorial". The meta description often appears as the search result snippet, but a search engine may replace it with text from the page that better matches the user's query. There is no exact character limit, yet long descriptions get truncated, so keep it to a sentence or two.

<link rel="canonical" href="..."> suggests to search engines which URL is the original when one page is reachable at several addresses, such as a copy with ?ref=facebook. <meta name="robots" content="noindex"> is for pages that should stay out of search results, such as a thank-you page or internal search results. Open Graph tags (og:title, og:description, og:image) control the share card in social apps.

On a site in two languages, such as Myanmar and English, tags like <link rel="alternate" hreflang="my" href="..."> point to the page's other language versions, so a search engine can show users the version in their language. JSON-LD structured data likewise describes facts such as ratings and prices in a machine-readable way, but it must be derived only from information visible on the page.

Metadata only helps a page represent itself well. It cannot replace useful content, correct headings, crawlable <a href> links and fast pages, and metadata that does not match the content damages users' trust.

Mental model: one head, several readers
  1. charset, viewport: the browser
  2. title, description: search
  3. canonical, robots: crawlers
  4. og:*: social apps
  5. Real content still matters most

Ask "who reads this tag?" and it becomes clear what belongs in it.

General pattern

html
<html lang="language-code">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Specific page topic - Site name</title>
  <meta name="description" content="One or two sentences about this page.">
  <link rel="canonical" href="https://example.com/the-one-true-url">
  <meta property="og:title" content="Title for share cards">
</head>

charset comes first, followed by the viewport, a unique title and description, the canonical link and Open Graph tags. Open Graph uses the property attribute rather than name.

Example: the essential head of a tutorial page

This head contains the four tags every page needs. Nothing appears in the page body, so look at the browser tab instead, and switch to a phone size with the DevTools device toolbar.

html
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>HTML Tutorial for Beginners</title>
  <meta name="description" content="Learn HTML from basic to practical projects with simple examples.">
</head>

Code breakdown

  1. Character set<meta charset="UTF-8">

    As the first tag in head, it lets the browser know about UTF-8 before reading any other text. "UTF-8" and "utf-8" are both correct.

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

    width=device-width matches the layout width to the phone's screen, and initial-scale=1.0 starts without zoom. CSS media queries need this tag to behave on phones.

  3. Title<title>HTML Tutorial for Beginners</title>

    This becomes the tab text, bookmark name and search headline. Other pages on the site need their own titles, such as "Input Types - HTML Tutorial".

  4. Description<meta name="description" content="Learn HTML from basic to practical projects with simple examples.">

    It summarises the page honestly in one sentence. Search engines may use it as the snippet, though that is not guaranteed.

You should see
Nothing appears in the page body. The browser tab shows "HTML Tutorial for Beginners", and on a phone the page is laid out at the device's width. The description text is not visible on the page; search results may use it as the snippet.

Open Graph for social share cards

When a link is pasted into apps such as Facebook, LinkedIn, Telegram or Slack, the app reads the page's head to build a card. Without og:image the card often has no picture, and without og:title the app usually falls back to <title>. Write the image as an absolute URL starting with https://, because apps often fail to resolve relative paths.

og-tags.html
<meta property="og:type" content="article">
<meta property="og:title" content="Input Types - HTML Tutorial">
<meta property="og:description" content="Pick the right input type for each field.">
<meta property="og:url" content="https://example.com/html/input">
<meta property="og:image" content="https://example.com/img/input-card.png">

In real projects

Where this shows up in real projects

In frameworks such as Next.js, each page produces its title, description, canonical and Open Graph tags from a metadata object or function, filled automatically from CMS data, so no template hard-codes "Home". Sites with a thousand blog or product pages take the description from each article's excerpt and og:image from its cover image.

Before launch, teams check indexing in Google Search Console and test share cards with the platforms' link preview debugging tools. Adding noindex to a staging site to keep it out of search, then forgetting to remove it when deploying to production, is a real and recurring incident, so it belongs on the release checklist. Many teams add an automated test that fails the build if production HTML contains noindex.

Common mistakes

Common mistakes

1. Meta keywords and hidden keyword stuffing

Google does not use meta keywords for ranking. Text hidden with CSS, or a keyword repeated over and over in the title, can violate spam policies and confuses users as well.

2. One title and description for every page

A title hard-coded in a template makes pages indistinguishable in search results and browser tabs. Lead each title with that page's own main topic.

3. Missing the viewport, or disabling zoom

Without a viewport, text on phones is far too small. Going the other way, maximum-scale=1 or user-scalable=no stops people with low vision from zooming, which is an accessibility failure.

4. Writing og:image as a relative path

Social apps often fail to resolve a relative path such as content="/img/card.png", so the share card shows no picture. Use the full URL starting with https://.

Best practices

Best practices

  • Make charset the first tag in <head>.
  • Write titles and descriptions that match the visible content.
  • Confirm on every deploy that no stray robots noindex was left behind.

Mini challenge

Mini challenge: a product page head

Write a complete <head> for an online shop's "Handwoven Shan Bag" product page. The body only needs the product name as a heading.

  • <html lang="en">, charset and viewport
  • A title with the product name first and the shop name last
  • A one- or two-sentence description that honestly describes the product
  • A canonical link to https://shop.example.com/bags/shan-bag plus og:title, og:image and og:url
shan-bag.html
<!doctype html>
<html>
<head>
  <!-- TODO: character set first -->
  <!-- TODO: mobile viewport -->
  <!-- TODO: unique title: product first, shop name last -->
  <!-- TODO: meta description -->
  <!-- TODO: canonical link and Open Graph tags (absolute URLs) -->
</head>
<body>
  <!-- TODO: product name as the page heading -->
</body>
</html>

Expected: The page shows only the "Handwoven Shan Bag" heading, and the tab reads "Handwoven Shan Bag - Golden Loom Shop". document.querySelector('link[rel=canonical]').href returns https://shop.example.com/bags/shan-bag.

Show hint

Open Graph tags use property="og:...", not name. Write og:image and og:url as full URLs starting with https://.

Show solution
shan-bag.html
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Handwoven Shan Bag - Golden Loom Shop</title>
  <meta name="description"
        content="A cotton shoulder bag handwoven in Shan State, with a zip pocket.">
  <link rel="canonical" href="https://shop.example.com/bags/shan-bag">
  <meta property="og:type" content="website">
  <meta property="og:title" content="Handwoven Shan Bag">
  <meta property="og:url" content="https://shop.example.com/bags/shan-bag">
  <meta property="og:image" content="https://shop.example.com/img/shan-bag.jpg">
</head>
<body>
  <h1>Handwoven Shan Bag</h1>
</body>
</html>

Quick quiz 1 / 3

What does filling <meta name="keywords" content="..."> with many words do for Google ranking?

Quick quiz 2 / 3

A product page is reachable at /bags/shan-bag and /bags/shan-bag?ref=facebook. What should you add?

Quick quiz 3 / 3

What usually happens when a responsive page without a viewport meta tag is opened on a phone?

What to remember

  • Put charset first, and use the viewport so phones lay the page out at device width.
  • Give every page a unique title and an honest description; meta keywords do not help ranking.
  • Canonical consolidates duplicate URLs, and robots noindex keeps a page out of search.
  • Open Graph controls share cards, and metadata never replaces good content.

HTML Living Standard — Document Metadata — WHATWG

Updated on

Progress is saved only in this browser on this device. It isn't synced to other devices.

Report a problem with this lessonOpens your email app with this lesson's address filled in — nothing is sent until you send it.

SEO & Meta Tags | Thuta Learning