Skip to content
Tutorials Center
My learning

Topics

HTML Reference ยท Document and Metadata

The <meta> element

Reference for the HTML <meta> element: charset, viewport, description, theme-color, http-equiv pragmas and social tags, with examples and technical details.

The <meta> element provides metadata that has no dedicated element of its own. Depending on its attributes it does one of four jobs: declare the character encoding (charset), give a named value (name + content), act like an HTTP header (http-equiv + content), or supply a microdata property (itemprop + content).

HTML
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Opening hours, prices and a map for the city aquarium.">

Try it

Reading meta values

Attributes

Exactly one of name, http-equiv, charset or itemprop must be present.

Attribute Values Description
charset utf-8 Declares the document's character encoding. utf-8 is the only valid value.
name A metadata name (see below) The name of the metadata; its value goes in content.
content Text The value for name, http-equiv or itemprop.
http-equiv content-language, content-type, default-style, refresh, content-security-policy, x-ua-compatible A "pragma" that works like the matching HTTP response header.
media A media query Only for name="theme-color": apply the color when the query matches.
itemprop A property name A microdata property whose value is in content.

It also accepts the global attributes.

Common name values

Name Purpose
viewport Controls the layout viewport on mobile devices. width=device-width, initial-scale=1 is the standard choice.
description A one- or two-sentence summary that search engines may show under your title.
theme-color A color browsers may use for their toolbar or title bar.
color-scheme The color schemes the page supports, e.g. light dark.
robots Instructions for crawlers, e.g. noindex, nofollow.
referrer The default referrer policy for the document.
author, generator, application-name Who wrote the page, which tool made it, and the web app's name.
keywords Comma-separated keywords. Major search engines ignore it.

Social preview tags such as Open Graph (<meta property="og:title" โ€ฆ>) use a non-standard property attribute defined by those platforms; browsers ignore them, but sharing services read them. See Social Sharing Previews.

Usage notes

  • Charset first. <meta charset="utf-8"> must appear within the first 1024 bytes of the file, so make it the first child of <head>. Save the file as UTF-8 too. See Character Encoding and UTF-8.
  • Don't disable zooming. Values like user-scalable=no or maximum-scale=1 stop people from pinch-zooming, which is an accessibility failure. Most mobile browsers now ignore them anyway. Responsive Web Design explains the viewport tag.
  • Write a real description. A unique, specific description per page helps searchers choose your result. Tips are in Page Titles and Descriptions.
  • Prefer real HTTP headers. http-equiv is a fallback for when you can't set headers. Some headers, such as frame-ancestors in a CSP, only work as real headers.
  • Avoid refresh redirects. <meta http-equiv="refresh" content="5; url=/new"> reloads or redirects the page after a delay, which can disorient users. Use a server-side redirect when you can.

Technical summary

Content categories Metadata content. With itemprop: also flow content and phrasing content.
Permitted content Nothing; it is a void element
Tag omission Must have a start tag and no end tag
Permitted parents With charset or http-equiv: a <head> element (http-equiv also inside a <noscript> in the head). With name: any element that accepts metadata content. With itemprop: any element that accepts metadata or phrasing content.
Implicit ARIA role No corresponding role
DOM interface HTMLMetaElement
Default display none

Browser support

Supported in every browser. Support for individual name values (for example theme-color and color-scheme) varies between browsers.