Definition and Usage
Here, metadata refers to
coded additional information required to handle and technically process HTML documents.
In HTML, there are metadata-related tags intended for "predefined, specific purposes," such as:
The <meta> tag is used to represent metadata other than the purposes covered by these tags.
For example, it can represent various types of information, such as document character encoding, summary descriptions, search engine optimization (SEO) information, social media sharing details, and web application data. Additionally, custom metadata allows you to represent and utilize diverse metadata tailored for specific needs, such as web analytics, user tracking, and delivering personalized content.
The <meta> tag is a void element that cannot contain any content. This means that it does not have a closing tag (</meta>).
Also, multiple <meta> tags can be used in a document.
Basic Example
Check how to use the <meta> tag through the following example.
<head>
<meta charset="utf-8">
<title>How to Use Meta Tags</title>
<meta name="description" content="Learn how to use meta tags.">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
</head>
As shown in the example above, multiple <meta> tags can be used in a document.
Attributes Related to Metadata Provided by the <meta> Tag
The <meta> tag can represent metadata beyond "predefined uses for specific purposes" using the following related attributes.
charset |
The character encoding of the document is specified by this attribute. The value of this attribute is a string type and is case-insensitive.
In HTML5, the value must be specified as utf-8, UTF-8, or another case-insensitive equivalent. |
|---|---|
http-equiv |
This attribute specifies metadata corresponding to HTTP headers. It is mainly used for purposes such as document refresh and cache control.
The possible values of this attribute are specific values that define behavior similar to HTTP headers. It is used together with the content attribute to specify the value of the metadata. |
name |
This attribute is used to represent document-level metadata in a way different from the charset, http-equiv, and itemprop attributes. It has the characteristic of specifying metadata names and values as a pair.
The value of this attribute specifies the name of the metadata being used, and the content attribute is used together to specify the value of that metadata. There are standard values included in the specification, non-standard values supported by most browsers, and values used by specific search engines.
In addition, custom document-level metadata can be specified by using the value of this attribute as the metadata name and the content attribute as the metadata value. |
content |
This attribute represents the value of the metadata specified by the http-equiv or name attribute. |
itemprop |
This attribute is used to provide "custom metadata" at the content item level rather than the document level. The value of this attribute becomes the name of the custom metadata.
It is mainly used when HTML elements have specific properties and is often used as "custom metadata" to provide semantic information of marked-up content (structured information that can be used by search engines and others). |
Be sure to understand!
The charset, http-equiv, name, and itemprop attributes
cannot be used together within a single <meta> tag. In other words, only one of these attributes can be specified in a single <meta> tag.
charset
This attribute specifies the character encoding of the document.
The value of this attribute is a string type and is case-insensitive.
In HTML5, the value must be specified as utf-8, UTF-8, or another case-insensitive equivalent.
When using the charset attribute in the <meta> tag, use it as a child element of the <head> tag.
<meta charset="utf-8">
http-equiv
his attribute specifies metadata corresponding to HTTP headers. It is mainly used for purposes such as document refresh and cache control.
The possible values of this attribute are specific values that define behavior similar to HTTP headers.
http-equiv attribute
<meta http-equiv="content-security-policy|content-type|default-style|x-ua-compatible|refresh">
When using the http-equiv attribute in the <meta> tag, it must be used only as a child element of the <head> tag.
However, if the value of the http-equiv attribute is not related to encoding (for example, <meta http-equiv="content-type" content="text/html; charset=utf-8">), it can be used as a child element of the <noscript> tag within the <head> tag.
The content attribute is used together with this attribute to specify the metadata value.
http-equiv="content-security-policy"
It is used to define the Content Security Policy (CSP) applied to the document. This security policy controls how the browser loads and executes resources on the web page.
<meta http-equiv="content-security-policy" content="script-src 'self'; object-src 'none'">
For more information about Content Security Policy, refer to MDN - Content-Security-Policy.
http-equiv="content-type"
http-equiv="content-type" represents the MIME type of the document content and the character encoding.
When using http-equiv="content-type", the value of the content attribute must be specified as text/html; charset=utf-8.
Note: It can only be used for documents served as text/html and cannot be used for documents served with an XML MIME type.
<meta http-equiv="content-type" content="text/html; charset=utf-8">
http-equiv="default-style"
It specifies the name of the default CSS style sheet set.
http-equiv="x-ua-compatible"
It is used to specify how a web page should be rendered in a specific version of Internet Explorer.
The Internet Explorer browser is no longer supported.
Therefore, http-equiv="x-ua-compatible" is no longer used.
http-equiv="refresh"
Specifies the time interval for refreshing the document.
This applies only when the value of the accompanying content attribute contains a non-negative integer. The integer represents the time in seconds.
<meta http-equiv="refresh" content="300">
Be careful when using this feature, as refreshing a document too frequently can negatively affect web accessibility.
When the value of the content attribute is a positive integer followed by the string "; url=" and a valid URL, it specifies the time in seconds until the page should be redirected to another page.
<meta http-equiv="refresh" content="3; url=https://example.com">
In the example above, content="3;url=https://example.com/" means that the page will be redirected to https://example.com/ after 3 seconds. In other words, the page automatically moves to the specified URL 3 seconds after it is loaded.
name
The name attribute is used to represent document-level metadata other than metadata represented by the charset, http-equiv, and itemprop attributes. It has the characteristic of specifying metadata as a name-value pair.
The value of this attribute specifies the name of the metadata to use, and the content attribute specifies the value of that metadata. There are standard values included in the specification, non-standard values supported by most browsers, and values used by specific search engines.
In addition, you can specify a custom document-level metadata name as the value of this attribute and use the content attribute to specify the value of that metadata.
<meta name="description" content="This page contains a description.">
In the example above, name="description" indicates that the metadata represents a description of the web page, and the content attribute specifies the actual description.
The name attribute can use standard metadata names for various purposes. For example, metadata such as description can be specified for search engine optimization.
The name attribute plays an important role in defining a web page's metadata and helps platforms such as search engines understand the page information.
itemprop
This attribute is used to provide "custom metadata" at the content item level rather than document-level metadata. The value of this attribute becomes the property name of the custom metadata.
It is added to HTML elements to represent the properties of a specific item and is often used as "custom metadata" to provide semantic information about marked-up content (structured information that can be used by search engines and other services).
In general, the itemprop attribute is used as follows.
<div itemscope itemtype="https://schema.org/Person">
<p>My name is <span itemprop="name">John Smith</span>.</p>
<p>I am <span itemprop="age">30</span> years old.</p>
</div>
In the example above, itemprop="name" indicates that the element represents a person's name, and itemprop="age" indicates that the element represents the person's age. This markup is provided as structured data, helping search engines understand the content and display it appropriately.
The itemprop attribute is commonly used when following structured data standards such as Schema.org. It can help web pages appear more effectively in search results and allow search engines to provide richer information. For more information, see Getting started with schema.org using Microdata.
Other Attributes Related to <meta> Tag Metadata
The Open Graph protocol is used to configure social media sharing previews. When a web page is shared on social media platforms such as Facebook or X (formerly Twitter), a preview image, title, and brief description are displayed along with the link.
This is because social media platforms can correctly recognize and use the metadata defined by the Open Graph protocol, which is inserted inside the HTML <head> tag.
Metadata is defined using the <meta> tag, the property attribute with values that use the og: prefix for metadata names, and the content attribute for metadata values.
<head>
<title>Metadata for a YouTube page shared on Facebook</title>
...
<meta property="og:url" content="https://www.youtube.com">
<meta property="og:title" content="YouTube">
<meta property="og:type" content="website">
<meta property="og:description" content="Enjoy the videos and music you love...">
<meta property="og:image" content="https://www.youtube.com/img/desktop/yt_1200.png">
...
</head>
Technical Summary
| Permitted parents |
|
|---|---|
| Permitted content | None; it is a void element. |
Implicit ARIA role |
No corresponding role |
Permitted ARIA roles |
No role permitted |
Specifications
| Specification | |
|---|---|
<meta>
|
HTML Standard #the-meta-element |
Browser Compatibility
| Tag |
Desktop Chrome
|
Desktop Edge
|
Desktop Firefox
|
Safari
|
|---|---|---|---|---|
<meta>
|
1 | 12 | 1 | 1 |