HTMLAnchorElement: hreflang プロパティ

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.

hreflangHTMLAnchorElement インターフェイスのプロパティで、リンクされたソースの言語の文字列です。

<a> 要素の hreflang 属性を反映し、hreflang 要素がない場合は空文字列 ("") となります。

ウェブブラウザーや検索エンジンは、リンク先のコンテンツの言語をより正確に理解するためにこの情報を使用することがありますが、従うことで義務付けられているわけではありません。hreflang 属性に提供された値は、RFC 5646: Tags for Identifying Languages(別名 BCP 47)で定義されている形式に従います。 そうでない場合は、無視されます。

ウェブブラウザーは、リンク先のリソースを取得した後、hreflang 属性だけに頼っているわけではありません。代わりに、リソースに直接関連付けられた言語情報(例えば、HTTP ヘッダーを通じて)を使用して、その言語を決定します。

言語タグを収めた文字列、または hreflang 要素がない場合は空文字列 ("") です。

html
<a id="exampleLink" href="https://example.com" hreflang="en-IN">Example Link</a>
<p class="hreflang"></p>
css
#exampleLink {
  font-size: 1.5rem;
}
js
const anchorElement = document.getElementById("exampleLink");
const pTag = document.querySelector(".hreflang");
console.log(anchorElement.hreflang); // Outputs: "en-IN"
pTag.textContent = anchorElement.hreflang;

結果

仕様書

Specification
HTML
# dom-a-hreflang

ブラウザーの互換性

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
hreflang

Legend

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

Full support
Full support

関連情報