Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. HTMLMetaElement

HTMLMetaElement

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨July 2015⁩.

TheHTMLMetaElement interface contains descriptive metadata about a document provided in HTML as<meta> elements.This interface inherits all of the properties and methods described in theHTMLElement interface.

EventTarget Node Element HTMLElement HTMLMetaElement

Instance properties

Inherits properties from its parent,HTMLElement.

<meta#charset>

The character encoding for a HTML document.

HTMLMetaElement.content

The 'value' part of the name-value pairs of the document metadata.

HTMLMetaElement.httpEquiv

The name of the pragma directive, the HTTP response header, for a document.

HTMLMetaElement.media

The media context for atheme-color metadata property.

HTMLMetaElement.name

The 'name' part of the name-value pairs defining the named metadata of a document.

HTMLMetaElement.schemeDeprecated

Defines the scheme of the value in theHTMLMetaElement.content attribute.This is deprecated and should not be used on new web pages.

Instance methods

No specific method; inherits methods from its parent,HTMLElement.

Examples

The following two examples show a general approach to using theHTMLMetaElement interface.For specific examples, see the pages for the individual properties as described in theInstance properties section above.

Setting the page description metadata

The following example creates a new<meta> element with aname attribute set todescription.Thecontent attribute sets a description of the document and is appended to the document<head>:

js
const 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);

Setting the viewport metadata

The following example shows how to create a new<meta> element with aname attribute set toviewport.Thecontent attribute sets the viewport size and is appended to the document<head>:

js
const 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<meta name="viewport">.

Specifications

Specification
HTML
# htmlmetaelement

Browser compatibility

See also

  • The HTML element implementing this interface:<meta>

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp