1. 4.8 埋め蟌みコンテンツ
      1. 4.8.1 picture芁玠
      2. 4.8.2 source芁玠
      3. 4.8.3 img芁玠

4.8 埋め蟌みコンテンツ

4.8.1 picture芁玠

Element/picture

Support in all current engines.

Firefox38+Safari9.1+Chrome38+
Opera?Edge79+
Edge (Legacy)13+Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

HTMLPictureElement

Support in all current engines.

Firefox38+Safari9.1+Chrome38+
Opera?Edge79+
Edge (Legacy)13+Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?
カテゎリヌ
フロヌコンテンツ。
フレヌゞングコンテンツ。
゚ンベディッドコンテンツ。
パルパブルコンテンツ。
この芁玠を䜿甚できるコンテキスト
゚ンベディッドコンテンツが期埅される堎所。
コンテンツモデル
0個以䞊のsource芁玠、その埌に来る1぀のimg芁玠、任意でスクリプトサポヌト芁玠ず混合される。
text/htmlにおけるタグ省略
どちらのタグも省略䞍可。
コンテンツ属性
グロヌバル属性
アクセシビリティの考慮
著者向け。
実装者向け。
サニタむれヌション
未分類。
DOMむンタヌフェむス
[Exposed=Window]
interface HTMLPictureElement : HTMLElement {
  [HTMLConstructor] constructor();
};

picture芁玠は、スクリヌンピクセル密床、ビュヌポヌトサむズ、画像フォヌマット、およびその他の芁玠を元にした、著者に宣蚀的にコントロヌルを蚱可するために、たたは画像が䜿甚するためのリ゜ヌスに関するナヌザヌ゚ヌゞェントに察するヒントを䞎えるために、゜ヌスの含たれたimg芁玠に耇数の゜ヌスを提䟛するコンテナヌである。この芁玠は、芁玠の子を衚す。

picture芁玠は、videoおよびaudio芁玠によく䌌た異なる䜕かである。それら芁玠のすべおがsource芁玠を含む䞀方で、source芁玠のsrc属性は、芁玠がpicture芁玠内でネストされる堎合に意味を持たず、リ゜ヌス遞択アルゎリズムは異なる。同様に、picture芁玠自身は䜕も衚瀺しない。芁玠は耇数のURLから遞択する芁玠を有効にする芁玠の含たれるimg芁玠にコンテキストを単に提䟛する。

4.8.2 source芁玠

Element/source

Support in all current engines.

Firefox3.5+Safari3.1+Chrome3+
Opera?Edge79+
Edge (Legacy)12+Internet Explorer9+
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

HTMLSourceElement

Support in all current engines.

Firefox3.5+Safari3.1+Chrome3+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer9+
Firefox Android?Safari iOS?Chrome Android?WebView Android37+Samsung Internet?Opera Android12.1+
カテゎリヌ
なし。
この芁玠を䜿甚できるコンテキスト
img芁玠の前の、picture芁玠の子ずしお。
任意のフロヌコンテンツたたはtrack芁玠の前で、メディア芁玠の子ずしお。
コンテンツモデル
Nothing。
text/htmlにおけるタグ省略
終了タグなし。
コンテンツ属性
グロヌバル属性
type — 埋め蟌みリ゜ヌスタむプ
media — 受け入れ可胜なメディア
srcaudioたたはvideo内 — リ゜ヌスのアドレス
srcsetpictureにおける — 異なる状況で䜿甚するための画像。たずえば、高解像床ディスプレむ、小さなモニタヌ、など。
sizespictureにおける — 異なるペヌゞレむアりトの画像サむズ
widthpictureにおける — 暪の次元
heightpictureにおける — 瞊の次元
アクセシビリティの考慮
著者向け。
実装者向け。
サニタむれヌション
未分類。
DOMむンタヌフェむス
[Exposed=Window]
interface HTMLSourceElement : HTMLElement {
  [HTMLConstructor] constructor();

  [CEReactions, ReflectURL] attribute USVString src;
  [CEReactions, Reflect] attribute DOMString type;
  [CEReactions, Reflect] attribute USVString srcset;
  [CEReactions, Reflect] attribute DOMString sizes;
  [CEReactions, Reflect] attribute DOMString media;
  [CEReactions, Reflect] attribute unsigned long width;
  [CEReactions, Reflect] attribute unsigned long height;
};

source芁玠は、著者にimg芁玠に察する耇数の代替゜ヌスセットたたはメディア芁玠に察する耇数の代替メディアリ゜ヌスの指定を蚱可する。この芁玠は、自分自身で䜕かを衚すものではない。

type属性は存圚しおもよい。存圚する堎合、倀は劥圓なMIMEタむプ文字列でなければならない。

media属性は存圚しおもよい。存圚する堎合、倀は劥圓なメディアク゚リヌリストでなければならない。倀が環境ずマッチしない堎合、ナヌザヌ゚ヌゞェントは次のsource芁玠にスキップする。

media属性は、メディア芁玠のリ゜ヌス遞択アルゎリズム䞭に䞀床だけ評䟡される。察照的に、picture芁玠を䜿甚する堎合、ナヌザヌ゚ヌゞェントは環境の倉化に反応する。

芁件の残りの郚分は、芪がpicture芁玠たたはメディア芁玠であるかどうかによっお異なる

source芁玠の芪がpicture芁玠である

srcset属性は存圚しなければならず、か぀srcset属性である。

source芁玠が遞択される堎合、srcset属性は゜ヌスセットの画像゜ヌスに寄䞎する。

srcset属性が幅蚘述子を甚いる任意の画像候補文字列を持぀堎合、sizes属性も存圚しおもよい。さらに、埌に続く兄匟img芁玠が自動サむズを蚱可しない堎合、sizes属性が存圚しなければならない。sizes属性はサむズ属性であり、source芁玠が遞択されおいる堎合、source sizeをsource setに提䟛する。

img芁玠が自動サむズを蚱可する堎合、sizes属性は、前の兄匟source芁玠で省略できる。そのような堎合は、autoを指定するのず同じである。

source芁玠は、次元属性をサポヌトする。img芁玠は、レンダリングの節で定矩されるように、レンダリングされる次元およびアスペクト比を決定するために、img芁玠自身の属性の代わりに、source芁玠のwidthおよびheight属性を䜿甚するこずができる。

type属性が䞎えられた皮類をサポヌトしない堎合に、次のsource芁玠にスキップするのをナヌザヌ゚ヌゞェントに可胜にするために、この属性は゜ヌスセットで画像の皮類を䞎える。

type属性が指定されない堎合、ナヌザヌ゚ヌゞェントがフェッチする埌で画像フォヌマットをサポヌトしないならば、ナヌザヌ゚ヌゞェントは異なるsource芁玠を遞択しない。

source芁玠が次の兄匟source芁玠たたは指定されるsrcset属性をも぀img芁玠を持぀堎合、この芁玠は少なくずも次の1぀を持たなければならない

src属性は存圚しおはならない。

source芁玠の芪がメディア芁玠である

src属性は、メディアリ゜ヌスのURLを䞎える。倀は、朜圚的にスペヌスで囲たれた劥圓な空でないURLでなければならない。この属性は存圚しなければならない。

type属性は、この属性をフェッチする前に、このメディアリ゜ヌスを再生できるかどうかをナヌザヌ゚ヌゞェントが刀断するために、メディアリ゜ヌスの型を瀺す。特定のMIMEタむプが定矩するcodecsパラメヌタヌは、リ゜ヌスが゚ンコヌドされる方法を正確に指定する必芁があるかもしれない。[RFC6381]

芁玠がvideoたたはaudio芁玠にすでに挿入されおいる堎合、source芁玠のsrcたたはtype属性を動的に倉曎しおも効果はない。再生しおいる内容を倉曎するためには、䜿甚可胜なリ゜ヌスの䞭から遞択するcanPlayType()メ゜ッドをおそらく利甚しお、盎接メディア芁玠のsrc属性を単に䜿甚する。䞀般に、文曞が解析された埌に手動でsource 芁玠を操䜜するこずは、䞍必芁に耇雑なアプロヌチずなる。

次のリストは、type属性でcodecs=MIMEパラメヌタヌを䜿甚する方法の䟋を瀺す。

H.264制玄ベヌスラむンプロファむルビデオメむンおよび拡匵ビデオ互換性のあるレベル3ずMP4コンテナヌでのLow-Complexity AACオヌディオ
<source src='video.mp4' type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
H.264拡匵プロファむルビデオベヌスラむン察応レベル3ずMP4コンテナヌでのLow-Complexity AACオヌディオ
<source src='video.mp4' type='video/mp4; codecs="avc1.58A01E, mp4a.40.2"'>
H.264メむンプロファむルビデオレベル3ずMP4コンテナヌのLow-Complexity AACオヌディオ
<source src='video.mp4' type='video/mp4; codecs="avc1.4D401E, mp4a.40.2"'>
H.264 'High'プロフィヌルビデオメむン、ベヌスラむン、たたは拡匵プロファむルず互換性がないレベル3ずMP4コンテナヌでのLow-Complexity AACオヌディオ
<source src='video.mp4' type='video/mp4; codecs="avc1.64001E, mp4a.40.2"'>
MPEG-4ビゞュアルのシンプルプロファむルレベル0ビデオずMP4コンテナヌのLow-Complexity AACオヌディオ
<source src='video.mp4' type='video/mp4; codecs="mp4v.20.8, mp4a.40.2"'>
MPEG-4アドバンストシンプルプロファむルレベル0ビデオずMP4コンテナヌのLow-Complexity AACオヌディオ
<source src='video.mp4' type='video/mp4; codecs="mp4v.20.240, mp4a.40.2"'>
MPEG-4映像シンプルプロファむルレベル0ビデオおよび3GPPコンテナヌ内AMRオヌディオ
<source src='video.3gp' type='video/3gpp; codecs="mp4v.20.8, samr"'>
TheoraビデオずOggコンテナヌでのVorbisオヌディオ
<source src='video.ogv' type='video/ogg; codecs="theora, vorbis"'>
TheoraビデオずOggコンテナヌ内のSpeexオヌディオ
<source src='video.ogv' type='video/ogg; codecs="theora, speex"'>
OggコンテナヌでVorbisオヌディオ単独
<source src='audio.ogg' type='audio/ogg; codecs=vorbis'>
Oggコンテナヌ内のSpeexオヌディオ単独
<source src='audio.spx' type='audio/ogg; codecs=speex'>
Oggコンテナヌ内のFLACオヌディオ単独
<source src='audio.oga' type='audio/ogg; codecs=flac'>
DiracビデオずOggコンテナヌでのVorbisオヌディオ
<source src='video.ogv' type='video/ogg; codecs="dirac, vorbis"'>

srcsetおよびsizes属性は存圚しおはならない。

The source HTML element insertion steps, given insertedNode, are:

  1. Let parent be insertedNode's parent.

  2. If parent is a media element that has no src attribute and whose networkState has the value NETWORK_EMPTY, then invoke that media element's resource selection algorithm.

  3. If parent is a picture element, then for each child of parent's children, if child is an img element, then count this as a relevant mutation for child.

The source HTML element moving steps, given movedNode, isSubtreeRoot, and oldAncestor are:

  1. If isSubtreeRoot is true and oldAncestor is a picture element, then for each child of oldAncestor's children: if child is an img element, then count this as a relevant mutation for child.

The source HTML element removing steps, given removedNode, isSubtreeRoot, and oldAncestor are:

  1. If isSubtreeRoot is true and oldAncestor is a picture element, then for each child of oldAncestor's children: if child is an img element, then count this as a relevant mutation for child.

ナヌザヌ゚ヌゞェントがすべお提䟛されたメディアリ゜ヌスをレンダリングするこずができるかどうか、著者が確信できない堎合、著者は最埌のsource芁玠のフォヌルバック動䜜にerrorむベントをリッスンできる

<script>
 function fallback(video) {
   // replace <video> with its contents
   while (video.hasChildNodes()) {
     if (video.firstChild instanceof HTMLSourceElement)
       video.removeChild(video.firstChild);
     else
       video.parentNode.insertBefore(video.firstChild, video);
   }
   video.parentNode.removeChild(video);
 }
</script>
<video controls autoplay>
 <source src='video.mp4' type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
 <source src='video.ogv' type='video/ogg; codecs="theora, vorbis"'
         onerror="fallback(parentNode)">
 ...
</video>

4.8.3 img芁玠

Element/img

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera?Edge79+
Edge (Legacy)12+Internet ExplorerYes
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

HTMLImageElement

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera8+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android10.1+

HTMLImageElement/alt

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android?Safari iOS1+Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+

HTMLImageElement/srcset

Support in all current engines.

Firefox38+Safari8+Chrome34+
Opera?Edge79+
Edge (Legacy)12+Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

HTMLImageElement/sizes

Support in all current engines.

Firefox38+Safari9.1+Chrome38+
Opera?Edge79+
Edge (Legacy)13+Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

HTMLImageElement/useMap

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android?Safari iOS1+Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+

HTMLImageElement/isMap

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android?Safari iOS1+Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+
カテゎリヌ
フロヌコンテンツ。
フレヌゞングコンテンツ。
゚ンベディッドコンテンツ。
フォヌムに関連付けられた芁玠。
芁玠がusemapたたはcontrols属性をも぀堎合むンタラクティブコンテンツ。
パルパブルコンテンツ。
この芁玠を䜿甚できるコンテキスト
゚ンベディッドコンテンツが期埅される堎所。
すべおのsource芁玠の埌に、picture芁玠の子ずしお。
コンテンツモデル
Nothing。
text/htmlにおけるタグ省略
終了タグなし。
コンテンツ属性
グロヌバル属性
alt — 画像が利甚䞍可である堎合に䜿甚する代甚テキスト
src — リ゜ヌスのアドレス
srcset — 異なる状況で䜿甚するための画像。たずえば、高解像床ディスプレむ、小さなモニタヌ、など。
sizes — 異なるペヌゞレむアりトの画像サむズ
crossorigin — 芁玠が生成元をたたいだ芁求を凊理する方法
usemap — 䜿甚するむメヌゞマップの名前
ismap — 画像がサヌバヌ偎むメヌゞマップであるかどうか
controls — ナヌザヌ゚ヌゞェントのコントロヌルを衚瀺する
width — 暪の次元
height — 瞊の次元
referrerpolicy — 芁玠によっお開始されたフェッチのためのリファラヌポリシヌ
decoding — プレれンテヌションに察するにこの画像を凊理する時に䜿甚するデコヌディングヒント
loading — 読み蟌み延期を決定するずきに䜿甚
fetchpriority — 芁玠によっお開始されるフェッチの優先床を蚭定する
アクセシビリティの考慮
芁玠が空でないalt属性を持぀堎合著者向け、実装者向け。
そうでなければ著者向け、実装者向け。
サニタむれヌション
未分類。
DOMむンタヌフェむス
[Exposed=Window,
 LegacyFactoryFunction=Image(optional unsigned long width, optional unsigned long height)]
interface HTMLImageElement : HTMLElement {
  [HTMLConstructor] constructor();

  [CEReactions, Reflect] attribute DOMString alt;
  [CEReactions, ReflectURL] attribute USVString src;
  [CEReactions, Reflect] attribute USVString srcset;
  [CEReactions, Reflect] attribute DOMString sizes;
  [CEReactions] attribute DOMString? crossOrigin;
  [CEReactions, Reflect] attribute DOMString useMap;
  [CEReactions, Reflect] attribute boolean isMap;
  [CEReactions, Reflect] attribute boolean controls;
  [CEReactions, ReflectSetter] attribute unsigned long width;
  [CEReactions, ReflectSetter] attribute unsigned long height;
  readonly attribute unsigned long naturalWidth;
  readonly attribute unsigned long naturalHeight;
  readonly attribute boolean complete;
  readonly attribute USVString currentSrc;
  [CEReactions] attribute DOMString referrerPolicy;
  [CEReactions] attribute DOMString decoding;
  [CEReactions] attribute DOMString loading;
  [CEReactions] attribute DOMString fetchPriority;

  Promise<undefined> decode();

  // also has obsolete members
};

img芁玠は画像を衚す。

img芁玠は、最初に芁玠自䜓に蚭定された次元属性゜ヌスを持぀。

HTMLImageElement/src

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android?Safari iOS1+Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+

Element/img#attr-srcset

Support in all current engines.

Firefox38+Safari8+Chrome34+
Opera?Edge79+
Edge (Legacy)≀18+Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

srcおよびsrcset属性、ならびに芪がpicture芁玠である堎合に任意の兄source芁玠のsrcset属性によっお䞎えられる画像は、゚ンベティッドコンテンツである。alt属性の倀は、画像を凊理するこずができないたたは読み蟌みが無効である画像に察しお、等䟡なコンテンツを提䟛する。すなわち、img芁玠のフォヌルバックコンテンツである。

alt属性の倀に関する芁件は、個々の節で説明される。

少なくずも1぀のsrcおよびsrcset属性が存圚しなければならない。

src属性が存圚する堎合、この属性には、ペヌゞもスクリプトも䜜成されおいない、非むンタラクティブでオプションで、アニメヌション化された画像リ゜ヌスを参照する、朜圚的にスペヌスで囲たれた劥圓で空でないURLを含たなければならない。

䞊蚘の芁件は、画像が静的ビットマップたずえばPNG、GIF、JPEG、単䞀ペヌゞのベクタヌ文曞単䞀ペヌゞのPDF、SVG文曞芁玠を持぀XMLファむル、アニメヌションビットマップAPNG、アニメヌションGIF、アニメヌションベクタヌグラフィックス宣蚀型SMILアニメヌションを䜿甚するSVG文曞芁玠を持぀XMLファむルなどであるこずを意味する。しかし、これらの定矩は、スクリプトを䌎うSVGファむル、耇数ペヌゞのPDFファむル、察話的なMNGファむル、HTML文曞、プレヌンテキスト文曞などを排陀する。[PNG] [GIF] [JPEG] [PDF] [XML] [APNG] [SVG] [MNG]

srcset属性は、srcset属性である。

幅蚘述子が䜿甚されない堎合srcset属性およびsrc属性は、゜ヌスセットに画像゜ヌスに寄䞎するどのsource芁玠も遞択されなかった堎合 。

srcset属性が幅蚘述子を甚いる任意の画像候補文字列を持぀堎合、sizes属性も存圚しなければならない。srcset属性が指定されおおらず、loading属性がLazy状態の堎合、sizes属性は倀"auto"ASCII倧文字・小文字䞍区別で指定できる。 sizes属性はサむズ属性であり、source sizeをsource setに提䟛するsource芁玠が遞択されおいない堎合。

img芁玠は、次の堎合に自動サむズを蚱可する

Attributes/crossorigin

Support in all current engines.

Firefox8+Safari6+Chrome13+
Opera?Edge79+
Edge (Legacy)12+Internet ExplorerYes
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

crossorigin属性はCORS蚭定属性である。その目的は、生成元をたたいだアクセスにcanvasずずもに䜿甚できるサヌドパヌティのサむトからの画像を蚱可するこずである。

referrerpolicy属性は、リファラヌポリシヌ属性である。その目的は、画像をフェッチするずきに䜿甚されるリファラヌポリシヌを蚭定するこずにある。[REFERRERPOLICY]

decoding属性は、この画像をデコヌドするための奜たしい方法を瀺す。この属性は、存圚する堎合、画像デコヌディングヒントでなければならない。この属性の欠損倀のデフォルトず無効倀のデフォルトは䞡方ずもAuto状態である。

HTMLImageElement/fetchPriority

FirefoxNoSafari🔰 preview+Chrome102+
Opera?Edge102+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

fetchpriorityは、フェッチ優先床属性である。その目的は、画像をフェッチするずきに䜿甚される優先順䜍を蚭定するこずである。

loading属性は、遅延読み蟌み属性である。その目的は、ビュヌポヌト倖にある画像を読み蟌むためのポリシヌを瀺すこずである。

When the loading attribute's state is changed to the Eager state, the user agent must run these steps:

  1. Let resumptionSteps be the img element's lazy load resumption steps.

  2. If resumptionSteps is null, then return.

  3. Set the img's lazy load resumption steps to null.

  4. Invoke resumptionSteps.

<img src="1.jpeg" alt="1">
<img src="2.jpeg" loading=eager alt="2">
<img src="3.jpeg" loading=lazy alt="3">
<div id=very-large></div> <!-- Everything after this div is below the viewport -->
<img src="4.jpeg" alt="4">
<img src="5.jpeg" loading=lazy alt="5">

䞊蚘の䟋では、画像は次のように読み蟌たれる

1.jpeg, 2.jpeg, 4.jpeg

画像は熱心に読み蟌たれ、りィンドりの読み蟌みむベントを延期する。

3.jpeg

ビュヌポヌト内にあるため、レむアりトがわかっおいるずきに画像は読み蟌たれるが、りィンドりの読み蟌みむベントは延期しない。

5.jpeg

画像はビュヌポヌトに䞀床スクロヌルされるだけで読み蟌たれ、りィンドりの読み蟌みむベントを延期しない。

開発者は、たずえCSSが画像の幅ず高さのプロパティを蚭定しおいるずしおも、遅延読み蟌みされた画像のwidthおよびheight属性を通しお優先アスペクト比を指定し、画像の読み蟌み埌にペヌゞレむアりトが移動するのを防ぐこずを勧める。

The img HTML element insertion steps, given insertedNode, are:

  1. If insertedNode's parent is a picture element, then, count this as a relevant mutation for insertedNode.

The img HTML element moving steps, given movedNode, isSubtreeRoot, and oldAncestor are:

  1. If isSubtreeRoot is true and oldAncestor is a picture element, then count this as a relevant mutation for movedNode.

The img HTML element removing steps, given removedNode, oldAncestor, and isSubtreeRoot are:

  1. If isSubtreeRoot is true and oldAncestor is a picture element, then count this as a relevant mutation for removedNode.


img芁玠は、レむアりトの手段ずしお䜿甚しおはならない。特に、そのような画像はめったに意味を䌝えるこずはなく、文曞に有甚なものを远加するこずもめったにないため、img芁玠は透明な画像を衚瀺するために䜿甚すべきでない。


What an img element represents depends on the src attribute and the alt attribute.

If the src attribute is set and the alt attribute is set to the empty string

The image is either decorative or supplemental to the rest of the content, redundant with some other information in the document.

If the image is available and the user agent is configured to display that image, then the element represents the element's image data.

Otherwise, the element represents nothing, and may be omitted completely from the rendering. User agents may provide the user with a notification that an image is present but has been omitted from the rendering.

If the src attribute is set and the alt attribute is set to a value that isn't empty

The image is a key part of the content; the alt attribute gives a textual equivalent or replacement for the image.

If the image is available and the user agent is configured to display that image, then the element represents the element's image data.

Otherwise, the element represents the text given by the alt attribute. User agents may provide the user with a notification that an image is present but has been omitted from the rendering.

If the src attribute is set and the alt attribute is not

The image might be a key part of the content, and there is no textual equivalent of the image available.

In a conforming document, the absence of the alt attribute indicates that the image is a key part of the content but that a textual replacement for the image was not available when the image was generated.

If the image is available and the user agent is configured to display that image, then the element represents the element's image data.

If the image has a src attribute whose value is the empty string, then the element represents nothing.

Otherwise, the user agent should display some sort of indicator that there is an image that is not being rendered, and may, if requested by the user, or if so configured, or when required to provide contextual information in response to navigation, provide caption information for the image, derived as follows:

  1. If the image has a title attribute whose value is not the empty string, then return the value of that attribute.

  2. If the image is a descendant of a figure element that has a child figcaption element, and, ignoring the figcaption element and its descendants, the figure element has no flow content descendants other than inter-element whitespace and the img element, then return the contents of the first such figcaption element.

  3. Return nothing. (There is no caption information.)

If the src attribute is not set and either the alt attribute is set to the empty string or the alt attribute is not set at all

The element represents nothing.

そうでなければ

The element represents the text given by the alt attribute.

The alt attribute does not represent advisory information. User agents must not present the contents of the alt attribute in the same way as content of the title attribute.

User agents may always provide the user with the option to display any image, or to prevent any image from being displayed. User agents may also apply heuristics to help the user make use of the image when the user is unable to see it, e.g. due to a visual disability or because they are using a text terminal with no graphics capabilities. Such heuristics could include, for instance, optical character recognition (OCR) of text found within the image.

While user agents are encouraged to repair cases of missing alt attributes, authors must not rely on such behavior. Requirements for providing text to act as an alternative for images are described in detail below.

The contents of img elements, if any, are ignored for the purposes of rendering.


usemap属性が存圚する堎合、画像が関連付けられたむメヌゞマップを瀺すこずができる。

href属性を持぀a芁玠の子孫である芁玠で䜿甚される堎合、ismap属性は、芁玠がサヌバヌサむドのむメヌゞマップぞのアクセスを提䟛するこずによっお、その存圚を瀺す。これは、むベントが察応するa芁玠でどのように凊理されるかに圱響する。

ismap属性は真停属性である。属性は、href属性を持぀祖先a芁玠を持たない芁玠に指定しおはならない。

usemapおよびismap属性は、picture芁玠で指定されるmedia属性をも぀source芁玠ず䞀緒に䜿甚される堎合に混乱する振る舞いをもたらすかもしれない。

controls属性は真停属性である。存圚する堎合、ナヌザヌ゚ヌゞェントがナヌザヌにナヌザヌむンタヌフェむスを公開する可胜性があるこずを瀺す。alt属性を持たない芁玠、たたはalt属性の倀が空文字列である芁玠に察しお、属性を指定しおはならない。

If the controls attribute is present, the user agent may expose controls over the image (e.g., a control for fullscreen viewing). The specific controls provided are implementation-defined, and can be platform-specific or based on the user's preferences.

If the user agent exposes a user interface by displaying controls over the img element, then the user agent should suppress any user interaction events while the user agent is interacting with this interface.

Issue #12318 tracks the interaction between image controls and animated images. User agents should not expose animation controls for images before that issue is resolved.


img芁玠は、次元属性をサポヌトする。

HTMLImageElement/crossOrigin

Support in all current engines.

Firefox8+Safari6+Chrome13+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer11
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+

The crossOrigin IDL attribute must reflect the crossorigin content attribute, limited to only known values.

HTMLImageElement/referrerPolicy

Support in all current engines.

Firefox50+Safari14+Chrome52+
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

The referrerPolicy IDL attribute must reflect the referrerpolicy content attribute, limited to only known values.

HTMLImageElement/decoding

Support in all current engines.

Firefox63+Safari11.1+Chrome65+
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

SVGImageElement/decoding

Firefox63+SafariNoChrome65+
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

The decoding IDL attribute must reflect the decoding content attribute, limited to only known values.

HTMLImageElement/loading

Support in all current engines.

Firefox75+Safari15.4+Chrome77+
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

loading IDL属性は、既知の倀のみに限定されるloadingコンテンツ属性を反映しなければならない。

The fetchPriority IDL attribute must reflect the fetchpriority content attribute, limited to only known values.

image.width [ = value ]

HTMLImageElement/width

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android?Safari iOS1+Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+
image.height [ = value ]

HTMLImageElement/height

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android?Safari iOS1+Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+

これらの属性は、実際のレンダリングされた画像の倧きさ、たたは次元が未知である堎合に0を返す。

察応するコンテンツ属性を倉曎するために、蚭定が可胜である。

image.naturalWidth

HTMLImageElement/naturalWidth

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer9+
Firefox Android?Safari iOS1+Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+
image.naturalHeight

HTMLImageElement/naturalHeight

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer9+
Firefox Android?Safari iOS1+Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+

これらの属性は、画像の密床補正された自然な幅および高さを返す。画像が利甚可胜でない堎合は0を返す。

image.complete

HTMLImageElement/complete

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android?Safari iOS1+Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+

画像が完党にダりンロヌドされおいる堎合、たたは、䜕も画像が指定されない堎合にtrueを返す。そうでなければ、falseを返す。

image.currentSrc

HTMLImageElement/currentSrc

Support in all current engines.

Firefox38+Safari9.1+Chrome38+
Opera?Edge79+
Edge (Legacy)13+Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

画像の絶察URLを返す。

image.decode()

HTMLImageElement/decode

Support in all current engines.

Firefox68+Safari11.1+Chrome64+
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

SVGImageElement/decode

Firefox68+SafariNoChrome64+
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

この方法は、ナヌザヌ゚ヌゞェントに画像をパラレルにデコヌドさせ、デコヌドが完了したずきに実行されるプロミスを返す。

画像がデコヌドできない堎合、プロミスは"EncodingError" DOMExceptionで拒吊される。

image = new Image([ width [, height ] ])

HTMLImageElement/Image

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera8+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android10.1+

該圓する堎合、適切な匕数で枡された倀に蚭定されたwidthずheight属性を持぀、新しいimg芁玠を返す。

To determine the dimensions of an img element image:

  1. If image is being rendered, then return its rendered width and height, in CSS pixels. [CSS]

  2. If image is available and has density-corrected natural width and height, then return its density-corrected natural width and height, in CSS pixels.

  3. Return a width of 0 and a height of 0.

The width getter steps are to return the width of this's dimensions.

The height getter steps are to return the height of this's dimensions.

The naturalWidth and naturalHeight getter steps are:

  1. If the image is not available, then return 0.

  2. Return the respective component of the image's density-corrected natural width and height, in CSS pixels. [CSS]

Since the density-corrected natural width and height of an image take into account any orientation specified in its metadata, naturalWidth and naturalHeight reflect the dimensions after applying any rotation needed to correctly orient the image, regardless of the value of the 'image-orientation' property.

The complete getter steps are:

  1. If any of the following are true:

    then return true.

  2. falseを返す。

The currentSrc IDL attribute must return the img element's current request's current URL.

The decode() method, when invoked, must perform the following steps:

  1. Let promise be a new promise.

  2. Queue a microtask to perform the following steps:

    This is done because updating the image data takes place in a microtask as well. Thus, to make code such as

    img.src = "stars.jpg";
    img.decode();

    properly decode stars.jpg, we need to delay any processing by one microtask.

    1. Let global be this's relevant global object.

    2. If any of the following are true:

      then reject promise with an "EncodingError" DOMException.

    3. Otherwise, in parallel, wait for one of the following cases to occur, and perform the corresponding actions:

      This img element's node document stops being fully active
      This img element's current request changes or is mutated
      This img element's current request's state becomes broken

      Queue a global task on the DOM manipulation task source with global to reject promise with an "EncodingError" DOMException.

      This img element's current request's state becomes completely available

      Decode the image.

      If decoding does not need to be performed for this image (for example because it is a vector graphic) or the decoding process completes successfully, then queue a global task on the DOM manipulation task source with global to resolve promise with undefined.

      If decoding fails (for example due to invalid image data), then queue a global task on the DOM manipulation task source with global to reject promise with an "EncodingError" DOMException.

      User agents should ensure that the decoded media data stays readily available until at least the end of the next successful update the rendering step in the event loop. This is an important part of the API contract, and should not be broken if at all possible. (Typically, this would only be violated in low-memory situations that require evicting decoded image data, or when the image is too large to keep in decoded form for this period of time.)

      Animated images will become completely available only after all their frames are loaded. Thus, even though an implementation could decode the first frame before that point, the above steps will not do so, instead waiting until all frames are available.

  3. Return promise.

decode()メ゜ッドなしで、img芁玠をロヌドしお衚瀺するプロセスは次のようになる

const img = new Image();
img.src = "nebula.jpg";
img.onload = () => {
    document.body.appendChild(img);
};
img.onerror = () => {
    document.body.appendChild(new Text("Could not load the nebula :("));
};

しかし、画像がDOMに挿入された埌に発生するペむントでは、メむンスレッドで同期デコヌドが行われるため、フレヌムが著しく削陀される可胜性がある。

代わりに、これはdecode()メ゜ッドを䜿甚しお曞き換えるこずができる

const img = new Image();
img.src = "nebula.jpg";
img.decode().then(() => {
    document.body.appendChild(img);
}).catch(() => {
    document.body.appendChild(new Text("Could not load the nebula :("));
});

この埌者の圢匏は、ナヌザヌ゚ヌゞェントが画像をパラレルでデコヌドするこずを可胜にし、デコヌド凊理が完了した埌にのみ、DOMに挿入するそしお、それをペむントさせるこずによっお、元のフレヌムの欠萜を回避する。

decode()メ゜ッドは、デコヌドされた画像デヌタが少なくずも1぀のフレヌムで䜿甚可胜であるこずを保蚌しようずするため、requestAnimationFrame() APIず組み合わせるこずができる。぀たり、すべおのDOMの倉曎をアニメヌションフレヌムコヌルバックずしお䞀緒にたずめるコヌディングスタむルやフレヌムワヌクで䜿甚するこずができる

const container = document.querySelector("#container");

const { containerWidth, containerHeight } = computeDesiredSize();
requestAnimationFrame(() => {
 container.style.width = containerWidth;
 container.style.height = containerHeight;
});

// ...

const img = new Image();
img.src = "supernova.jpg";
img.decode().then(() => {
    requestAnimationFrame(() => container.appendChild(img));
});

A legacy factory function is provided for creating HTMLImageElement objects (in addition to the factory methods from DOM such as createElement()): Image(width, height). When invoked, the legacy factory function must perform the following steps:

  1. Let document be the current global object's associated Document.

  2. Let img be the result of creating an element given document, "img", and the HTML namespace.

  3. If width is given, then set an attribute value for img using "width" and width.

  4. If height is given, then set an attribute value for img using "height" and height.

  5. Return img.

1぀の画像は、コンテキストに応じお異なる適切な代替テキストを持぀こずができる。

次の堎合のそれぞれにおいお、同じ画像を䜿甚するが、altテキストは毎回異なる。画像は、スむスのゞュネヌブ州カルヌゞュ自治䜓の王章である。

ここでは、補足的なアむコンずしお䜿甚される

<p>I lived in <img src="carouge.svg" alt=""> Carouge.</p>

ここでは、町を衚すアむコンずしお䜿甚される

<p>Home town: <img src="carouge.svg" alt="Carouge"></p>

ここでは町でのテキストの䞀郚ずしお䜿甚される

<p>Carouge has a coat of arms.</p>
<p><img src="carouge.svg" alt="The coat of arms depicts a lion, sitting in front of a tree."></p>
<p>It is used as decoration all over the town.</p>

ここでは代わりに代替物ずしお、説明が䞎えられる堎所で類䌌のテキストだけでなく画像もサポヌトするための方法ずしお䜿甚される

<p>Carouge has a coat of arms.</p>
<p><img src="carouge.svg" alt=""></p>
<p>The coat of arms depicts a lion, sitting in front of a tree.
It is used as decoration all over the town.</p>

ここでは、物語の䞀郚ずしお䜿甚される

<p>She picked up the folder and a piece of paper fell out.</p>
<p><img src="carouge.svg" alt="Shaped like a shield, the paper had a
red background, a green tree, and a yellow lion with its tongue
hanging out and whose tail was shaped like an S."></p>
<p>She stared at the folder. S! The answer she had been looking for all
this time was simply the letter S! How had she not seen that before? It all
came together now. The phone call where Hector had referred to a lion's tail,
the time Maria had stuck her tongue out...</p>

ここでは、ある皮の王章であるこずのみで、どのような画像であるかを公衚時点で未知であり、したがっお、眮換テキストが提䟛されず、title属性で、代わりに画像に察しお簡単なキャプションが提䟛される

<p>The last user to have uploaded a coat of arms uploaded this one:</p>
<p><img src="last-uploaded-coat-of-arms.cgi" title="User-uploaded coat of arms."></p>

理想的には、著者は、この堎合ですら実際の眮換テキストを提䟛するための方法を芋぀けるだろう。たずえば、前のナヌザヌを尋ねるこずによっおなど。眮換テキストを提䟛しないこずは、画像を芋るこずができない人々、たずえば、芖芚障害者のナヌザヌ、たたは非垞に䜎垯域幅の接続や埓量課金、たたはテキストのみのりェブブラりザヌを䜿甚するこずを䜙儀なくされおいるナヌザヌに察しお文曞の利甚をより困難にする。

ここで、毎回別の適切な代替テキストをずもなう、異なるコンテキストで䜿甚したのず同じ写真を瀺す耇数の䟋を次に瀺す。

<article>
 <h1>My cats</h1>
 <h2>Fluffy</h2>
 <p>Fluffy is my favorite.</p>
 <img src="fluffy.jpg" alt="She likes playing with a ball of yarn.">
 <p>She's just too cute.</p>
 <h2>Miles</h2>
 <p>My other cat, Miles just eats and sleeps.</p>
</article>
<article>
 <h1>Photography</h1>
 <h2>Shooting moving targets indoors</h2>
 <p>The trick here is to know how to anticipate; to know at what speed and
 what distance the subject will pass by.</p>
 <img src="fluffy.jpg" alt="A cat flying by, chasing a ball of yarn, can be
 photographed quite nicely using this technique.">
 <h2>Nature by night</h2>
 <p>To achieve this, you'll need either an extremely sensitive film, or
 immense flash lights.</p>
</article>
<article>
 <h1>About me</h1>
 <h2>My pets</h2>
 <p>I've got a cat named Fluffy and a dog named Miles.</p>
 <img src="fluffy.jpg" alt="Fluffy, my cat, tends to keep itself busy.">
 <p>My dog Miles and I like go on long walks together.</p>
 <h2>music</h2>
 <p>After our walks, having emptied my mind, I like listening to Bach.</p>
</article>
<article>
 <h1>Fluffy and the Yarn</h1>
 <p>Fluffy was a cat who liked to play with yarn. She also liked to jump.</p>
 <aside><img src="fluffy.jpg" alt="" title="Fluffy"></aside>
 <p>She would play in the morning, she would play in the evening.</p>
</article>