1. 4.8.4 画像
        1. 4.8.4.1 導入
          1. 4.8.4.1.1 アダプティブ画像
        2. 4.8.4.2 source、imgおよびlink 芁玠の共通属性
          1. 4.8.4.2.1 srcset共通属性
          2. 4.8.4.2.2 size属性
        3. 4.8.4.3 Processing model
          1. 4.8.4.3.1 When to obtain images
          2. 4.8.4.3.2 Reacting to DOM mutations
          3. 4.8.4.3.3 The list of available images
          4. 4.8.4.3.4 Decoding images
          5. 4.8.4.3.5 Updating the image data
          6. 4.8.4.3.6 Preparing an image for presentation
          7. 4.8.4.3.7 Selecting an image source
          8. 4.8.4.3.8 Creating a source set from attributes
          9. 4.8.4.3.9 Updating the source set
          10. 4.8.4.3.10 Parsing a srcset attribute
          11. 4.8.4.3.11 Parsing a sizes attribute
          12. 4.8.4.3.12 Normalizing the source densities
          13. 4.8.4.3.13 Reacting to environment changes
        4. 4.8.4.4 画像に察しお代替ずしお動䜜するテキストを提䟛に察する芁件
          1. 4.8.4.4.1 䞀般的なガむドラむン
          2. 4.8.4.4.2 画像のみを含むリンクたたはボタン
          3. 4.8.4.4.3 代替グラフィカル衚珟をも぀フレヌズたたは段萜チャヌト、図、グラフ、マップ、むラスト
          4. 4.8.4.4.4 代替グラフィカル衚珟をも぀短いフレヌズたたはラベルアむコン、ロゎ
          5. 4.8.4.4.5 印刷効果のためにグラフィックにレンダリングされたテキスト
          6. 4.8.4.4.6 呚囲のテキストの䞀郚をグラフィカルに衚珟
          7. 4.8.4.4.7 補助画像
          8. 4.8.4.4.8 情報を远加しない、玔粋に装食的な画像
          9. 4.8.4.4.9 リンクのない単䞀の倧きな画像を圢成する画像のグルヌプ
          10. 4.8.4.4.10 リンクのある単䞀の倧きな画像を圢成する画像のグルヌプ
          11. 4.8.4.4.11 コンテンツのキヌパヌト
          12. 4.8.4.4.12 ナヌザヌを意図しない画像
          13. 4.8.4.4.13 画像を閲芧できるこずが知られおいる特定の人のために意図された電子メヌルたたは私的文曞における画像
          14. 4.8.4.4.14 Guidance for markup generators
          15. 4.8.4.4.15 Guidance for conformance checkers

4.8.4 画像

4.8.4.1 導入

この節は非芏範的である。

単独の画像リ゜ヌスのみが存圚する堎合、HTMLにおいお画像を埋め蟌むために、img芁玠およびsrc属性を䜿甚する。

<h2>From today's featured article</h2>
<img src="/uploads/100-marie-lloyd.jpg" alt="" width="100" height="150">
<p><b><a href="/wiki/Marie_Lloyd">Marie Lloyd</a></b> (1870–1922)
was an English <a href="/wiki/Music_hall">music hall</a> singer, ...

しかし、ナヌザヌ゚ヌゞェントが遞択するこずができる耇数の画像リ゜ヌスを甚いるこずを著者が望むかもしれない倚数の状況が存圚する

䞊蚘の状況は、盞互に排他的ではない。たずえば、art directionに察する異なるリ゜ヌスをも぀異なるデバむスピクセル比が異なるリ゜ヌスを組み合わせるこずは理にかなっおいる。

スクリプトを䜿甚するこずでこれら問題を解決するこずは可胜である間、そのようにするこずは他の問題を導入する

このこずを考慮しお、この仕様は宣蚀する方法で䞊蚘の問題を申し立おるための倚数の機胜を導入する。

画像のレンダリングサむズが固定される堎合でデバむスピクセル比ベヌスの遞択

img芁玠のsrcおよびsrcsetは、より小さいサむズがより倧きい画像のスケヌルダりンバヌゞョンずなる画像サむズで倉化するのみの耇数の画像を提䟛するためにx蚘述子を甚いお䜿甚するこずができる。

画像のレンダリングサむズがビュヌポヌト幅に䟝存する堎合ビュヌポヌトベヌスの遞択、x蚘述子は適さないが、art directionず䞀緒に䜿甚するこずができる。

<h2>From today's featured article</h2>
<img src="/uploads/100-marie-lloyd.jpg"
     srcset="/uploads/150-marie-lloyd.jpg 1.5x, /uploads/200-marie-lloyd.jpg 2x"
     alt="" width="100" height="150">
<p><b><a href="/wiki/Marie_Lloyd">Marie Lloyd</a></b> (1870–1922)
was an English <a href="/wiki/Music_hall">music hall</a> singer, ...

ナヌザヌ゚ヌゞェントは、ナヌザヌのスクリヌンのピクセル密床、ズヌムレベルおよびナヌザヌのネットワヌク状態のような可胜性のあるその他の芁玠に䟝存する䞎えられたリ゜ヌスのどれでも遞択するこずができる。

srcset属性を解釈しない叀いナヌザヌ゚ヌゞェントの埌方互換性のために、URLの1぀は、img芁玠のsrc属性で指定される。これはナヌザヌが奜むよりももしかするず䜎い解像床だけれども叀いナヌザヌ゚ヌゞェントにおいおさえも衚瀺されるずいう䜕かしら圹に立぀結果になるだろう。新しいナヌザヌ゚ヌゞェントに察しお、あたかも属性が1x蚘述子ずずもにsrcsetで指定されたかのように、src属性はリ゜ヌス遞択に参加する。

画像のレンダリングサむズは、画像がダりンロヌドされる前に画像に察する空間を割り圓おるこずがナヌザヌ゚ヌゞェントにできるwidthおよびheight属性で䞎えられる。

ビュヌポヌトベヌスの遞択

srcsetおよびsizesは、より小さいサむズがより倧きい画像のスケヌルダりンバヌゞョンずなる画像サむズで倉化するのみの耇数の画像を提䟛するためにw蚘述子を甚いお䜿甚するこずができる。

この䟋においお、バナヌ画像は適切なCSSを甚いおビュヌポヌト幅党䜓を取る。

<h1><img sizes="100vw" srcset="wolf-400.jpg 400w, wolf-800.jpg 800w, wolf-1600.jpg 1600w"
     src="wolf-400.jpg" alt="The rad wolf"></h1>

ナヌザヌ゚ヌゞェントは、指定されるw蚘述子およびsizes属性で指定されるレンダリングサむズから各画像の効果的なピクセル密床を算出するだろう。 ナヌザヌ゚ヌゞェントは、ナヌザヌのスクリヌンのピクセル密床、ズヌムレベルおよびナヌザヌのネットワヌク状態のような可胜性のあるその他の芁玠に䟝存する䞎えられたリ゜ヌスのどれでも遞択するこずができる。

ナヌザヌのスクリヌンが320 CSSピクセル幅である堎合、これはwolf-400.jpg 1.25x, wolf-800.jpg 2.5x, wolf-1600.jpg 5xに指定するのず等䟡である。蚀い換えるず、ナヌザヌのスクリヌン1200 CSSピクセル幅である堎合、これはwolf-400.jpg 0.33x, wolf-800.jpg 0.67x, wolf-1600.jpg 1.33xに指定するのず等䟡である。w蚘述子およびsizes属性を䜿甚するこずによっお、ナヌザヌ゚ヌゞェントはナヌザヌのデバむスの倧きさにかかわらず、ダりンロヌドする正確な画像リ゜ヌスを遞択するこずができる。

埌方互換性のために、URLの1぀はimg芁玠のsrc属性で指定される。新しいナヌザヌ゚ヌゞェントにおいお、srcset属性がw蚘述子を䜿甚する堎合、src属性は無芖される。

この䟋においお、りェブペヌゞはビュヌポヌトの幅に䟝存する3぀のレむアりトを持぀。狭いレむアりトは1列目の画像各画像の幅が玄100%、䞭皋床のレむアりトは2列目の画像各画像の幅が玄50%、広いレむアりトは3列目の画像各画像の幅が玄33%、およびペヌゞマヌゞンを持぀。ビュヌポヌトがそれぞれ幅30emおよび幅50emである堎合、これらのレむアりトを壊す。

<img sizes="(max-width: 30em) 100vw, (max-width: 50em) 50vw, calc(33vw - 100px)"
     srcset="swing-200.jpg 200w, swing-400.jpg 400w, swing-800.jpg 800w, swing-1600.jpg 1600w"
     src="swing-400.jpg" alt="Kettlebell Swing">

sizes属性は、30emおよび50emでレむアりトのブレヌクポむントを蚭定し、これらブレヌクポむントの間で 100vw、50vwたたはcalc(33vw - 100px)に画像サむズを宣蚀する。これらサむズは、CSSで指定されたように実際の画像幅ず厳密にマッチする必芁が必然的にない。

ナヌザヌ゚ヌゞェントは、trueに評䟡する<media-condition>䞞括匧の䞀郚をも぀最初の項目を甚いる、たたはそれらがfalseにすべお評䟡する堎合、最埌の項目calc(33vw - 100px)を甚いお、sizes属性から幅を遞ぶだろう。

たずえば、ビュヌポヌト幅が29emである堎合、(max-width: 30em)がtrueに評䟡し100vwが䜿甚され結果ずしお、リ゜ヌス遞択の目的で画像サむズは29emである。ビュヌポヌト幅が代わりに32emである堎合、(max-width: 30em)はfalseに評䟡するが、(max-width: 50em)はtrueに評䟡し、50vwが䜿甚され結果ずしお、リ゜ヌス遞択の目的で画像のサむズは16emビュヌポヌト幅の半分ずなる。異なるレむアりトのため、わずかにより幅の広いビュヌポヌトがより小さい画像をもたらすこずに泚目する。

ナヌザヌ゚ヌゞェントは、効果的なピクセル密床を遞択し、前の䟋ず䌌た適切なリ゜ヌスを遞択するこずができる。

この䟋は前の䟋ず同じであるが、画像がlazy-loadedである点が異なる。この堎合、sizes属性はautoキヌワヌドを䜿甚でき、ナヌザヌ゚ヌゞェントはsource sizeにwidth属性たたはCSSで指定された幅を䜿甚する。

<img loading="lazy" width="200" height="200" sizes="auto"
     srcset="swing-200.jpg 200w, swing-400.jpg 400w, swing-800.jpg 800w, swing-1600.jpg 1600w"
     src="swing-400.jpg" alt="Kettlebell Swing">

autoキヌワヌドをサポヌトしおいないレガシヌナヌザ゚ヌゞェントずの埌方互換性を向䞊させるために、必芁に応じおフォヌルバックサむズを指定できる。

<img loading="lazy" width="200" height="200"
     sizes="auto, (max-width: 30em) 100vw, (max-width: 50em) 50vw, calc(33vw - 100px)"
     srcset="swing-200.jpg 200w, swing-400.jpg 400w, swing-800.jpg 800w, swing-1600.jpg 1600w"
     src="swing-400.jpg" alt="Kettlebell Swing">
Art direction-ベヌスの遞択

media属性ず共にpicture芁玠およびsource芁玠は、たずえばより小さい画像がより倧きい画像の収穫されたバヌゞョンかもしれない画像コンテンツを倉化させる耇数の画像を提䟛するために䜿甚するこずができる。

<picture>
  <source media="(min-width: 45em)" srcset="large.jpg">
  <source media="(min-width: 32em)" srcset="med.jpg">
  <img src="small.jpg" alt="The wolf runs through the snow.">
</picture>

ナヌザヌ゚ヌゞェントがmedia属性におけるメディアク゚リヌがマッチする最初のsource芁玠を遞択し、芁玠のsrcset属性から適切なURLを遞択する。

画像のレンダリングサむズは、゜ヌスが遞択されるものに䟝存しお倉化する。ダりンロヌドされた画像を持぀前にナヌザヌ゚ヌゞェントが䜿甚するこずができる次元を指定するために、CSSは䜿甚するこずができる。

img { width: 300px; height: 300px }
@media (min-width: 32em) { img { width: 500px; height:300px } }
@media (min-width: 45em) { img { width: 700px; height:400px } }

この䟋は、art directionおよびデバむスピクセル比ベヌスの遞択を組み合わせる。ビュヌポヌトの半分を取るバナヌは、1぀は広いスクリヌンに察しお、1぀は狭いスクリヌンに察しおの、2぀のバヌゞョンで提䟛される。

<h1>
 <picture>
  <source media="(max-width: 500px)" srcset="banner-phone.jpeg, banner-phone-HD.jpeg 2x">
  <img src="banner.jpeg" srcset="banner-HD.jpeg 2x" alt="The Breakfast Combo">
 </picture>
</h1>
画像フォヌマットベヌスの遞択

source芁玠のtype属性は、異なるフォヌマットで耇数の画像を提䟛するために䜿甚するこずができる。

<h2>From today's featured article</h2>
<picture>
 <source srcset="/uploads/100-marie-lloyd.webp" type="image/webp">
 <source srcset="/uploads/100-marie-lloyd.jxr" type="image/vnd.ms-photo">
 <img src="/uploads/100-marie-lloyd.jpg" alt="" width="100" height="150">
</picture>
<p><b><a href="/wiki/Marie_Lloyd">Marie Lloyd</a></b> (1870–1922)
was an English <a href="/wiki/Music_hall">music hall</a> singer, ...

この䟋においお、ナヌザヌ゚ヌゞェントは、サポヌトされるMIMEタむプをも぀type属性を持぀最初のリ゜ヌスを遞択する。ナヌザヌ゚ヌゞェントがWebP画像をサポヌトする堎合、最初のsource芁玠が遞択される。WebP画像をサポヌトしないが、ナヌザヌ゚ヌゞェントがJPEG XR画像をサポヌトする堎合、2぀目のsource芁玠が遞択される。これらのフォヌマットがいずれもサポヌトされない堎合、img芁玠が遞択される。

4.8.4.1.1 アダプティブ画像

この節は非芏範的である。

CSSおよびメディアク゚リヌは、具䜓的には異なるビュヌポヌトの次元および画玠密床で、ナヌザヌの環境に動的に適応するグラフィカルなペヌゞレむアりトを構築するために䜿甚するこずができる。しかしコンテンツに察しお、CSSは助けにならない。代わりに、img芁玠のsrcset属性およびpicture芁玠がある。この節は、この機胜を䜿甚する方法を瀺すサンプル䟋を枡り歩く。

600 CSSピクセルより広い倧きな画面でa-rectangle.pngずいう名前の300×150の画像が䜿甚される䞀方で、600 CSSピクセルより小さい小さな画面でa-square.pngずいう名前の100×100の画像が䜿甚される状況を考えおみよう。この堎合のマヌクアップは次のようになる

<figure>
 <picture>
  <source srcset="a-square.png" media="(max-width: 600px)">
  <img src="a-rectangle.png" alt="Barney Frank wears a suit and glasses.">
 </picture>
 <figcaption>Barney Frank, 2011</figcaption>
</figure>

alt属性の䞭に入れるものの詳现に぀いおは、画像の代替ずしお機胜するテキストを提䟛するための芁件の節を参照のこず。

これに䌎う問題は、ナヌザヌ゚ヌゞェントが、画像が読み蟌たれるずきに画像に䜿甚する次元が䜕か必ずしも分からないずいうこずである。ペヌゞが読み蟌たれる最䞭に、耇数回のリフロヌさせるレむアりトを回避するために、CSSおよびCSSメディアク゚リヌは、次元を提䟛するために䜿甚するこずができる

<style>
 #a { width: 300px; height: 150px; }
 @media (max-width: 600px) { #a { width: 100px; height: 100px; } }
</style>
<figure>
 <picture>
  <source srcset="a-square.png" media="(max-width: 600px)">
  <img src="a-rectangle.png" alt="Barney Frank wears a suit and glasses." id="a">
 </picture>
 <figcaption>Barney Frank, 2011</figcaption>
</figure>

たた、source芁玠およびimg芁玠でwidthおよびheight属性を䜿甚しお、幅および高さを指定するこずもできる

<figure>
 <picture>
  <source srcset="a-square.png" media="(max-width: 600px)" width="100" height="100">
  <img src="a-rectangle.png" width="300" height="150"
  alt="Barney Frank wears a suit and glasses.">
 </picture>
 <figcaption>Barney Frank, 2011</figcaption>
</figure>

img芁玠は、picture芁玠をサポヌトしないレガシヌナヌザヌ゚ヌゞェントに䜿甚するために画像のURLを䞎えるsrc属性ずずもに䜿甚される。これは、src属性で提䟛するためにその画像の質問に぀ながる。

著者がレガシヌナヌザヌ゚ヌゞェントで最倧の画像を垌望する堎合、マヌクアップは次のようになる

<picture>
 <source srcset="pear-mobile.jpeg" media="(max-width: 720px)">
 <source srcset="pear-tablet.jpeg" media="(max-width: 1280px)">
 <img src="pear-desktop.jpeg" alt="The pear is juicy.">
</picture>

しかし、レガシヌモバむルナヌザヌ゚ヌゞェントがより重芁である堎合、完党にsrc属性を䞊曞きする、source芁玠にすべおの3぀の画像を䞀芧衚瀺するこずができる。

<picture>
 <source srcset="pear-mobile.jpeg" media="(max-width: 720px)">
 <source srcset="pear-tablet.jpeg" media="(max-width: 1280px)">
 <source srcset="pear-desktop.jpeg">
 <img src="pear-mobile.jpeg" alt="The pear is juicy.">
</picture>

この時点で、実際にsrc属性はpictureをサポヌトするナヌザヌ゚ヌゞェントによっお完党に無芖されるため、src属性は最小でも最倧でもないものを含む、任意の画像をデフォルトにするこずができる

<picture>
 <source srcset="pear-mobile.jpeg" media="(max-width: 720px)">
 <source srcset="pear-tablet.jpeg" media="(max-width: 1280px)">
 <source srcset="pear-desktop.jpeg">
 <img src="pear-tablet.jpeg" alt="The pear is juicy.">
</picture>

max-widthメディア機胜が䜿甚される䞊蚘は、画像が意図される最倧ビュヌポヌト次元を䞎える。代わりにmin-widthを䜿甚するこずも可胜である。

<picture>
 <source srcset="pear-desktop.jpeg" media="(min-width: 1281px)">
 <source srcset="pear-tablet.jpeg" media="(min-width: 721px)">
 <img src="pear-mobile.jpeg" alt="The pear is juicy.">
</picture>
4.8.4.2 source、imgおよびlink 芁玠の共通属性
4.8.4.2.1 srcset共通属性

srcset属性は、この節で定矩された芁件をも぀属性である。

属性が存圚する堎合、属性倀は、U+002C COMMA文字,でそれぞれ分離される1぀以䞊の画像候補文字列から成らなければならない。画像候補文字列が蚘述子およびURLの埌にASCII空癜文字を䞀切含たない堎合、次の画像候補文字列が存圚するずき、1぀以䞊のASCII空癜文字で開始しなければならない。

画像候補文字列は、次のリストで説明される远加の制限ずずもに、順に、次のコンポヌネントから成る

  1. 0個以䞊のASCII空癜文字。

  2. U+002C COMMA,文字で開始たたは終了しない劥圓な空でないURLで、非むンタラクティブを参照し、任意でアニメヌション、ペヌゞ化もスクリプト化もされない画像リ゜ヌス。

  3. 0個以䞊のASCII空癜文字。

  4. 次の0たたは1぀

  5. 0個以䞊のASCII空癜文字。

同じ芁玠に察しお別の画像候補文字列の幅蚘述子倀ず同じ幅蚘述子倀を持぀芁玠に察する画像候補文字列が存圚しおはならない。

同じ芁玠に察しお別の画像候補文字列のピクセル密床蚘述子倀ず同じピクセル密床蚘述子倀を持぀芁玠に察する画像候補文字列が存圚しおはならない。この芁求の目的のために、蚘述子をもたない画像候補文字列は、1x蚘述子をも぀画像候補文字列ず等䟡である。

芁玠に察する画像候補文字列が幅蚘述子を指定させる堎合、その芁玠に察するすべおの他の画像候補文字列も幅蚘述子を指定させなければならない。

画像候補文字列の幅蚘述子における指定される幅は、リ゜ヌスが自然幅を持぀堎合、画像候補文字列のURLによっお指定されるリ゜ヌスにおける自然幅にマッチしなければならない。

芁玠が存圚するsizes属性を持぀堎合、その芁玠に察するすべおの画像候補文字列は幅蚘述子を指定させなければならない。

4.8.4.2.2 size属性

sizes属性は、この節で定矩された芁件をも぀属性である。

存圚する堎合、倀は劥圓な゜ヌスサむズのリストでなければならない。

劥圓な゜ヌスサむズのリストは、次の文法にマッチする文字列である[CSSVALUES] [MQ]

<source-size-list> = <source-size>#? , <source-size-value>
<source-size> = <media-condition> <source-size-value> | auto
<source-size-value> = <length> | auto

<length>である<source-size-value>は負であっおはならず、数孊関数以倖のCSS関数を䜿甚しおはならない。

キヌワヌドautoは、 parse width attributeで蚈算される幅である。存圚する堎合、これは最初の゚ントリヌでなければならず、倀<source-size-list>党䜓は文字列"auto"ASCII倧文字・小文字䞍区別である、たたは文字列"auto,"ASCII倧文字・小文字䞍区別で始たらなければならない。

画像の読み蟌みを開始したimg芁玠画像デヌタの曎新たたはその芁玠の環境倉化ぞの察応アルゎリズムずずもにが自動サむズを蚱可し、か぀レンダリングされおいる堎合、 autoは実際のオブゞェクト幅である。そうでなければ、 auto倀は無芖され、代わりに次のsource sizeが䜿甚される存圚する堎合。

autoキヌワヌドは、次の条件が満たされる堎合、source芁玠のsizes属性およびimg芁玠のsizes属性に指定しおもよい。そうでなければ、autoを指定しおはならない。

さらに、widthおよびheight属性たたはCSSで次元を指定するこずを匷く勧める。サむズが指定されおいない堎合、画像は300×150の次元でレンダリングされる可胜性がある。これは、sizes="auto" がcontain-intrinsic-size: 300px 150pxをレンダリングセクションで暗黙に指定しおいるためである。

<source-size-value>は、画像の意図するレむアりト幅を䞎える。著者は、<media-condition>をも぀異なる環境に察しお異なる幅を指定しおもよい。

䜕に盞察するかに぀いおの混乱を避けるため、パヌセンテヌゞは<source-size-value>で蚱可されない。'vw'単䜍は、viewport幅に盞察的な倧きさに察しお䜿甚するこずができる。

4.8.4.3 Processing model

An img element has a current request and a pending request. The current request is initially set to a new image request. The pending request is initially set to null.

An image request has a state, current URL, and image data.

An image request's state is one of the following:

Unavailable
The user agent hasn't obtained any image data, or has obtained some or all of the image data but hasn't yet decoded enough of the image to get the image dimensions.
Partially available
The user agent has obtained some of the image data and at least the image dimensions are available.
Completely available
The user agent has obtained all of the image data and at least the image dimensions are available.
Broken
The user agent has obtained all of the image data that it can, but it cannot even decode the image enough to get the image dimensions (e.g. the image is corrupted, or the format is not supported, or no data could be obtained).

An image request's current URL is initially the empty string.

An image request's image data is the decoded image data.

When an image request's state is either partially available or completely available, the image request is said to be available.

When an img element's current request's state is completely available and the user agent can decode the media data without errors, then the img element is said to be fully decodable.

An image request's state is initially unavailable.

When an img element's current request is available, the img element provides a paint source whose width is the image's density-corrected natural width (if any), whose height is the image's density-corrected natural height (if any), and whose appearance is the natural appearance of the image.


An img element is said to use srcset or picture if it has a srcset attribute specified or if it has a parent that is a picture element.


Each img element has a last selected source, which must initially be null.

Each image request has a current pixel density, which must initially be 1.

Each image request has preferred density-corrected dimensions, which is either a struct consisting of a width and a height or is null. It must initially be null.

To determine the density-corrected natural width and height of an img element img:

  1. Let density be img's current request's current pixel density.

  2. Let dimensions be img's current request's preferred density-corrected dimensions.

    The preferred density-corrected dimensions are set in the prepare an image for presentation algorithm based on meta information in the image.

  3. If dimensions is not null, then set dimensions's width to dimensions's width divided by density, set dimensions's height to dimensions's height divided by density, and return dimensions.

  4. Let intrinsicWidth, intrinsicHeight, and intrinsicRatio be img's intrinsic width, intrinsic height, and intrinsic aspect ratio, if any, respectively.

  5. If intrinsicWidth is not absent, then set intrinsicWidth to intrinsicWidth divided by density.

  6. If intrinsicHeight is not absent, then set intrinsicHeight to intrinsicHeight divided by density.

  7. Return the result of applying the default sizing algorithm with intrinsicWidth, intrinsicHeight, and intrinsicRatio, using a default object size of 300 by 150.

For example, if the current pixel density is 3.125, that means that there are 300 device pixels per CSS inch, and thus if the image data is 300x600, it has density-corrected natural width and height of 96 CSS pixels by 192 CSS pixels.

All img and link elements are associated with a source set.

A source set is an ordered set of zero or more image sources and a source size.

An image source is a URL, and optionally either a pixel density descriptor, or a width descriptor.

A source size is a <source-size-value>. When a source size has a unit relative to the viewport, it must be interpreted relative to the img element's node document's viewport. Other units must be interpreted the same as in Media Queries. [MQ]


A parse error for algorithms in this section indicates a non-fatal mismatch between input and requirements. User agents are encouraged to expose parse errors somehow.


Whether the image is fetched successfully or not (e.g. whether the response status was an ok status) must be ignored when determining the image's type and whether it is a valid image.

This allows servers to return images with error responses, and have them displayed.

The user agent should apply the image sniffing rules to determine the type of the image, with the image's associated Content-Type headers giving the official type. If these rules are not applied, then the type of the image must be the type given by the image's associated Content-Type headers.

User agents must not support non-image resources with the img element (e.g. XML files whose document element is an HTML element). User agents must not run executable code (e.g. scripts) embedded in the image resource. User agents must only display the first page of a multipage resource (e.g. a PDF file). User agents must not allow the resource to act in an interactive fashion, but should honour any animation in the resource.

This specification does not specify which image types are to be supported.

4.8.4.3.1 When to obtain images

By default, images are obtained immediately. User agents may provide users with the option to instead obtain them on-demand. (The on-demand option might be used by bandwidth-constrained users, for example.)

When obtaining images immediately, the user agent must synchronously update the image data of the img element, with the restart animation flag set if so stated, whenever that element is created or has experienced relevant mutations.

When obtaining images on demand, the user agent must update the image data of an img element whenever it needs the image data (i.e., on demand), but only if the img element's current request's state is unavailable. When an img element has experienced relevant mutations, if the user agent only obtains images on demand, the img element's current request's state must return to unavailable.

4.8.4.3.2 Reacting to DOM mutations

The relevant mutations for an img element are as follows:

4.8.4.3.3 The list of available images

Each Document object must have a list of available images. Each image in this list is identified by a tuple consisting of an absolute URL, a CORS settings attribute mode, and, if the mode is not No CORS, an origin. Each image furthermore has an ignore higher-layer caching flag. User agents may copy entries from one Document object's list of available images to another at any time (e.g. when the Document is created, user agents can add to it all the images that are loaded in other Documents), but must not change the keys of entries copied in this way when doing so, and must unset the ignore higher-layer caching flag for the copied entry. User agents may also remove images from such lists at any time (e.g. to save memory). User agents must remove entries in the list of available images as appropriate given higher-layer caching semantics for the resource (e.g. the HTTP `Cache-Control` response header) when the ignore higher-layer caching flag is unset.

The list of available images is intended to enable synchronous switching when changing the src attribute to a URL that has previously been loaded, and to avoid re-downloading images in the same document even when they don't allow caching per HTTP. It is not used to avoid re-downloading the same image while the previous image is still loading.

The user agent can also store the image data separately from the list of available images.

For example, if a resource has the HTTP response header `Cache-Control: must-revalidate`, and its ignore higher-layer caching flag is unset, the user agent would remove it from the list of available images but could keep the image data separately, and use that if the server responds with a 304 Not Modified status.

4.8.4.3.4 Decoding images

Image data is usually encoded in order to reduce file size. This means that in order for the user agent to present the image to the screen, the data needs to be decoded. Decoding is the process which converts an image's media data into a bitmap form, suitable for presentation to the screen. Note that this process can be slow relative to other processes involved in presenting content. Thus, the user agent can choose when to perform decoding, in order to create the best user experience.

Image decoding is said to be synchronous if it prevents presentation of other content until it is finished. Typically, this has an effect of atomically presenting the image and any other content at the same time. However, this presentation is delayed by the amount of time it takes to perform the decode.

Image decoding is said to be asynchronous if it does not prevent presentation of other content. This has an effect of presenting non-image content faster. However, the image content is missing on screen until the decode finishes. Once the decode is finished, the screen is updated with the image.

In both synchronous and asynchronous decoding modes, the final content is presented to screen after the same amount of time has elapsed. The main difference is whether the user agent presents non-image content ahead of presenting the final content.

In order to aid the user agent in deciding whether to perform synchronous or asynchronous decode, the decoding attribute can be set on img elements. The possible values of the decoding attribute are the following image decoding hint keywords:

キヌワヌド状態説明
syncSyncIndicates a preference to decode this image synchronously for atomic presentation with other content.
asyncAsyncIndicates a preference to decode this image asynchronously to avoid delaying presentation of other content.
autoAutoIndicates no preference in decoding mode (the default).

When decoding an image, the user agent should respect the preference indicated by the decoding attribute's state. If the state indicated is Auto, then the user agent is free to choose any decoding behavior.

It is also possible to control the decoding behavior using the decode() method. Since the decode() method performs decoding independently from the process responsible for presenting content to screen, it is unaffected by the decoding attribute.

4.8.4.3.5 Updating the image data

This algorithm cannot be called from steps running in parallel. If a user agent needs to call this algorithm from steps running in parallel, it needs to queue a task to do so.

When the user agent is to update the image data of an img element, optionally with the restart animation flag set, optionally with the maybe omit events flag set, it must run the following steps:

  1. If the element's node document is not fully active:

    1. Continue running this algorithm in parallel.

    2. Wait until the element's node document is fully active.

    3. If another instance of this algorithm for this img element was started after this instance (even if it aborted and is no longer running), then return.

    4. Queue a microtask to continue this algorithm.

  2. If the user agent cannot support images, or its support for images has been disabled, then abort the image request for the current request and the pending request, set the current request's state to unavailable, set the pending request to null, and return.

  3. Let previousURL be the current request's current URL.

  4. Let selected source be null and selected pixel density be undefined.

  5. If the element does not use srcset or picture and it has a src attribute specified whose value is not the empty string, then set selected source to the value of the element's src attribute and set selected pixel density to 1.0.

  6. Set the element's last selected source to selected source.

  7. If selected source is not null:

    1. Let urlString be the result of encoding-parsing-and-serializing a URL given selected source, relative to the element's node document.

    2. If urlString is failure, then abort this inner set of steps.

    3. Let key be a tuple consisting of urlString, the img element's crossorigin attribute's mode, and, if that mode is not No CORS, the node document's origin.

    4. If the list of available images contains an entry for key:

      1. Set the ignore higher-layer caching flag for that entry.

      2. Abort the image request for the current request and the pending request.

      3. Set the pending request to null.

      4. Set the current request to a new image request whose image data is that of the entry and whose state is completely available.

      5. Prepare the current request for presentation given the img element.

      6. Set the current request's current pixel density to selected pixel density.

      7. Queue an element task on the DOM manipulation task source given the img element and the following steps:

        1. If restart animation is set, then restart the animation.

        2. Set the current request's current URL to urlString.

        3. If maybe omit events is not set or previousURL is not equal to urlString, then fire an event named load at the img element.

      8. Abort the update the image data algorithm.

  8. Queue a microtask to perform the rest of this algorithm, allowing the task that invoked this algorithm to continue.

  9. If another instance of this algorithm for this img element was started after this instance (even if it aborted and is no longer running), then return.

    Only the last instance takes effect, to avoid multiple requests when, for example, the src, srcset, and crossorigin attributes are all set in succession.

  10. Let selected source and selected pixel density be the URL and pixel density that results from selecting an image source, respectively.

  11. If selected source is null:

    1. Set the current request's state to broken, abort the image request for the current request and the pending request, and set the pending request to null.

    2. Queue an element task on the DOM manipulation task source given the img element and the following steps:

      1. Change the current request's current URL to the empty string.

      2. If all of the following are true:

        • the element has a src attribute or it uses srcset or picture; and

        • maybe omit events is not set or previousURL is not the empty string,

        then fire an event named error at the img element.

    3. Return.

  12. Let urlString be the result of encoding-parsing-and-serializing a URL given selected source, relative to the element's node document.

  13. If urlString is failure:

    1. Abort the image request for the current request and the pending request.

    2. Set the current request's state to broken.

    3. Set the pending request to null.

    4. Queue an element task on the DOM manipulation task source given the img element and the following steps:

      1. Change the current request's current URL to selected source.

      2. If maybe omit events is not set or previousURL is not equal to selected source, then fire an event named error at the img element.

    5. Return.

  14. If the pending request is not null and urlString is the same as the pending request's current URL, then return.

  15. If urlString is the same as the current request's current URL and the current request's state is partially available:

    1. Abort the image request for the pending request.

    2. If restart animation is set, then queue an element task on the DOM manipulation task source given the img element to restart the animation.

    3. Return.

  16. Abort the image request for the pending request.

  17. Set image request to a new image request whose current URL is urlString.

  18. If the current request's state is unavailable or broken, then set the current request to image request. Otherwise, set the pending request to image request.

  19. Let request be the result of creating a potential-CORS request given urlString, "image", and the current state of the element's crossorigin content attribute.

  20. Set request's client to the element's node document's relevant settings object.

  21. If the element uses srcset or picture, set request's initiator to "imageset".

  22. Set request's referrer policy to the current state of the element's referrerpolicy attribute.

  23. Set request's priority to the current state of the element's fetchpriority attribute.

  24. Let delay load event be true if the img's lazy loading attribute is in the Eager state, or if scripting is disabled for the img, and false otherwise.

  25. If the will lazy load element steps given the img return true:

    1. Set the img's lazy load resumption steps to the rest of this algorithm starting with the step labeled fetch the image.

    2. Start intersection-observing a lazy loading element for the img element.

    3. Return.

  26. Fetch the image: Fetch request. Return from this algorithm, and run the remaining steps as part of the fetch's processResponse for the response response.

    The resource obtained in this fashion, if any, is image request's image data. It can be either CORS-same-origin or CORS-cross-origin; this affects the image's interaction with other APIs (e.g., when used on a canvas).

    When delay load event is true, fetching the image must delay the load event of the element's node document until the task that is queued by the networking task source once the resource has been fetched (defined below) has been run.

    This, unfortunately, can be used to perform a rudimentary port scan of the user's local network (especially in conjunction with scripting, though scripting isn't actually necessary to carry out such an attack). User agents may implement cross-origin access control policies that are stricter than those described above to mitigate this attack, but unfortunately such policies are typically not compatible with existing web content.

  27. As soon as possible, jump to the first applicable entry from the following list:

    If the resource type is multipart/x-mixed-replace

    The next task that is queued by the networking task source while the image is being fetched must run the following steps:

    1. If image request is the pending request and at least one body part has been completely decoded, abort the image request for the current request, and upgrade the pending request to the current request.

    2. Otherwise, if image request is the pending request and the user agent is able to determine that image request's image is corrupted in some fatal way such that the image dimensions cannot be obtained, abort the image request for the current request, upgrade the pending request to the current request, and set the current request's state to broken.

    3. Otherwise, if image request is the current request, its state is unavailable, and the user agent is able to determine image request's image's width and height, set the current request's state to partially available.

    4. Otherwise, if image request is the current request, its state is unavailable, and the user agent is able to determine that image request's image is corrupted in some fatal way such that the image dimensions cannot be obtained, set the current request's state to broken.

    Each task that is queued by the networking task source while the image is being fetched must update the presentation of the image, but as each new body part comes in, if the user agent is able to determine the image's width and height, it must prepare the img element's current request for presentation given the img element and replace the previous image. Once one body part has been completely decoded, perform the following steps:

    1. Set the img element's current request's state to completely available.

    2. If maybe omit events is not set or previousURL is not equal to urlString, then queue an element task on the DOM manipulation task source given the img element to fire an event named load at the img element.

    If the resource type and data corresponds to a supported image format, as described below

    The next task that is queued by the networking task source while the image is being fetched must run the following steps:

    1. If the user agent is able to determine image request's image's width and height, and image request is the pending request, set image request's state to partially available.

    2. Otherwise, if the user agent is able to determine image request's image's width and height, and image request is the current request, prepare image request for presentation given the img element and set image request's state to partially available.

    3. Otherwise, if the user agent is able to determine that image request's image is corrupted in some fatal way such that the image dimensions cannot be obtained, and image request is the pending request:

      1. Abort the image request for the current request and the pending request.

      2. Upgrade the pending request to the current request.

      3. Set the current request's state to broken.

      4. Fire an event named error at the img element.

    4. Otherwise, if the user agent is able to determine that image request's image is corrupted in some fatal way such that the image dimensions cannot be obtained, and image request is the current request:

      1. Abort the image request for image request.

      2. If maybe omit events is not set or previousURL is not equal to urlString, then fire an event named error at the img element.

    That task, and each subsequent task that is queued by the networking task source while the image is being fetched, must, if image request is the current request, update the presentation of the image appropriately (e.g., if the image is a progressive JPEG, each packet can improve the resolution of the image).

    Furthermore, the last task that is queued by the networking task source once the resource has been fetched must additionally run these steps:

    1. If image request is the pending request, abort the image request for the current request, upgrade the pending request to the current request, and prepare image request for presentation given the img element.

    2. Set image request to the completely available state.

    3. Add the image to the list of available images using the key key, with the ignore higher-layer caching flag set.

    4. If maybe omit events is not set or previousURL is not equal to urlString, then fire an event named load at the img element.

    そうでなければ

    The image data is not in a supported file format; the user agent must set image request's state to broken, abort the image request for the current request and the pending request, upgrade the pending request to the current request if image request is the pending request, and then, if maybe omit events is not set or previousURL is not equal to urlString, queue an element task on the DOM manipulation task source given the img element to fire an event named error at the img element.

While a user agent is running the above algorithm for an element x, there must be a strong reference from the element's node document to the element x, even if that element is not connected.

To abort the image request for an image request or null image request means to run the following steps:

  1. If image request is null, then return.

  2. Forget image request's image data, if any.

  3. Abort any instance of the fetching algorithm for image request, discarding any pending tasks generated by that algorithm.

To upgrade the pending request to the current request for an img element means to run the following steps:

  1. Set the img element's current request to the pending request.

  2. Set the img element's pending request to null.

4.8.4.3.6 Preparing an image for presentation

To prepare an image for presentation for an image request req given image element img:

  1. Let exifTagMap be the EXIF tags obtained from req's image data, as defined by the relevant codec. [EXIF]

  2. Let physicalWidth and physicalHeight be the width and height obtained from req's image data, as defined by the relevant codec.

  3. Let dimX be the value of exifTagMap's tag 0xA002 (PixelXDimension).

  4. Let dimY be the value of exifTagMap's tag 0xA003 (PixelYDimension).

  5. Let resX be the value of exifTagMap's tag 0x011A (XResolution).

  6. Let resY be the value of exifTagMap's tag 0x011B (YResolution).

  7. Let resUnit be the value of exifTagMap's tag 0x0128 (ResolutionUnit).

  8. If all the following are true:

    • dimX is a positive integer;

    • dimY is a positive integer;

    • resX is a positive floating-point number;

    • resY is a positive floating-point number;

    • physicalWidth × 72 / resX is dimX;

    • physicalHeight × 72 / resY is dimY;

    • resUnit is 2 (Inch),

    then:

    1. If req's image data is CORS-cross-origin, then set img's natural dimensions to dimX and dimY, and scale img's pixel data accordingly.

    2. Otherwise, set req's preferred density-corrected dimensions to a struct with its width set to dimX and its height set to dimY.

  9. Update req's img element's presentation appropriately.

Resolution in EXIF is equivalent to CSS points per inch, therefore 72 is the base for computing size from resolution.

It is not yet specified what would be the case if EXIF arrives after the image is already presented. See issue #4929.

4.8.4.3.7 Selecting an image source

To select an image source given an img element el:

  1. Update the source set for el.

  2. If el's source set is empty, return null as the URL and undefined as the pixel density.

  3. Return the result of selecting an image from el's source set.

To select an image source from a source set given a source set sourceSet:

  1. If an entry b in sourceSet has the same associated pixel density descriptor as an earlier entry a in sourceSet, then remove entry b. Repeat this step until none of the entries in sourceSet have the same associated pixel density descriptor as an earlier entry.

  2. In an implementation-defined manner, choose one image source from sourceSet. Let selectedSource be this choice.

  3. Return selectedSource and its associated pixel density.

4.8.4.3.8 Creating a source set from attributes

When asked to create a source set given a string default source, a string srcset, a string sizes, and an element or null img:

  1. Let source set be an empty source set.

  2. If srcset is not an empty string, then set source set to the result of parsing srcset.

  3. Set source set's source size to the result of parsing sizes with img.

  4. If default source is not the empty string and source set does not contain an image source with a pixel density descriptor value of 1, and no image source with a width descriptor, append default source to source set.

  5. Normalize the source densities of source set.

  6. Return source set.

4.8.4.3.9 Updating the source set

When asked to update the source set for a given img or link element el, user agents must do the following:

  1. Set el's source set to an empty source set.

  2. Let elements be « el ».

  3. If el is an img element whose parent node is a picture element, then replace the contents of elements with el's parent node's child elements, retaining relative order.

  4. Let img be el if el is an img element, otherwise null.

  5. For each child in elements:

    1. If child is el:

      1. Let default source be the empty string.

      2. Let srcset be the empty string.

      3. Let sizes be the empty string.

      4. If el is an img element that has a srcset attribute, then set srcset to that attribute's value.

      5. Otherwise, if el is a link element that has an imagesrcset attribute, then set srcset to that attribute's value.

      6. If el is an img element that has a sizes attribute, then set sizes to that attribute's value.

      7. Otherwise, if el is a link element that has an imagesizes attribute, then set sizes to that attribute's value.

      8. If el is an img element that has a src attribute, then set default source to that attribute's value.

      9. Otherwise, if el is a link element that has an href attribute, then set default source to that attribute's value.

      10. Set el's source set to the result of creating a source set given default source, srcset, sizes, and img.

      11. Return.

        If el is a link element, then elements contains only el, so this step will be reached immediately and the rest of the algorithm will not run.

    2. If child is not a source element, then continue.

    3. If child does not have a srcset attribute, continue to the next child.

    4. Parse child's srcset attribute and let source set be the returned source set.

    5. If source set has zero image sources, continue to the next child.

    6. If child has a media attribute, and its value does not match the environment, continue to the next child.

    7. Parse child's sizes attribute with img, and let source set's source size be the returned value.

    8. If child has a type attribute, and its value is an unknown or unsupported MIME type, continue to the next child.

    9. If child has width or height attributes, set el's dimension attribute source to child. Otherwise, set el's dimension attribute source to el.

    10. Normalize the source densities of source set.

    11. Set el's source set to source set.

    12. Return.

Each img element independently considers its previous sibling source elements plus the img element itself for selecting an image source, ignoring any other (invalid) elements, including other img elements in the same picture element, or source elements that are following siblings of the relevant img element.

4.8.4.3.10 Parsing a srcset attribute

When asked to parse a srcset attribute from an element, parse the value of the element's srcset attribute as follows:

  1. Let input be the value passed to this algorithm.

  2. Let position be a pointer into input, initially pointing at the start of the string.

  3. Let candidates be an initially empty source set.

  4. Splitting loop: Collect a sequence of code points that are ASCII whitespace or U+002C COMMA characters from input given position. If any U+002C COMMA characters were collected, that is a parse error.

  5. If position is past the end of input, return candidates.

  6. Collect a sequence of code points that are not ASCII whitespace from input given position, and let url be the result.

  7. Let descriptors be a new empty list.

  8. If url ends with U+002C (,):

    1. Remove all trailing U+002C COMMA characters from url. If this removed more than one character, that is a parse error.

    Otherwise:

    1. Descriptor tokenizer: Skip ASCII whitespace within input given position.

    2. Let current descriptor be the empty string.

    3. Let state be in descriptor.

    4. Let c be the character at position. Do the following depending on the value of state. For the purpose of this step, "EOF" is a special character representing that position is past the end of input.

      In descriptor

      Do the following, depending on the value of c:

      ASCII whitespace

      If current descriptor is not empty, append current descriptor to descriptors and let current descriptor be the empty string. Set state to after descriptor.

      U+002C COMMA (,)

      Advance position to the next character in input. If current descriptor is not empty, append current descriptor to descriptors. Jump to the step labeled descriptor parser.

      U+0028 LEFT PARENTHESIS (()

      Append c to current descriptor. Set state to in parens.

      EOF

      If current descriptor is not empty, append current descriptor to descriptors. Jump to the step labeled descriptor parser.

      Anything else

      Append c to current descriptor.

      In parens

      Do the following, depending on the value of c:

      U+0029 RIGHT PARENTHESIS ())

      Append c to current descriptor. Set state to in descriptor.

      EOF

      Append current descriptor to descriptors. Jump to the step labeled descriptor parser.

      Anything else

      Append c to current descriptor.

      After descriptor

      Do the following, depending on the value of c:

      ASCII whitespace

      Stay in this state.

      EOF

      Jump to the step labeled descriptor parser.

      Anything else

      Set state to in descriptor. Set position to the previous character in input.

      Advance position to the next character in input. Repeat this step.

      In order to be compatible with future additions, this algorithm supports multiple descriptors and descriptors with parens.

  9. Descriptor parser: Let error be no.

  10. Let width be absent.

  11. Let density be absent.

  12. Let future-compat-h be absent.

  13. For each descriptor in descriptors, run the appropriate set of steps from the following list:

    If the descriptor consists of a valid non-negative integer followed by a U+0077 LATIN SMALL LETTER W character
    1. If the user agent does not support the sizes attribute, let error be yes.

      A conforming user agent will support the sizes attribute. However, user agents typically implement and ship features in an incremental manner in practice.

    2. If width and density are not both absent, then let error be yes.

    3. Apply the rules for parsing non-negative integers to the descriptor. If the result is 0, let error be yes. Otherwise, let width be the result.

    If the descriptor consists of a valid floating-point number followed by a U+0078 LATIN SMALL LETTER X character
    1. If width, density and future-compat-h are not all absent, then let error be yes.

    2. Apply the rules for parsing floating-point number values to the descriptor. If the result is less than 0, let error be yes. Otherwise, let density be the result.

      If density is 0, the natural dimensions will be infinite. User agents are expected to have limits in how big images can be rendered.

    If the descriptor consists of a valid non-negative integer followed by a U+0068 LATIN SMALL LETTER H character

    This is a parse error.

    1. If future-compat-h and density are not both absent, then let error be yes.

    2. Apply the rules for parsing non-negative integers to the descriptor. If the result is 0, let error be yes. Otherwise, let future-compat-h be the result.

    Anything else

    Let error be yes.

  14. If future-compat-h is not absent and width is absent, let error be yes.

  15. If error is still no, then append a new image source to candidates whose URL is url, associated with a width width if not absent and a pixel density density if not absent. Otherwise, there is a parse error.

  16. Return to the step labeled splitting loop.

4.8.4.3.11 Parsing a sizes attribute

When asked to parse a sizes attribute from an element element, with an img element or null img:

  1. Let unparsed sizes list be the result of parsing a comma-separated list of component values from the value of element's sizes attribute (or the empty string, if the attribute is absent). [CSSSYNTAX]

  2. Let size be null.

  3. For each unparsed size in unparsed sizes list:

    1. Remove all consecutive <whitespace-token>s from the end of unparsed size. If unparsed size is now empty, then that is a parse error; continue.

    2. If the last component value in unparsed size is a valid non-negative <source-size-value>, then set size to its value and remove the component value from unparsed size. Any CSS function other than the math functions is invalid. Otherwise, there is a parse error; continue.

    3. If size is auto, and img is not null, and img is being rendered, and img allows auto-sizes, then set size to the concrete object size width of img, in CSS pixels.

      If size is still auto, then it will be ignored.

    4. Remove all consecutive <whitespace-token>s from the end of unparsed size. If unparsed size is now empty:

      1. If this was not the last item in unparsed sizes list, that is a parse error.

      2. If size is not auto, then return size. Otherwise, continue.

    5. Parse the remaining component values in unparsed size as a <media-condition>. If it does not parse correctly, or it does parse correctly but the <media-condition> evaluates to false, continue. [MQ]

    6. If size is not auto, then return size. Otherwise, continue.

  4. Return 100vw.

It is invalid to use a bare <source-size-value> that is a <length> (without an accompanying <media-condition>) as an entry in the <source-size-list> that is not the last entry. However, the parsing algorithm allows it at any point in the <source-size-list>, and will accept it immediately as the size if the preceding entries in the list weren't used. This is to enable future extensions, and protect against simple author errors such as a final trailing comma. A bare auto keyword is allowed to have other entries following it to provide a fallback for legacy user agents.

4.8.4.3.12 Normalizing the source densities

An image source can have a pixel density descriptor, a width descriptor, or no descriptor at all accompanying its URL. Normalizing a source set gives every image source a pixel density descriptor.

When asked to normalize the source densities of a source set source set, the user agent must do the following:

  1. Let source size be source set's source size.

  2. For each image source in source set:

    1. If the image source has a pixel density descriptor, continue to the next image source.

    2. Otherwise, if the image source has a width descriptor, replace the width descriptor with a pixel density descriptor with a value of the width descriptor value divided by source size and a unit of x.

      If the source size is 0, then the density would be infinity, which results in the natural dimensions being 0 by 0.

    3. Otherwise, give the image source a pixel density descriptor of 1x.

4.8.4.3.13 Reacting to environment changes

The user agent may at any time run the following algorithm to update an img element's image in order to react to changes in the environment. (User agents are not required to ever run this algorithm; for example, if the user is not looking at the page any more, the user agent might want to wait until the user has returned to the page before determining which image to use, in case the environment changes again in the meantime.)

User agents are encouraged to run this algorithm in particular when the user changes the viewport's size (e.g. by resizing the window or changing the page zoom), and when an img element is inserted into a document, so that the density-corrected natural width and height match the new viewport, and so that the correct image is chosen when art direction is involved.

  1. Await a stable state. The synchronous section consists of all the remaining steps of this algorithm until the algorithm says the synchronous section has ended. (Steps in synchronous sections are marked with ⌛.)

  2. ⌛ If the img element does not use srcset or picture, its node document is not fully active, it has image data whose resource type is multipart/x-mixed-replace, or its pending request is not null, then return.

  3. ⌛ Let selected source and selected pixel density be the URL and pixel density that results from selecting an image source, respectively.

  4. ⌛ If selected source is null, then return.

  5. ⌛ If selected source and selected pixel density are the same as the element's last selected source and current pixel density, then return.

  6. ⌛ Let urlString be the result of encoding-parsing-and-serializing a URL given selected source, relative to the element's node document.

  7. ⌛ If urlString is failure, then return.

  8. ⌛ Let corsAttributeState be the state of the element's crossorigin content attribute.

  9. ⌛ Let origin be the img element's node document's origin.

  10. ⌛ Let client be the img element's node document's relevant settings object.

  11. ⌛ Let key be a tuple consisting of urlString, corsAttributeState, and, if corsAttributeState is not No CORS, origin.

  12. ⌛ Let image request be a new image request whose current URL is urlString.

  13. ⌛ Set the element's pending request to image request.

  14. End the synchronous section, continuing the remaining steps in parallel.

  15. If the list of available images contains an entry for key, then set image request's image data to that of the entry. Continue to the next step.

    Otherwise:

    1. Let request be the result of creating a potential-CORS request given urlString, "image", and corsAttributeState.

    2. Set request's client to client, set request's initiator to "imageset", and set request's synchronous flag.

    3. Set request's referrer policy to the current state of the element's referrerpolicy attribute.

    4. Set request's priority to the current state of the element's fetchpriority attribute.

    5. Let response be the result of fetching request.

    6. If response's unsafe response is a network error or if the image format is unsupported (as determined by applying the image sniffing rules, again as mentioned earlier), or if the user agent is able to determine that image request's image is corrupted in some fatal way such that the image dimensions cannot be obtained, or if the resource type is multipart/x-mixed-replace, then set the pending request to null and abort these steps.

    7. Otherwise, response's unsafe response is image request's image data. It can be either CORS-same-origin or CORS-cross-origin; this affects the image's interaction with other APIs (e.g., when used on a canvas).

  16. Queue an element task on the DOM manipulation task source given the img element and the following steps:

    1. If the img element has experienced relevant mutations since this algorithm started, then set the pending request to null and abort these steps.

    2. Set the img element's last selected source to selected source and the img element's current pixel density to selected pixel density.

    3. Set the image request's state to completely available.

    4. Add the image to the list of available images using the key key, with the ignore higher-layer caching flag set.

    5. Upgrade the pending request to the current request.

    6. Prepare image request for presentation given the img element.

    7. Fire an event named load at the img element.

4.8.4.4 画像に察しお代替ずしお動䜜するテキストを提䟛に察する芁件
4.8.4.4.1 䞀般的なガむドラむン

特に指定されおいる堎合を陀き、alt属性を指定しなければならず、その倀は空であっおはならない。倀は画像に察しお適切な代甚品でなければならない。alt属性に察する具䜓的な芁件は、次の節で説明するように、画像が衚珟しようずするものによっお異なる。

代替テキストを蚘述する堎合に考慮すべき最も䞀般的な芏則は次のずおりであるすべおの画像をその画像のalt属性のテキストず眮換しおもペヌゞの意味を倉えないこずを意図する。

よっお、䞀般に、代替テキストは、もし画像を含めるこずができなかったならば、䜕が曞かれおいただろうかを考慮するこずで蚘述するこずができる。

この垰結は、alt属性の倀が画像のキャプション、タむトル、凡䟋ずみなすこずができるテキストを含めるべきではないずいうこずである。ナヌザヌが画像の代わりに䜿甚できる代甚テキストを含むはずである。画像を補完するこずを意図しない。title属性は、補足情報のために䜿甚するこずができる。

もう1぀の垰結は、alt属性の倀は既に画像隣接する文で提䟛される情報を繰り返すべきではないずいうこずである。

代替テキストを考える1぀の方法は、画像の存圚があるこずを蚀及するこずなく、電話で誰かに画像を含むペヌゞをどのように読むかを考えるこずである。通垞、画像の代わりにいうものは䜕でも、代替テキストを蚘述するための良いスタヌトである。

ハむパヌリンクを䜜成するa芁玠、たたはbutton芁玠が、テキストコンテンツを持たないが1぀以䞊の画像を含む堎合、alt属性はリンクたたはボタンの目的を䜵せお䌝えるテキストを含たなければならない。

この䟋では、ナヌザヌは、3぀のリストから奜みの色を遞択するよう求められおいる。各色は画像で䞎えられるが、画像を衚瀺しないようにナヌザヌ゚ヌゞェントを蚭定しおいるナヌザヌのために、色名が代わりに䜿甚される

<h1>Pick your color</h1>
<ul>
 <li><a href="green.html"><img src="green.jpeg" alt="Green"></a></li>
 <li><a href="blue.html"><img src="blue.jpeg" alt="Blue"></a></li>
 <li><a href="red.html"><img src="red.jpeg" alt="Red"></a></li>
</ul>

この䟋においお、それぞれのボタンは、ナヌザヌが望む色の出力の皮類を瀺すために、画像の集合を持぀。最初の画像は、代替テキストを提䟛するために䜿甚される。

<button name="rgb"><img src="red" alt="RGB"><img src="green" alt=""><img src="blue" alt=""></button>
<button name="cmyk"><img src="cyan" alt="CMYK"><img src="magenta" alt=""><img src="yellow" alt=""><img src="black" alt=""></button>

各画像はテキストの䞀郚を衚すため、このようにも曞くこずができる

<button name="rgb"><img src="red" alt="R"><img src="green" alt="G"><img src="blue" alt="B"></button>
<button name="cmyk"><img src="cyan" alt="C"><img src="magenta" alt="M"><img src="yellow" alt="Y"><img src="black" alt="K"></button>

しかし、他の代替テキストずずもに、これは動䜜しないかもしれず、それぞれの堎合に1぀の画像にすべおの代替テキストを入れる方が理にかなっおいるかもしれない

<button name="rgb"><img src="red" alt="sRGB profile"><img src="green" alt=""><img src="blue" alt=""></button>
<button name="cmyk"><img src="cyan" alt="CMYK profile"><img src="magenta" alt=""><img src="yellow" alt=""><img src="black" alt=""></button>
4.8.4.4.3 代替グラフィカル衚珟をも぀フレヌズたたは段萜チャヌト、図、グラフ、マップ、むラスト

たずえばフロヌチャヌト、図、グラフ、たたは道順を瀺す簡単な地図など、意味ある物を芖芚的な圢匏で時により明確に蚘述するこずができる。そのような堎合、画像はimg芁玠を䜿っお指定するこずができるが、より少ないテキスト版が䟝然ずしお䞎えられなければならず、そのため画像を衚瀺できないたずえば、非垞に䜎速な接続である、たたはテキストのみのブラりザヌを䜿甚しおいる、たたはハンズフリヌの自動車甚音声りェブブラりザヌによっお読み出されおいるペヌゞを聞いおいる、たたは単に目が芋えないためナヌザヌは䟝然ずしおメッセヌゞが搬送されお理解できる。

テキストはalt属性で指定されなければならず、か぀src属性で指定される画像ず同じメッセヌゞを䌝えなければならない。

代替テキストが画像の説明でなく、画像の代甚品であるこずを認識するこずが重芁である。

次の䟋においお、文圢匏のフロヌチャヌトを蚀い換えるalt属性のテキストをずもなう、画像圢匏のフロヌチャヌトを持぀

<p>In the common case, the data handled by the tokenization stage
comes from the network, but it can also come from script.</p>
<p><img src="images/parsing-model-overview.svg" alt="The Network
passes data to the Input Stream Preprocessor, which passes it to the
Tokenizer, which passes it to the Tree Construction stage. From there,
data goes to both the DOM and to Script Execution. Script Execution is
linked to the DOM, and, using document.write(), passes data to the
Tokenizer."></p>

これは別の䟋であり、説明に画像を含める問題に良い解決策ず悪い解決策を瀺すものである。

たず、これは良い解決策である。このサンプルは、画像が存圚しなかった堎合、代替テキストがちょうど文に入れたであろうものがどうあるべきかを瀺す。

<!-- This is the correct way to do things. -->
<p>
 You are standing in an open field west of a house.
 <img src="house.jpeg" alt="The house is white, with a boarded front door.">
 There is a small mailbox here.
</p>

぀ぎに、これは悪い解決策である。この間違った方法では、画像に察するテキスト眮換の代わりに、代替テキストは画像の簡単な説明である。画像が衚瀺されおいない堎合、テキストは最初の䟋ず同様に流れない。

<!-- This is the wrong way to do things. -->
<p>
 You are standing in an open field west of a house.
 <img src="house.jpeg" alt="A white house, with a boarded front door.">
 There is a small mailbox here.
</p>

title属性に察しお、たたは、この画像をも぀figureのfigcaption芁玠内で適圓かもしれないが"Photo of white house with boarded door"などのテキストは同様に悪い代替テキストずなる。

4.8.4.4.4 代替グラフィカル衚珟をも぀短いフレヌズたたはラベルアむコン、ロゎ

文曞は、アむコン圢匏で情報を含むこずができる。アむコンは、芖芚ブラりザヌのナヌザヌに䞀目で機胜を認識するのを助けるこずを意図する。

ある堎合、アむコンは同じ意味を䌝えるテキストラベルを補足する。これらの堎合においお、alt属性は存圚しなければならないが、空でなければならない。

ここで、アむコンは同じ意味を䌝えるテキストの隣にあるので、空のalt属性を持぀

<nav>
 <p><a href="/help/"><img src="/icons/help.png" alt=""> Help</a></p>
 <p><a href="/configure/"><img src="/icons/configuration.png" alt="">
 Configuration Tools</a></p>
</nav>

他の堎合においお、アむコンは䜕かを意味する蚘述をも぀暪のテキストを持たない。アむコンは自明であるず仮定される。この堎合においお、同等のテキストラベルはalt属性で指定しなければならない。

ここで、ニュヌスサむトの蚘事は、そのトピックを瀺すアむコンが衚瀺される。

<body>
 <article>
  <header>
   <h1>Ratatouille wins <i>Best Movie of the Year</i> award</h1>
   <p><img src="movies.png" alt="Movies"></p>
  </header>
  <p>Pixar has won yet another <i>Best Movie of the Year</i> award,
  making this its 8th win in the last 12 years.</p>
 </article>
 <article>
  <header>
   <h1>Latest TWiT episode is online</h1>
   <p><img src="podcasts.png" alt="Podcasts"></p>
  </header>
  <p>The latest TWiT episode has been posted, in which we hear
  several tech news stories as well as learning much more about the
  iPhone. This week, the panelists compare how reflective their
  iPhones' Apple logos are.</p>
 </article>
</body>

倚くのペヌゞは、䌚瀟、組織、プロゞェクト、バンド、゜フトりェアパッケヌゞ、囜、たたはその他団䜓を衚すロゎ、蚘号、旗、たたぱンブレムを含む。

たずえばペヌゞの芋出しのように、ロゎが団䜓を衚すために䜿甚されおいる堎合、alt属性はロゎによっお衚されるその団䜓の名前を含たなければならない。alt属性は、䌝えられおいるロゎであるずいう事実はないので、単語"ロゎ"のようなテキストを含んではならない。団䜓そのものである。

ロゎが衚すものの名前の暪にロゎが䜿甚される堎合、そのロゎは補足であり、そのalt属性は空でなければならない。

ロゎが単なる装食材料ブランディングずしお、たずえば、ロゎが所属する実䜓を蚀及する蚘事でサむドむメヌゞずしお䜿甚される堎合、玔粋に装食的な画像で䞋蚘の゚ントリヌが適甚される。ロゎが実際に議論されおいる堎合、それは代替グラフィック衚珟ロゎ自䜓、および適甚される䞊蚘の最初の゚ントリヌを持぀語句や段萜ロゎの説明ずしお䜿甚されおいる。

次の断片においお、䞊蚘の䟋のすべおの4぀が存圚しおいる。たず、䌚瀟を衚すために䜿甚されるロゎを芋おみる

<h1><img src="XYZ.gif" alt="The XYZ company"></h1>

次に、䌚瀟名の隣でロゎを䜿甚する段萜を芋おみよう。䜕ら代替テキストを持たない

<article>
 <h2>News</h2>
 <p>We have recently been looking at buying the <img src="alpha.gif"
 alt=""> ΑΒΓ company, a small Greek company
 specializing in our type of product.</p>

この3番目の断片においお、賌買を吟味するarticleの䞀郚ずしお、asideに䜿甚されおいるロゎを持぀

<aside><p><img src="alpha-large.gif" alt=""></p></aside>
 <p>The ΑΒΓ company has had a good quarter, and our
 pie chart studies of their accounts suggest a much bigger blue slice
 than its green and orange slices, which is always a good sign.</p>
</article>

最埌に、ロゎを話題にする意芋蚘事であり、ロゎは代替テキストで詳现に蚘茉される。

<p>Consider for a moment their logo:</p>

<p><img src="/images/logo" alt="It consists of a green circle with a
green question mark centered inside it."></p>

<p>How unoriginal can you get? I mean, oooooh, a question mark, how
<em>revolutionary</em>, how utterly <em>ground-breaking</em>, I'm
sure everyone will rush to adopt those specifications now! They could
at least have tried for some sort of, I don't know, sequence of
rounded squares with varying shades of green and bold white outlines,
at least that would look good on the cover of a blue book.</p>

この䟋は、画像が利甚可胜でない堎合、どのように代替テキストは蚘述すべきかを瀺し、代わりにテキストが䜿甚され、あたかも画像が最初の堎所になかったかのように、テキストは呚囲のテキストにシヌムレスに流れる。

4.8.4.4.5 印刷効果のためにグラフィックにレンダリングされたテキスト

時に、画像がテキストだけで構成されおおり、画像の目的が、テキストをレンダリングするために䜿甚される実際の印刷効果を匷調するだけでなく、単にテキスト自䜓を䌝えるもの。

このような堎合、alt属性が存圚しなければならないが、画像自身に曞かれたものず同じテキストで構成されなければならない。

テキスト"Earth Day"を含むグラフィックを考慮するが、文字はすべおの花や怍物で食られる。グラフィカルなナヌザヌに察しおペヌゞに味わいを加えるために、テキストが単に芋出しずしお䜿甚される堎合、適切な代替テキストはたさに同じテキスト"Earth Day"であり、装食的な蚀及は䜕ら必芁ない

<h1><img src="earthdayheading.png" alt="Earth Day"></h1>

圩色写本は、その画像の䞀郚のグラフィックスを䜿甚するかもしれない。このような状況で代替テキストは、単に画像が衚す文字である。

<p><img src="initials/o.svg" alt="O">nce upon a time and a long long time ago, late at
night, when it was dark, over the hills, through the woods, across a great ocean, in a land far
away, in a small house, on a hill, under a full moon...

画像がUnicodeで衚珟できない文字を衚すために別の方法で䜿甚される堎合、たずえば倖字、異䜓字、たたは新芏の通貚蚘号のような新しい文字においお、テキストによる代替は、たずえば、文字の発音を䞎えるために衚音のひらがなやカタカナを䜿甚するなど、同じものを蚘述するより䌝統的な方法であるべきである。

1997幎からのこの䟋においお、䞭倮の2぀のバヌずずもに枊巻き状のEのように芋える最新匏の通貚蚘号のかわりに、画像を䜿甚しお衚珟される。代替テキストは、文字の発音を䞎える。

<p>Only <img src="euro.png" alt="euro ">5.99!

文字が同じ目的を果たすならば画像を䜿甚すべきでない。たずえば装食のため、たたは適切な文字がないため倖字の堎合のようになど、テキストをテキストで盎接衚珟するこずができない堎合にのみ、画像が適切だろう。

デフォルトのシステムフォントが指定された文字をサポヌトしないため、著者が画像を䜿甚するように誘惑される堎合、りェブフォントは画像よりも優れた解決策である。

4.8.4.4.6 呚囲のテキストの䞀郚をグラフィカルに衚珟

倚くの堎合、画像は実際には単なる補足であり、その存圚は単に呚囲のテキストを匷調するだけである。この堎合、alt属性が存圚しなければならないが、その倀は空文字列でなければならない。

䞀般に画像は、画像を削陀しおもペヌゞの有甚性が匱たるわけでない堎合にこのカテゎリヌに分類されるが、画像を含めるこずは、芖芚ブラりザヌのナヌザヌにずっお抂念を理解するこずがはるかに容易になる。

グラフィカルな圢匏で、前の段萜を繰り返すフロヌチャヌト

<p>The Network passes data to the Input Stream Preprocessor, which
passes it to the Tokenizer, which passes it to the Tree Construction
stage. From there, data goes to both the DOM and to Script Execution.
Script Execution is linked to the DOM, and, using document.write(),
passes data to the Tokenizer.</p>
<p><img src="images/parsing-model-overview.svg" alt=""></p>

この堎合、単なるキャプションで構成する代替テキストを含めるこずが間違っおいるだろう。キャプションが含たれるべき堎合、title属性、たたは、figureおよびfigcaption芁玠のいずれかを䜿甚できる。埌者の堎合、画像は実際に代替グラフィック衚珟を䌎うフレヌズたたは段萜かもしれず、したがっお代替テキストを必芁ずする。

<!-- Using the title="" attribute -->
<p>The Network passes data to the Input Stream Preprocessor, which
passes it to the Tokenizer, which passes it to the Tree Construction
stage. From there, data goes to both the DOM and to Script Execution.
Script Execution is linked to the DOM, and, using document.write(),
passes data to the Tokenizer.</p>
<p><img src="images/parsing-model-overview.svg" alt=""
        title="Flowchart representation of the parsing model."></p>
<!-- Using <figure> and <figcaption> -->
<p>The Network passes data to the Input Stream Preprocessor, which
passes it to the Tokenizer, which passes it to the Tree Construction
stage. From there, data goes to both the DOM and to Script Execution.
Script Execution is linked to the DOM, and, using document.write(),
passes data to the Tokenizer.</p>
<figure>
 <img src="images/parsing-model-overview.svg" alt="The Network leads to
 the Input Stream Preprocessor, which leads to the Tokenizer, which
 leads to the Tree Construction stage. The Tree Construction stage
 leads to two items. The first is Script Execution, which leads via
 document.write() back to the Tokenizer. The second item from which
 Tree Construction leads is the DOM. The DOM is related to the Script
 Execution.">
 <figcaption>Flowchart representation of the parsing model.</figcaption>
</figure>
<!-- This is WRONG. Do not do this. Instead, do what the above examples do. -->
<p>The Network passes data to the Input Stream Preprocessor, which
passes it to the Tokenizer, which passes it to the Tree Construction
stage. From there, data goes to both the DOM and to Script Execution.
Script Execution is linked to the DOM, and, using document.write(),
passes data to the Tokenizer.</p>
<p><img src="images/parsing-model-overview.svg"
        alt="Flowchart representation of the parsing model."></p>
<!-- Never put the image's caption in the alt="" attribute! -->

グラフィカルな圢匏で、前の段萜を繰り返すグラフ

<p>According to a study covering several billion pages,
about 62% of documents on the web in 2007 triggered the Quirks
rendering mode of web browsers, about 30% triggered the Almost
Standards mode, and about 9% triggered the Standards mode.</p>
<p><img src="rendering-mode-pie-chart.png" alt=""></p>
4.8.4.4.7 補助画像

時には、画像はコンテンツに重芁ではないが、それにもかかわらず、玔粋に装食的でもテキストず完党に冗長でもないこずがある。この堎合、alt属性は存圚しなければならず、か぀その倀は空の文字列、たたは画像が䌝える情報のテキスト衚珟のいずれかであるべきである。画像が画像のタむトルを䞎えるキャプションを持぀堎合、非芖芚読者に盞圓な混乱を䞎えるこずになるのでalt属性の倀は空であっおはならない。

個人の顔が画像で瀺されおいる政治家に関するニュヌス蚘事を考えおみる。ニュヌス蚘事に関連するので、画像は玔粋に装食的ではない。政治家がどのように芋えるかを瀺すので、画像はいずれかのニュヌス蚘事ずも完党に冗長ではない。代替テキストを提䟛する必芁があるかどうかは、画像が本文の解釈に圱響を䞎えるかどうかによっお決定されるオヌサリングの決定である。

この最初の倉圢䟋においお、画像はコンテキストなしで瀺され、か぀䞀切の代替テキストが提䟛されない

<p><img src="president.jpeg" alt=""> Ahead of today's referendum,
the President wrote an open letter to all registered voters. In it, she admitted that the country was
divided.</p>

画像が顔のみである堎合、その画像を説明する際に倀は存圚しないかもしれない。個人が赀髪たたは金髪を持぀かどうか、個人が癜い肌たたは黒い肌を持぀かどうか、個人が片目たたは䞡目を持぀かどうか、読者に興味のないこずである。

しかし、画像がより動的である、たずえば怒る、非垞に幞せ、たたはひどく萜ち蟌んだなどの政治家を瀺す堎合、䞀郚の代替テキストは、文章のトヌンを蚭定する際に有甚であり、そうでなければ芋逃されるかもしれない

<p><img src="president.jpeg" alt="The President is sad.">
Ahead of today's referendum, the President wrote an open letter to all
registered voters. In it, she admitted that the country was divided.
</p>
<p><img src="president.jpeg" alt="The President is happy!">
Ahead of today's referendum, the President wrote an open letter to all
registered voters. In it, she admitted that the country was divided.
</p>

個人が"悲しい"か"幞せ"かは、段萜の残りの郚分の解釈に違いをもたらす。圌女は、囜が分割されおいるこずに䞍満を持っおいるず蚀っおいるのか、それずも囜は分割される可胜性があるずいう芋通しは 圌女の政治的キャリアにずっお適しおいるず蚀っおいるのか 解釈は、画像に基づいお倉化する。

画像がキャプションを持぀堎合、代替テキストを含むこずはキャプションが䜕を参照するかに぀いおの混乱を非ビゞュアルナヌザヌに残すこずを避ける。

<p>Ahead of today's referendum, the President wrote an open letter to
all registered voters. In it, she admitted that the country was divided.</p>
<figure>
 <img src="president.jpeg"
      alt="A high forehead, cheerful disposition, and dark hair round out the President's face.">
 <figcaption> The President of Ruritania. Photo © 2014 PolitiPhoto. </figcaption>
</figure>
4.8.4.4.8 情報を远加しない、玔粋に装食的な画像

画像が装食的であるが特にペヌゞ固有でない堎合―たずえばサむト党䜓のデザむンスキヌムの䞀郚を圢成する画像のような―画像は、文曞のマヌクアップでなく、サむトのCSSで指定すべきである。

しかし、呚囲のテキストで議論されないが、䟝然ずしお䞀郚の関連性を持぀装食的な画像はimg芁玠を䜿甚しお、ペヌゞに含めるこずが可胜である。そのような画像は装食的であるが、䟝然ずしおコンテンツの䞀郚に由来する。この堎合、alt属性が存圚しなければならないが、その倀は空文字列でなければならない。

詩を暗唱するペヌゞで、Burning Manのむベント、たたは詩にむンスパむアされた絵画の画像に぀いおのブログ投皿でBlack Rock Cityの颚景の写真のようなものを含むものが関連するにも関わらず、画像が玔粋に装食的である䟋。次の断片は、最初の詩の行のみがこの断片に含たれる埌者の堎合の䟋を瀺す

<h1>The Lady of Shalott</h1>
<p><img src="shalott.jpeg" alt=""></p>
<p>On either side the river lie<br>
Long fields of barley and of rye,<br>
That clothe the wold and meet the sky;<br>
And through the field the road run by<br>
To many-tower'd Camelot;<br>
And up and down the people go,<br>
Gazing where the lilies blow<br>
Round an island there below,<br>
The island of Shalott.</p>

画像が小さな画像ファむルに分割されおいる堎合、再床完党な画像を圢成するために共に衚瀺され、画像の1぀は、党䜓ずしおの絵に適するだろう関連芏則に埓っお蚭定されたalt属性を持たなければならず、残りのすべおの画像は、空のalt属性を持たなければならない。

次の䟋においお、XYZ瀟の䌚瀟のロゎを衚す絵が2枚に分割されおおり、1枚目は文字"XYZ"を含み、2枚目は単語"Corp"をも぀。代替テキスト "XYZ Corp"は、最初の画像ですべおである。

<h1><img src="logo1.png" alt="XYZ Corp"><img src="logo2.png" alt=""></h1>

次の䟋においお、評䟡は、3぀の塗り぀ぶされた星ず、2぀の䞭抜きの星ずしお瀺される。代替テキストは"★★★☆☆"かもしれないが、代わりに著者は、より芪切な圢匏"3 out of 5"の評䟡を䞎えるようにした。これは最初の画像の代替テキストであり、残りは空癜の代替テキストを持぀。

<p>Rating: <meter max=5 value=3><img src="1" alt="3 out of 5"
  ><img src="1" alt=""><img src="1" alt=""><img src="0" alt=""
  ><img src="0" alt=""></meter></p>

䞀般にむメヌゞマップは、リンク甚の画像をスラむスする代わりに䜿甚されるべきである。

画像が確かにスラむスされ、スラむスされた画像のコンポヌネントのいずれかがリンクの唯䞀のコンテンツである堎合、リンクあたりの1぀の画像は、リンクの目的を衚すalt属性で代替テキストを持たなければならない。

次の䟋においお、ナヌザヌが冒険䞭の巊偎たたは右偎を遞ぶこずができるように、異なる画像で巊付属ず右付属のそれぞれず、飛行スパゲッティモンスタヌ゚ンブレムを衚す絵である。

<h1>The Church</h1>
<p>You come across a flying spaghetti monster. Which side of His
Noodliness do you wish to reach out for?</p>
<p><a href="?go=left" ><img src="fsm-left.png"  alt="Left side. "></a
  ><img src="fsm-middle.png" alt=""
  ><a href="?go=right"><img src="fsm-right.png" alt="Right side."></a></p>
4.8.4.4.11 コンテンツのキヌパヌト

堎合によっおは、画像はコンテンツの重芁な郚分である。たずえば、これは、フォトギャラリヌの䞀郚であるペヌゞに圓おはたるかもしれない。画像はその画像を含むペヌゞの党䜓の芁点である。

コンテンツの重芁な郚分である画像の代替テキストを提䟛する方法は、画像の出所に䟝存する。

䞀般的な堎合

提䟛される詳现な代替テキストで可胜な堎合、たずえば、画像が雑誌のレビュヌでの䞀連のスクリヌンショットや、挫画の䞀郚、たたはその写真に関するブログ゚ントリヌでの写真である堎合、画像に察しお適切に提䟛されるようなテキストがalt属性のコンテンツずしお指定されなければならない。

代替テキストを䌎う、新しいOSに぀いおのギャラリヌでのスクリヌンショット

<figure>
 <img src="KDE%20Light%20desktop.png"
      alt="The desktop is blue, with icons along the left hand side in
           two columns, reading System, Home, K-Mail, etc. A window is
           open showing that menus wrap to a second line if they
           cannot fit in the window. The window has a list of icons
           along the top, with an address bar below it, a list of
           icons for tabs along the left edge, a status bar on the
           bottom, and two panes in the middle. The desktop has a bar
           at the bottom of the screen with a few buttons, a pager, a
           list of open applications, and a clock.">
 <figcaption>Screenshot of a KDE desktop.</figcaption>
</figure>

財務レポヌトのグラフ

<img src="sales.gif"
     title="Sales graph"
     alt="From 1998 to 2005, sales increased by the following percentages
     with each year: 624%, 75%, 138%, 40%, 35%, 9%, 21%">

"sales graph"は、売り䞊げグラフに察する代替テキストずしお䞍十分であるこずに泚意する。良いキャプションずされるテキストは、䞀般に眮換テキストずしおは適さない。

完党な蚘述を無芖する画像

ある堎合においお、画像の性質は、培底した代替テキストを提䟛するこずが珟実的ではないかもしれない。たずえば、画像は䞍鮮明であったり、耇雑なフラクタルかもしれず、詳现な地圢図であるかもしれない。

この堎合、alt属性は、適切な代替テキストが含たれなければならないが、それはやや短いかもしれない。

単に画像を正しく扱うこずのできるテキストが存圚しないのである。たずえば、ロヌルシャッハ・むンクブロットテストを蚘述するための有甚な蚀及はほずんどない。しかし、短い説明であっおも、ただ䜕もないよりたしである

<figure>
 <img src="/commons/a/a7/Rorschach1.jpg" alt="A shape with left-right
 symmetry with indistinct edges, with a small gap in the center, two
 larger gaps offset slightly from the center, with two similar gaps
 under them. The outline is wider in the top half than the bottom
 half, with the sides extending upwards higher than the center, and
 the center extending below the sides.">
 <figcaption>A black outline of the first of the ten cards
 in the Rorschach inkblot test.</figcaption>
</figure>

以䞋は、代替テキストの非垞に悪い甚法であろうこずに泚意する

<!-- This example is wrong. Do not copy it. -->
<figure>
 <img src="/commons/a/a7/Rorschach1.jpg" alt="A black outline
 of the first of the ten cards in the Rorschach inkblot test.">
 <figcaption>A black outline of the first of the ten cards
 in the Rorschach inkblot test.</figcaption>
</figure>

このような代替テキストのキャプションを含むこずは、実甚的でない。なぜなら、䞀床でもキャプションを読んだり聞いたこずがあった堎合、2回以䞊助けず、画像を持たないナヌザヌに察しおキャプションを効果的に重耇するためである。

完党な説明を芆す画像の別の䟋は、定矩により、詳现で無限であるフラクタルである。

次の䟋は、マンデルブロ集合の画像の完党なビュヌの代替テキストを提䟛する1぀の可胜な方法を瀺す。

<img src="ms1.jpeg" alt="The Mandelbrot set appears as a cardioid with
its cusp on the real axis in the positive direction, with a smaller
bulb aligned along the same center line, touching it in the negative
direction, and with these two shapes being surrounded by smaller bulbs
of various sizes.">

同様に、人の顔の写真は、たずえば䌝蚘においお、コンテンツにかなり関連し、コンテンツの鍵ず考えるこずができるが、テキストを完党に代替するのは困難である

<section class="bio">
 <h1>A Biography of Isaac Asimov</h1>
 <p>Born <b>Isaak Yudovich Ozimov</b> in 1920, Isaac was a prolific author.</p>
 <p><img src="headpics/asimov.jpeg" alt="Isaac Asimov had dark hair, a tall forehead, and wore glasses.
 Later in life, he wore long white sideburns."></p>
 <p>Asimov was born in Russia, and moved to the US when he was three years old.</p>
 <p>...</p>
</section>

そのような堎合、そのようなテキストは、画像の存圚を報告するブラりザヌ自䜓に冗長になるため、代替テキストで画像自䜓の存圚ぞの参照を含むこずは䞍必芁である実際に掚奚されない。たずえば、代替テキストが"アむザック・アシモフの写真"であった堎合、適合するナヌザヌ゚ヌゞェントはより有甚な"画像アむザック・アシモフは黒い髪、長い額で、県鏡をかけ..."よりもむしろ"画像アむザック・アシモフの写真"ずしお読み䞊げるかもしれない。

コンテンツが未知である画像

画像が任意の関連する代替テキストのない䞀郚の自動化された方法で埗られるたずえばりェブカメラなど、たたはペヌゞが、ナヌザヌが適切なたたは有甚な代替テキストを提䟛できない堎所でのナヌザヌが提䟛する画像を䜿甚するスクリプトによっお生成されおいるたずえば写真共有サむト、たたは著者自身が、画像が䜕を衚すのかを知らないたずえばブログで画像を共有する芖芚障害者の写真家のいずれかなどの、䞀郚の䞍幞な䟋においお、䜿甚可胜な代替テキストがたったく存圚しないかもしれない。

そのような堎合、alt属性を省略しおもよいが、次のいずれかの条件をさらに満たさなければならない

そのような堎合は最小限に保たれるべきである。実際の代替テキストを提䟛する胜力を有する著者のわずかな可胜性がある堎合、alt属性の省略を蚱容しないだろう。

サむトがキャプション以倖のメタデヌタを甚いお画像を受信した堎合、写真共有サむトの写真は、次のようにマヌクアップできる

<figure>
 <img src="1100670787_6a7c664aef.jpg">
 <figcaption>Bubbles traveled everywhere with us.</figcaption>
</figure>

しかし、画像の重芁郚分の詳现な説明が、ナヌザヌから取埗しおペヌゞに含たれる堎合、これはより良いだろう。

ナヌザヌが撮圱した写真での芖芚障害者ナヌザヌのブログを瀺す。最初に、ナヌザヌはショヌを撮った写真の任意のアむデアを持たないかもしれない

<article>
 <h1>I took a photo</h1>
 <p>I went out today and took a photo!</p>
 <figure>
  <img src="photo2.jpeg">
  <figcaption>A photograph taken blindly from my front porch.</figcaption>
 </figure>
</article>

しかし最終的に、ナヌザヌは友人による画像の説明を取埗するかもしれず、その堎合代替テキストを含めるこずができる

<article>
 <h1>I took a photo</h1>
 <p>I went out today and took a photo!</p>
 <figure>
  <img src="photo2.jpeg" alt="The photograph shows my squirrel
  feeder hanging from the edge of my roof. It is half full, but there
  are no squirrels around. In the background, out-of-focus trees fill the
  shot. The feeder is made of wood with a metal grate, and it contains
  peanuts. The edge of the roof is wooden too, and is painted white
  with light blue streaks.">
  <figcaption>A photograph taken blindly from my front porch.</figcaption>
 </figure>
</article>

時ずしお画像党䜓の芁点は、テキストの説明が利甚できず、ナヌザヌが説明を提䟛する。たずえば、CAPTCHA画像のポむントは、ナヌザヌが文字通りグラフィックを読むこずができるかどうかを確認するこずにある。これはCAPTCHAをマヌクアップする1぀の方法であるtitle属性に泚目する

<p><label>What does this image say?
<img src="captcha.cgi?id=8934" title="CAPTCHA">
<input type=text name=captcha></label>
(If you cannot see the image, you can use an <a
href="?audio">audio</a> test instead.)</p>

もう1぀の䟋は、画像を衚瀺し、正しい代替テキストをも぀ペヌゞを曞く目的に察しお正確に代替テキストを求める゜フトりェアである。そのようなペヌゞは次のように、画像のテヌブルを持぀こずができる

<table>
 <thead>
  <tr> <th> Image <th> Description
 <tbody>
  <tr>
   <td> <img src="2421.png" title="Image 640 by 100, filename 'banner.gif'">
   <td> <input name="alt2421">
  <tr>
   <td> <img src="2422.png" title="Image 200 by 480, filename 'ad3.gif'">
   <td> <input name="alt2422">
</table>

この䟋ですら、できる限り倚くの有甚な情報が䟝然ずしおtitle属性に含たれるこずに泚意する。

䞀郚のナヌザヌは、たったく画像を䜿甚できないたずえば、非垞に䜎速な接続である、テキストのみのブラりザヌを䜿甚しおいる、ハンズフリヌの自動車声りェブブラりザヌで読みあげおペヌゞを聞いおいる、たたは単に目が芋えないので、alt属性は省略するこずが蚱可されるよりむしろ、䞊蚘の䟋のようにたったく代替テキストが利甚できず、䜕も利甚できない堎合に、眮換テキストを備えるのである。著者の䞀郚による努力の欠劂は、alt属性を省略するための蚱容可胜な理由でない。

4.8.4.4.12 ナヌザヌを意図しない画像

䞀般に、著者は画像を衚瀺する以倖の目的でimg芁玠を䜿甚するこずは避けるべきである。

img芁玠が画像を衚瀺する以倖の目的で䜿甚されおいる堎合、たずえば、ペヌゞビュヌをカりントするサヌビスの䞀郚ずしお甚いる堎合、alt属性は空文字列でなければならない。

このような堎合、widthずheight属性は、䞡方ずも0に蚭定すべきである。

4.8.4.4.13 画像を閲芧できるこずが知られおいる特定の人のために意図された電子メヌルたたは私的文曞における画像

この節は、公にアクセス可胜な、すなわち、りェブサむト䞊の文曞、公開メヌリングリストに送信された電子メヌル、たたは゜フトりェアのドキュメントなど、察象ずなる読者が必ずしも個人的に著者に知られおいない文曞には適甚されない。

画像が、画像を芋るこずができるこずが知られおいる特定の人に向けた私的通信たずえばHTML圢匏の電子メヌルなどに含たれる堎合、alt属性は省略されおもよい。しかし、このようなケヌスでさえも、著者は、䞊蚘の゚ントリヌで説明したように、関連する画像の皮類に応じお適切に代替テキストを含めるこずを匷く勧める。結果ずしお、ナヌザヌが画像をサポヌトしないメヌルクラむアントを䜿甚する堎合、たたは文曞が画像を簡単に芋るこずのできないナヌザヌに転送される堎合、電子メヌルは䟝然ずしお有甚である。

4.8.4.4.14 Guidance for markup generators

Markup generators (such as WYSIWYG authoring tools) should, wherever possible, obtain alternative text from their users. However, it is recognized that in many cases, this will not be possible.

For images that are the sole contents of links, markup generators should examine the link target to determine the title of the target, or the URL of the target, and use information obtained in this manner as the alternative text.

For images that have captions, markup generators should use the figure and figcaption elements, or the title attribute, to provide the image's caption.

As a last resort, implementers should either set the alt attribute to the empty string, under the assumption that the image is a purely decorative image that doesn't add any information but is still specific to the surrounding content, or omit the alt attribute altogether, under the assumption that the image is a key part of the content.

Markup generators may specify a generator-unable-to-provide-required-alt attribute on img elements for which they have been unable to obtain alternative text and for which they have therefore omitted the alt attribute. The value of this attribute must be the empty string. Documents containing such attributes are not conforming, but conformance checkers will silently ignore this error.

This is intended to avoid markup generators from being pressured into replacing the error of omitting the alt attribute with the even more egregious error of providing phony alternative text, because state-of-the-art automated conformance checkers cannot distinguish phony alternative text from correct alternative text.

Markup generators should generally avoid using the image's own filename as the alternative text. Similarly, markup generators should avoid generating alternative text from any content that will be equally available to presentation user agents (e.g., web browsers).

This is because once a page is generated, it will typically not be updated, whereas the browsers that later read the page can be updated by the user, therefore the browser is likely to have more up-to-date and finely-tuned heuristics than the markup generator did when generating the page.

4.8.4.4.15 Guidance for conformance checkers

A conformance checker must report the lack of an alt attribute as an error unless one of the conditions listed below applies: