HTMLMetaElement: content プロパティ

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.

HTMLMetaElement.content プロパティは、HTMLMetaElement.name または HTMLMetaElement.httpEquiv との組み合わせによる、プラグマディレクティブと名前付き <meta> データの content 属性を取得または設定します。 詳しくは、content 属性を参照してください。

文字列です。

meta 要素の内容の読み取り

次の例は name 属性に keywords という値を格納した <meta> 要素を問い合わせるものです。 content の値がコンソールにログ出力され、文書の keywords が表示されます。

js
// <meta name="keywords" content="documentation, HTML, web"> があるとします
let meta = document.querySelector("meta[name='keywords']");
console.log(meta.content);
// "documentation, HTML, web"

内容付きの meta 要素の作成

次の例は、新しい <meta> 要素を name 属性に description に設定して作成します。 content 属性に文書の説明を設定し、文書の <head> に追加されます。

js
let meta = document.createElement("meta");
meta.name = "description";
meta.content =
  "<meta> 要素は、名前と値のペアで文書のメタデータを提供するのに使用できます。name 属性はメタデータの名前を与え、content 属性は値を与えます。";
document.head.appendChild(meta);

仕様書

Specification
HTML
# dom-meta-content

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
content

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報