The HTMLMetaElement interface contains descriptive metadata about a document provided in HTML as <meta> elements. This interface inherits all of the properties and methods described in the HTMLElement interface.
The HTMLMetaElement interface contains descriptive metadata about a document provided in HTML as <meta> elements. This interface inherits all of the properties and methods described in the HTMLElement interface.
Inherits properties from its parent, HTMLElement.
HTMLMetaElement.charsetThe character encoding for a HTML document.
HTMLMetaElement.contentThe 'value' part of the name-value pairs of the document metadata.
HTMLMetaElement.httpEquivThe name of the pragma directive, the HTTP response header, for a document.
HTMLMetaElement.mediaThe media context for a theme-color metadata property.
HTMLMetaElement.nameThe 'name' part of the name-value pairs defining the named metadata of a document.
HTMLMetaElement.scheme Deprecated
Defines the scheme of the value in the HTMLMetaElement.content attribute. This is deprecated and should not be used on new web pages.
No specific method; inherits methods from its parent, HTMLElement.
The following two examples show a general approach to using the HTMLMetaElement interface. For specific examples, see the pages for the individual properties as described in the Instance properties section above.
The following example creates a new <meta> element with a name attribute set to description. The content attribute sets a description of the document and is appended to the document <head>:
js
let meta = document.createElement("meta"); meta.name = "description"; meta.content = "The <meta> element can be used to provide document metadata in terms of name-value pairs, with the name attribute giving the metadata name, and the content attribute giving the value."; document.head.appendChild(meta);
The following example shows how to create a new <meta> element with a name attribute set to viewport. The content attribute sets the viewport size and is appended to the document <head>:
js
var meta = document.createElement("meta"); meta.name = "viewport"; meta.content = "width=device-width, initial-scale=1"; document.head.appendChild(meta);
For more information on setting the viewport, see Viewport basics.
| Specification |
|---|
| HTML Standard # htmlmetaelement |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
HTMLMetaElement |
1 | 12 | 1 | 5.5 | ≤12.1 | 1 | 4.4 | 18 | 4 | ≤12.1 | 1 | 1.0 |
content |
1 | 12 | 1 | 5.5 | ≤12.1 | 1 | 4.4 | 18 | 4 | ≤12.1 | 1 | 1.0 |
httpEquiv |
1 | 12 | 1 | 5.5 | ≤12.1 | 1 | 4.4 | 18 | 4 | ≤12.1 | 1 | 1.0 |
media |
93 | 93 | 106 | No | 79 | 15 | 93 | 93 | 106 | 66 | 15 | 17.0 |
name |
1 | 12 | 1 | 5.5 | ≤12.1 | 1 | 4.4 | 18 | 4 | ≤12.1 | 1 | 1.0 |
scheme |
1 | 12 | 1 | 6 | ≤12.1 | 1 | 4.4 | 18 | 4 | ≤12.1 | 1 | 1.0 |
<meta>
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLMetaElement