HTML <source> srcset属性

❮HTML<source>タグ

2つのソースファイルとフォールバック画像を含む<picture>要素:

<picture>
  <source media="(min-width:650px)" srcset="img_pink_flowers.jpg">
  <source media="(min-width:465px)" srcset="img_white_flower.jpg">
  <img src="img_orange_flowers.jpg" alt="Flowers" style="width:auto;">
</picture>

定義と使用法

このsrcset属性は、さまざまな状況で使用する画像のURLを指定します。

この属性は、<source>で使用される場合に必要です <picture>


ブラウザのサポート

表の数字は、属性を完全にサポートする最初のブラウザーバージョンを示しています。

Attribute
srcset 38.0 13.0  38.0 9.1 25.0

構文

<source srcset="URL">

属性値

Value Description
URL Specifies the URL of the image.

Possible values:

  • An absolute URL - points to another web site (like href="http://www.example.com/flower.jpg")
  • A relative URL - points to a file within a web site (like href="flower.jpg")

❮HTML<source>タグ