メインコンテンツへスキップ

img要素


1.仕様

IMG要素は、
画像を表します。

img

画像埋め込み (Embedded image)

種類
空要素

任意のコンテンツを持つことができない要素です。

カテゴリ
  • フローコンテンツ
  • フレージングコンテンツ
  • エンベデッドコンテンツ
  • フォーム関連要素
  • インタラクティブコンテンツ(条件付き)
  • パルパブルコンテンツ

usemap属性がある場合は、インタラクティブコンテンツ。

コンテンツモデル
何もない

要素のコンテンツモデルが「何もない」の場合、要素にはテキストノード (要素間の空白以外) と要素ノードが含まれていてはなりません。

タグの省略

終了タグはありません。

コンテンツ属性
グローバル属性 他
alt属性
画像が利用できない場合に使用する代替テキスト
src属性
リソースのアドレス
srcset属性
高解像度ディスプレイ、小型モニターなど、さまざまな状況で使用する画像。
sizes属性
さまざまなページレイアウトの画像サイズ
crossorigin属性
要素がクロスオリジンリクエストを処理する方法
usemap属性
使用するイメージマップの名前
ismap属性
画像がサーバーサイドイメージマップであるかどうか
width属性
水平寸法
height属性
垂直寸法
referrerpolicy属性
要素によって開始されたフェッチのリファラーポリシー
decoding属性
この画像をプレゼンテーション用に処理するときに使用するデコードのヒント
loading属性
積載延期を決定する際に使用
fetchpriority属性
要素によって開始されるフェッチの優先度を設定します
DOM インターフェイス
HTMLImageElement
  1. [Exposed=Window]
  2. interface HTMLImageElement : HTMLElement {
  3. [HTMLConstructor] constructor();
  4.  
  5. [CEReactions] attribute DOMString alt;
  6. [CEReactions] attribute USVString src;
  7. [CEReactions] attribute USVString srcset;
  8. [CEReactions] attribute DOMString sizes;
  9. [CEReactions] attribute DOMString? crossOrigin;
  10. [CEReactions] attribute DOMString useMap;
  11. [CEReactions] attribute boolean isMap;
  12. [CEReactions] attribute unsigned long width;
  13. [CEReactions] attribute unsigned long height;
  14. readonly attribute unsigned long naturalWidth;
  15. readonly attribute unsigned long naturalHeight;
  16. readonly attribute boolean complete;
  17. readonly attribute USVString currentSrc;
  18. [CEReactions] attribute DOMString referrerPolicy;
  19. [CEReactions] attribute DOMString decoding;
  20. [CEReactions] attribute DOMString loading;
  21. [CEReactions] attribute DOMString fetchPriority;
  22.  
  23. Promise decode();
  24.  
  25. // also has obsolete members
  26. };
HTMLElement
  1. [Exposed=Window]
  2. interface HTMLElement : Element {
  3. [HTMLConstructor] constructor();
  4.  
  5. // metadata attributes
  6. [CEReactions] attribute DOMString title;
  7. [CEReactions] attribute DOMString lang;
  8. [CEReactions] attribute boolean translate;
  9. [CEReactions] attribute DOMString dir;
  10.  
  11. // user interaction
  12. [CEReactions] attribute (boolean or unrestricted double or DOMString)? hidden;
  13. [CEReactions] attribute DOMString inert;
  14. undefined click();
  15. [CEReactions] attribute DOMString accessKey;
  16. readonly attribute DOMString accessKeyLabel;
  17. [CEReactions] attribute boolean draggable;
  18. [CEReactions] attribute boolean spellcheck;
  19. [CEReactions] attribute DOMString writingSuggestions;
  20. [CEReactions] attribute DOMString autocapitalize;
  21.  
  22. [CEReactions] attribute [LegacyNullToEmptyString] DOMString innerText;
  23. [CEReactions] attribute [LegacyNullToEmptyString] DOMString outerText;
  24.  
  25. ElementInternals attachInternals();
  26.  
  27. // The popover API
  28. undefined showPopover();
  29. undefined hidePopover();
  30. boolean togglePopover(optional boolean force);
  31. [CEReactions] attribute DOMString? popover;
  32. };
  33.  
  34. HTMLElement includes GlobalEventHandlers;
  35. HTMLElement includes ElementContentEditable;
  36. HTMLElement includes HTMLOrSVGElement;
Element
  1. [Exposed=Window]
  2. interface Element : Node {
  3. readonly attribute DOMString? namespaceURI;
  4. readonly attribute DOMString? prefix;
  5. readonly attribute DOMString localName;
  6. readonly attribute DOMString tagName;
  7.  
  8. [CEReactions] attribute DOMString id;
  9. [CEReactions] attribute DOMString className;
  10. [SameObject, PutForwards=value] readonly attribute DOMTokenList classList;
  11. [CEReactions, Unscopable] attribute DOMString slot;
  12.  
  13. boolean hasAttributes();
  14. [SameObject] readonly attribute NamedNodeMap attributes;
  15. sequence<DOMString> getAttributeNames();
  16. DOMString? getAttribute(DOMString qualifiedName);
  17. DOMString? getAttributeNS(DOMString? namespace, DOMString localName);
  18. [CEReactions] undefined setAttribute(DOMString qualifiedName, DOMString value);
  19. [CEReactions] undefined setAttributeNS(DOMString? namespace, DOMString qualifiedName, DOMString value);
  20. [CEReactions] undefined removeAttribute(DOMString qualifiedName);
  21. [CEReactions] undefined removeAttributeNS(DOMString? namespace, DOMString localName);
  22. [CEReactions] boolean toggleAttribute(DOMString qualifiedName, optional boolean force);
  23. boolean hasAttribute(DOMString qualifiedName);
  24. boolean hasAttributeNS(DOMString? namespace, DOMString localName);
  25.  
  26. Attr? getAttributeNode(DOMString qualifiedName);
  27. Attr? getAttributeNodeNS(DOMString? namespace, DOMString localName);
  28. [CEReactions] Attr? setAttributeNode(Attr attr);
  29. [CEReactions] Attr? setAttributeNodeNS(Attr attr);
  30. [CEReactions] Attr removeAttributeNode(Attr attr);
  31.  
  32. ShadowRoot attachShadow(ShadowRootInit init);
  33. readonly attribute ShadowRoot? shadowRoot;
  34.  
  35. Element? closest(DOMString selectors);
  36. boolean matches(DOMString selectors);
  37. boolean webkitMatchesSelector(DOMString selectors); // legacy alias of .matches
  38.  
  39. HTMLCollection getElementsByTagName(DOMString qualifiedName);
  40. HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName);
  41. HTMLCollection getElementsByClassName(DOMString classNames);
  42.  
  43. [CEReactions] Element? insertAdjacentElement(DOMString where, Element element); // legacy
  44. undefined insertAdjacentText(DOMString where, DOMString data); // legacy
  45. };
GlobalEventHandlers
  1. interface mixin GlobalEventHandlers {
  2. attribute EventHandler onabort;
  3. attribute EventHandler onauxclick;
  4. attribute EventHandler onbeforeinput;
  5. attribute EventHandler onbeforematch;
  6. attribute EventHandler onbeforetoggle;
  7. attribute EventHandler onblur;
  8. attribute EventHandler oncancel;
  9. attribute EventHandler oncanplay;
  10. attribute EventHandler oncanplaythrough;
  11. attribute EventHandler onchange;
  12. attribute EventHandler onclick;
  13. attribute EventHandler onclose;
  14. attribute EventHandler oncontextlost;
  15. attribute EventHandler oncontextmenu;
  16. attribute EventHandler oncontextrestored;
  17. attribute EventHandler oncopy;
  18. attribute EventHandler oncuechange;
  19. attribute EventHandler oncut;
  20. attribute EventHandler ondblclick;
  21. attribute EventHandler ondrag;
  22. attribute EventHandler ondragend;
  23. attribute EventHandler ondragenter;
  24. attribute EventHandler ondragleave;
  25. attribute EventHandler ondragover;
  26. attribute EventHandler ondragstart;
  27. attribute EventHandler ondrop;
  28. attribute EventHandler ondurationchange;
  29. attribute EventHandler onemptied;
  30. attribute EventHandler onended;
  31. attribute OnErrorEventHandler onerror;
  32. attribute EventHandler onfocus;
  33. attribute EventHandler onformdata;
  34. attribute EventHandler oninput;
  35. attribute EventHandler oninvalid;
  36. attribute EventHandler onkeydown;
  37. attribute EventHandler onkeypress;
  38. attribute EventHandler onkeyup;
  39. attribute EventHandler onload;
  40. attribute EventHandler onloadeddata;
  41. attribute EventHandler onloadedmetadata;
  42. attribute EventHandler onloadstart;
  43. attribute EventHandler onmousedown;
  44. [LegacyLenientThis] attribute EventHandler onmouseenter;
  45. [LegacyLenientThis] attribute EventHandler onmouseleave;
  46. attribute EventHandler onmousemove;
  47. attribute EventHandler onmouseout;
  48. attribute EventHandler onmouseover;
  49. attribute EventHandler onmouseup;
  50. attribute EventHandler onpaste;
  51. attribute EventHandler onpause;
  52. attribute EventHandler onplay;
  53. attribute EventHandler onplaying;
  54. attribute EventHandler onprogress;
  55. attribute EventHandler onratechange;
  56. attribute EventHandler onreset;
  57. attribute EventHandler onresize;
  58. attribute EventHandler onscroll;
  59. attribute EventHandler onscrollend;
  60. attribute EventHandler onsecuritypolicyviolation;
  61. attribute EventHandler onseeked;
  62. attribute EventHandler onseeking;
  63. attribute EventHandler onselect;
  64. attribute EventHandler onslotchange;
  65. attribute EventHandler onstalled;
  66. attribute EventHandler onsubmit;
  67. attribute EventHandler onsuspend;
  68. attribute EventHandler ontimeupdate;
  69. attribute EventHandler ontoggle;
  70. attribute EventHandler onvolumechange;
  71. attribute EventHandler onwaiting;
  72. attribute EventHandler onwebkitanimationend;
  73. attribute EventHandler onwebkitanimationiteration;
  74. attribute EventHandler onwebkitanimationstart;
  75. attribute EventHandler onwebkittransitionend;
  76. attribute EventHandler onwheel;
  77. };
ElementContentEditable
  1. interface mixin ElementContentEditable {
  2. [CEReactions] attribute DOMString contentEditable;
  3. [CEReactions] attribute DOMString enterKeyHint;
  4. readonly attribute boolean isContentEditable;
  5. [CEReactions] attribute DOMString inputMode;
  6. };
HTMLOrSVGElement
  1. interface mixin HTMLOrSVGElement {
  2. [SameObject] readonly attribute DOMStringMap dataset;
  3. attribute DOMString nonce; // intentionally no [CEReactions]
  4.  
  5. [CEReactions] attribute boolean autofocus;
  6. [CEReactions] attribute long tabIndex;
  7. undefined focus(optional FocusOptions options = {});
  8. undefined blur();
  9. };
ARIA in HTML
暗黙的="img" ARIAロール="あり" aria-* 属性="GlobalAny"

暗黙的な ARIAセマンティクスは、role=img です。

空でない alt (alt='some text') がある場合、またはアクセス可能な名前が指定されている場合は、role=img

空の alt (alt='') があり、その他の img 命名方法がない場合は、role=none, role=presentation

alt属性がなく、その他の img 命名方法がない場合、role=img

作成者が要素に指定してもよい ARIAロール値は、 button, checkbox, link, menuitem, menuitemcheckbox, menuitemradio, meter, option, progressbar, radio, scrollbar, separator, slider, switch, tab, treeitem です。

グローバル aria-* 属性と、許可されたロールに適用される任意の aria-* 属性が記述できます。

レンダリング
置換要素
画像
  1. img:is([sizes='auto' i], [sizes^='auto,' i]) {
  2. contain: size !important;
  3. contain-intrinsic-size: 300px 150px;
  4. }
  5. img[align=left i] {
  6. margin-right: 3px;
  7. float: left;
  8. }
  9. img[align=right i] {
  10. margin-left: 3px;
  11. float: right;
  12. }
  13. img[align=top i] { vertical-align: top; }
  14. img[align=baseline i] { vertical-align: baseline; }
  15. img[align=texttop i] { vertical-align: text-top; }
  16. img[align=absmiddle i], img[align=abscenter i] { vertical-align: middle; }
  17. img[align=bottom i] { vertical-align: bottom; }

CSS を大雑把に読むと、 コンテンツが CSSフォーマットモデルの範囲外にある要素です。 などになります。

説明
img要素は、画像を表します。

img要素は、src属性と srcset属性によって指定された画像、および親が picture要素の場合は以前の兄弟 source要素の srcset属性は、埋め込みコンテンツです。alt属性の値は、画像を処理できない人や画像の読み込みが無効になっている人の為に同等のコンテンツを提供します (つまり、img要素のフォールバックコンテンツです)。

  1. <!DOCTYPE html>
  2. <html lang="ja">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>img要素の例 - (Example of img element) | 離珠のHTMLでしぃ!</title>
  6. </head>
  7. <body>
  8. <h1>img要素の例</h1>
  9. <img src="../Img/G00/demo.gif" srcset="../Img/G00/risyu.png 469w, ../Img/G00/demo.gif" sizes="(min-width: 640px) 469px" alt="Sample gif">
  10. <p>この例の img要素は、画面の横幅で用意している画像が異なります。</p>
  11. </body>
  12. </html>

このサンプルへのリンクです。
(./eximg.htm)

参照元
参照元
JSONデータ
JSON形式での、データのイメージです。
  1. {
  2. "img": {
  3. "check": "2024-09-29",
  4. "group": "Embedded",
  5. "element": "- X EMPTY -- Embedded image. (Void elements.) [Flow|Phrasing|Embedded|Form|Interactivelimited|Palpable] --",
  6. "attlist": {
  7. "%Global;": "",
  8. "alt": "%Text; #REQUIRED -- Replacement text for use when images are not available --",
  9. "src": "%URI; #REQUIRED -- Address of the resource --",
  10. "srcset": "CDATA #IMPLIED -- Images to use in different situations, e.g., high-resolution displays, small monitors, etc. --",
  11. "sizes": "CDATA #IMPLIED -- Image sizes for different page layouts --",
  12. "crossorigin": "CDATA #IMPLIED -- How the element handles crossorigin requests --",
  13. "usemap": "%URI; #IMPLIED -- Name of image map to use --",
  14. "ismap": "(ismap) #IMPLIED -- Whether the image is a server-side image map --",
  15. "width": "%Length; #IMPLIED -- Horizontal dimension --",
  16. "height": "%Length; #IMPLIED -- Vertical dimension --",
  17. "referrerpolicy": "CDATA #IMPLIED -- Referrer policy for fetches initiated by the element --",
  18. "decoding": "CDATA #IMPLIED -- Decoding hint to use when processing this image for presentation --",
  19. "loading": "CDATA #IMPLIED -- Used when determining loading deferral --",
  20. "fetchpriority": "CDATA #IMPLIED -- Sets the priority for fetches initiated by the element --",
  21. },
  22. "comment": "画像埋め込み (Embedded image)",
  23. "point": "画像を表します。",
  24. "description": "src属性と srcset属性によって指定された画像、および親が picture要素の場合は以前の兄弟 source要素の srcset属性は、埋め込みコンテンツです。alt属性の値は、画像を処理できない人や画像の読み込みが無効になっている人の為に同等のコンテンツを提供します (つまり、img要素のフォールバックコンテンツです)。",
  25. "kind": "Void",
  26. "categories": [
  27. "Flow",
  28. "Phrasing",
  29. "Embedded",
  30. "Formassociated",
  31. "Interactivelimited",
  32. "Palpable",
  33. ],
  34. "categoriessupplement": "usemap属性がある場合は、インタラクティブコンテンツ。",
  35. "used": [
  36. "parent %Embedded",
  37. "picture (source*,img)",
  38. ],
  39. "contentmodel": "%Nothing",
  40. "tag": [
  41. "-",
  42. "X",
  43. ],
  44. "attributes": {
  45. "alt": "画像が利用できない場合に使用する代替テキスト",
  46. "src": "リソースのアドレス",
  47. "srcset": "高解像度ディスプレイ、小型モニターなど、さまざまな状況で使用する画像。",
  48. "sizes": "さまざまなページレイアウトの画像サイズ",
  49. "crossorigin": "要素がクロスオリジンリクエストを処理する方法",
  50. "usemap": "使用するイメージマップの名前",
  51. "ismap": "画像がサーバーサイドイメージマップであるかどうか",
  52. "width": "水平寸法",
  53. "height": "垂直寸法",
  54. "referrerpolicy": "要素によって開始されたフェッチのリファラーポリシー",
  55. "decoding": "この画像をプレゼンテーション用に処理するときに使用するデコードのヒント",
  56. "loading": "積載延期を決定する際に使用",
  57. "fetchpriority": "要素によって開始されるフェッチの優先度を設定します",
  58. },
  59. "dominterface": "HTMLImageElement",
  60. "rendering": "Images",
  61. "reference": [
  62. {
  63. "title": "HTML Living Standard. 4.8.3 The img element",
  64. "href": "https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element",
  65. "heading": "HTML Living Standard. 4.8.3 The img element",
  66. "sub": "Last Updated 27 August 2024",
  67. },
  68. {
  69. "title": "HTML Living Standard. 15 Rendering 15.4.2 Images",
  70. "href": "https://html.spec.whatwg.org/multipage/rendering.html#images-3",
  71. "heading": "HTML Living Standard. 15 Rendering 15.4.2 Images",
  72. "sub": "Last Updated 27 August 2024",
  73. },
  74. {
  75. "title": "HTML 5.2 W3C Recommendation. 4.7.5. The img element. W3C Recommendation, 14 December 2017.",
  76. "href": "https://www.w3.org/TR/2017/REC-html52-20171214/semantics-embedded-content.html#the-img-element",
  77. "heading": "HTML 5.2 W3C 勧告. 4.7.5. The img element",
  78. "sub": "W3C勧告、2017年12月14日",
  79. },
  80. {
  81. "title": "HTML 5.2 W3C Recommendation. 10.4.2. Images. W3C Recommendation, 14 December 2017.",
  82. "href": "https://www.w3.org/TR/2017/REC-html52-20171214/rendering.html#replaced-elements-images",
  83. "heading": "HTML 5.2 W3C 勧告. 10.4.2. Images",
  84. "sub": "W3C勧告、2017年12月14日",
  85. },
  86. {
  87. "title": "HTML 5.1 W3C Recommendation. 4.7.5. The img element. W3C Recommendation, 1 November 2016.",
  88. "href": "https://www.w3.org/TR/2016/REC-html51-20161101/semantics-embedded-content.html#the-img-element",
  89. "heading": "HTML 5.1 W3C 勧告. 4.7.5. The img element",
  90. "sub": "W3C勧告、2016年11月1日",
  91. },
  92. {
  93. "title": "HTML 5.1 W3C Recommendation. 10.4.2. Images. W3C Recommendation, 1 November 2016.",
  94. "href": "https://www.w3.org/TR/2016/REC-html51-20161101/rendering.html#replaced-elements-images",
  95. "heading": "HTML 5.1 W3C 勧告. 10.4.2. Images",
  96. "sub": "W3C勧告、2016年11月1日",
  97. },
  98. {
  99. "title": "HTML 5 W3C Recommendation. 4.7.1 The img element. W3C Recommendation, 28 October 2014.",
  100. "href": "https://www.w3.org/TR/2014/REC-html5-20141028/embedded-content-0.html#the-img-element",
  101. "heading": "HTML 5 W3C 勧告. 4.7.1 The img element",
  102. "sub": "W3C勧告、2014年10月28日",
  103. },
  104. {
  105. "title": "HTML 5 W3C Recommendation. 10.4.2. Images. W3C Recommendation, 28 October 2014.",
  106. "href": "https://www.w3.org/TR/2014/REC-html5-20141028/rendering.html#images",
  107. "heading": "HTML 5 W3C 勧告. 10.4.2. Images",
  108. "sub": "W3C勧告、2014年10月28日",
  109. },
  110. {
  111. "title": "HTML 4.01 Specification W3C Recommendation. 13.2 Including an image: the IMG element. W3C Recommendation 24 December 1999.",
  112. "href": "https://www.w3.org/TR/html401/struct/objects.html#edef-IMG",
  113. "heading": "HTML 4.01 Specification W3C 勧告. 13.2 Including an image: the IMG element",
  114. "sub": "W3C勧告1999年12月24日",
  115. },
  116. {
  117. "title": "HTML 3.2 Reference Specification. W3C Recommendation 14-Jan-1997.",
  118. "href": "https://www.w3.org/TR/2018/SPSD-html32-20180315/#img",
  119. "heading": "HTML 3.2 Reference Specification",
  120. "sub": "W3C勧告1997年1月14日",
  121. },
  122. {
  123. "title": "Hypertext Markup Language - 2.0. November 1995.",
  124. "href": "https://www.ietf.org/rfc/rfc1866.txt",
  125. "heading": "Hypertext Markup Language - 2.0",
  126. "sub": "November 1995",
  127. },
  128. {
  129. "title": "Hypertext Markup Language (HTML). June 1993.",
  130. "href": "https://www.w3.org/MarkUp/draft-ietf-iiir-html-01.txt",
  131. "heading": "Hypertext Markup Language (HTML)",
  132. "sub": "June 1993",
  133. },
  134. {
  135. "title": "MDN Web Docs. HTML <img>: The Image Embed element.",
  136. "href": "https://developer.mozilla.org/ja/docs/Web/HTML/Element/img",
  137. "heading": "MDN Web Docs. HTML <img>: 画像埋め込み要素",
  138. },
  139. ],
  140. "version": {
  141. "first": "HTML",
  142. "latest": "HTML Living Standard",
  143. },
  144. }
  145. }

注意: 簡易に描画する為に、各項目の後ろに , を付与しています。JSON の形式では、末尾の項目の後には , は付けません。

最終確認日

2024-09-29


2.使用できるコンテキスト


3.コンテンツモデル


4.コンテンツ属性


5.DOM インターフェイス


6.レンダリング


7.気を付ける点


8.付記