Skip to content
Tutorials Center
My learning

Topics

Lesson 52 of 122 ยท The Head, Metadata and SEO

Meta Tags

A practical guide to HTML meta tags: charset, viewport, description, robots, theme-color, color-scheme, referrer and http-equiv, plus the old tags you can drop.

The <meta> element is the head's all-purpose label. Each one records a single fact about the document: which character encoding it uses, how it should behave on phones, whether search engines may index it, what color the browser's toolbar should be, and more.

There are dozens of meta tags floating around old templates and blog posts, and many of them do nothing at all today. This lesson covers the ones that matter in modern HTML, explains exactly what each does, and points out the ones you can safely delete.

The anatomy of a meta tag

<meta> is a void element: it has no content and no closing tag. Every meta element uses one of these attribute patterns:

HTML
<!-- 1. Character encoding -->
<meta charset="utf-8">

<!-- 2. Named metadata: name + content -->
<meta name="description" content="A field guide to backyard birds.">

<!-- 3. A pragma directive: http-equiv + content -->
<meta http-equiv="refresh" content="30">

You will also see <meta property="og:title" content="โ€ฆ">. The property attribute comes from a different system (RDFa) and is used by Open Graph social tags, covered in Social Sharing Previews. Microdata uses <meta itemprop="โ€ฆ">, covered in Structured Data.

Let's start by listing every meta tag on a page, because there is no other way to see them without DevTools.

List the meta tags

charset: the character encoding

HTML
<meta charset="utf-8">

This tells the browser how to turn the bytes of the file into characters. The only value you should use is utf-8, and the tag must appear within the first 1,024 bytes of the document, which in practice means first in the head. If a server also sends an encoding in its HTTP Content-Type header, the header wins. Character Encoding and UTF-8 explains what goes wrong without it.

viewport: behaving on phones

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

Without this tag, mobile browsers assume the page was designed for a desktop screen, lay it out about 980 pixels wide and shrink it to fit, leaving tiny text. With it, the layout viewport matches the device's width and your CSS media queries work as intended. See Responsive Web Design.

Never disable zooming. Values such as user-scalable=no or maximum-scale=1 stop people from pinching to zoom, which locks out anyone who needs larger text. Some browsers ignore them for that reason. Fix layouts that "break" when zoomed instead.

The content value is a comma-separated list of properties. The ones you may see:

Property Meaning
width Layout width: device-width or a number of pixels such as width=600
height Layout height, rarely used
initial-scale Zoom when the page first loads (1 = no zoom)
minimum-scale, maximum-scale Limits for how far the visitor can zoom out or in
user-scalable yes or no: whether zooming is allowed
viewport-fit cover lets the page draw under notches and rounded corners (use with env(safe-area-inset-*))
interactive-widget How the on-screen keyboard resizes the page: resizes-visual, resizes-content or overlays-content

A fixed width=600 makes a phone lay the page out as if its screen were 600 pixels wide and then scale it to fit, which is how old non-responsive pages were squeezed onto phones. A responsive page should use width=device-width and let CSS do the work.

description: the summary

HTML
<meta name="description" content="A field guide to the birds you can spot from your kitchen window.">

A short summary that search engines may show under your title in results. It is not shown on the page and is not a ranking factor. Writing good descriptions is covered in Page Titles and Descriptions.

robots: instructions for search engine crawlers

The robots meta tag tells crawlers what they may do with a page they have already fetched:

HTML
<!-- Do not show this page in search results -->
<meta name="robots" content="noindex">

<!-- Show it, but do not follow its links -->
<meta name="robots" content="nofollow">

<!-- Several rules, comma-separated -->
<meta name="robots" content="noindex, nofollow">

Common values:

Value Meaning
noindex Do not include this page in search results.
nofollow Do not follow the links on this page.
nosnippet Do not show a text snippet or video preview for this page.
max-snippet:50 Limit text snippets to 50 characters.
max-image-preview:large Allow large image previews in results.

The default is "index and follow", so <meta name="robots" content="index, follow"> does nothing; leave it out. You can also address one crawler by name, for example name="googlebot".

Typical uses for noindex are internal search results pages, thank-you pages after a form, and staging copies of a site. Two important limits:

  • A crawler must fetch the page to see the tag. If robots.txt blocks a URL, crawlers never read its noindex, and the bare URL can still appear in results when other sites link to it.
  • It is not access control. Robots rules are a polite request that well-behaved crawlers honor. Anything private must sit behind a login.

For files that cannot carry a meta tag, such as PDFs, the server can send the same rules in an X-Robots-Tag HTTP header.

theme-color: tinting the browser

HTML
<meta name="theme-color" content="#2f6b4f">

Some browsers use this color for the address bar, the tab strip or the title bar of an installed web app. Support varies, so treat it as a finishing touch. The media attribute lets you supply different colors for light and dark mode:

HTML
<meta name="theme-color" content="#ffffff" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#14211b" media="(prefers-color-scheme: dark)">

color-scheme: light, dark or both

HTML
<meta name="color-scheme" content="light dark">

This tells the browser which color schemes your page supports, before any CSS has loaded. When the page supports dark mode and the user prefers it, the browser can paint the default background dark from the start (no white flash) and render built-in parts such as form controls and scrollbars in their dark style. The CSS color-scheme property does the same thing per element; the meta tag sets it for the whole page early.

Change the value with the drop-down and watch the default colors of the page and its controls change:

color-scheme in action

With light dark, the result follows your operating system's setting. Switch your system to dark mode and run it again.

referrer: what you tell other sites

When someone follows a link from your page, the browser normally tells the destination where the visitor came from, in the Referer header. The referrer meta tag sets the policy for the whole page:

HTML
<meta name="referrer" content="strict-origin-when-cross-origin">
Value What other sites receive
no-referrer Nothing at all.
origin Only the origin, such as https://birds.example.
strict-origin-when-cross-origin The full URL for links within your site, only the origin for other sites, and nothing when going from HTTPS to HTTP. This is the browser default.
same-origin The full URL within your site, nothing for other sites.

A stricter policy is useful when your URLs contain private details such as search terms or account pages. Individual links can override it with the referrerpolicy attribute, as you saw in Iframes.

http-equiv: pretending to be a header

http-equiv meta tags imitate HTTP response headers for cases where you cannot configure the server. Only a few values do anything in modern browsers.

refresh

HTML
<!-- Reload this page every 60 seconds -->
<meta http-equiv="refresh" content="60">

<!-- Go to another page after 5 seconds -->
<meta http-equiv="refresh" content="5; url=https://birds.example/new-home">

Avoid both forms when you can. Automatic reloads and timed redirects can move people before they have finished reading and confuse screen reader users. For a page that has moved, a server-side redirect (status 301 or 308) is faster and understood by every search engine. If you must use a meta refresh redirect, use a delay of 0.

content-security-policy

HTML
<meta http-equiv="content-security-policy" content="default-src 'self'; img-src 'self' https://images.example">

A Content Security Policy restricts where a page may load scripts, styles, images and other resources from, which limits the damage of a cross-site scripting bug. Sending it as an HTTP header is better, because a few directives (such as frame-ancestors and reporting) do not work in the meta version. CSP is a big subject of its own; for now, know that this tag exists.

Tags you can delete

Old templates are full of meta tags that modern browsers and search engines ignore:

  • <meta name="keywords">: ignored by major search engines.
  • <meta http-equiv="X-UA-Compatible" content="IE=edge">: only meant for Internet Explorer, which is retired.
  • <meta http-equiv="content-type" content="text/html; charset=utf-8">: an older, longer spelling of <meta charset="utf-8">. Use the short form.
  • <meta name="revisit-after">, <meta name="distribution">, <meta name="rating"> and similar: invented conventions no major crawler follows.

A few named tags are harmless and occasionally useful: author (who wrote the page), application-name (the name of a web app) and generator (the software that built the page).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which viewport tag is the right default for a responsive page?

    width=device-width, initial-scale=1 matches the layout to the device. Adding user-scalable=no would stop people from zooming, which hurts accessibility.
  2. 2. Your robots.txt blocks /drafts/, and the pages there contain <meta name="robots" content="noindex">. What is the problem?

    A crawler has to fetch a page to read its meta tags. If robots.txt blocks the URL, the noindex is never seen and the URL may still be listed when other sites link to it.
  3. 3. What does <meta name="color-scheme" content="light dark"> do?

    color-scheme declares which schemes the page supports. The address bar color is the job of theme-color.
  4. 4. A page has moved permanently. What is the best way to send visitors to the new address?

    A server-side permanent redirect is immediate, accessible and understood by every browser and search engine. Meta refresh is a fallback for when you cannot configure the server.

Summary

  • A <meta> element uses charset, name + content, or http-equiv + content.
  • Start every page with <meta charset="utf-8"> and <meta name="viewport" content="width=device-width, initial-scale=1">, and never disable zooming.
  • description summarizes the page for search results; robots controls indexing for crawlers that can fetch the page.
  • theme-color tints browser UI in some browsers; color-scheme declares light and dark support before CSS loads.
  • referrer controls how much of your URL other sites receive.
  • http-equiv="refresh" and meta CSP exist, but server-side redirects and headers are usually better.
  • Delete keywords, X-UA-Compatible and other tags that no longer do anything.

Next lesson: Social Sharing Previews.