Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1010301 of <picture>

  • Revision slug: Web/HTML/Element/picture
  • Revision title: <picture>
  • Revision id: 1010301
  • Created:
  • Creator: slimsag
  • Is current revision? No
  • Comment Tag as experimental

Revision Content

{{HTMLRef}}{{SeeCompatTable}}

The HTML <picture> element is a container used to specify multiple {{HTMLElement("source")}} elements for a specific {{HTMLElement("img")}} contained in it. The browser will choose the most suitable source according to the current layout of the page (the constraints of the box the image will appear in) and the device it will be displayed on (e.g. a normal or hiDPI device.)

Usage Context

Content categories Flow content, phrasing content, embedded content
Permitted content Zero or more {{HTMLElement("source")}} elements, followed by one {{HTMLElement("img")}} element, optionally intermixed with script-supporting elements.
Tag omission {{no_tag_omission}}
Permitted parent elements Any element that allows embedded content.
DOM interface {{domxref("HTMLPictureElement")}}

Attributes

This element includes only global attributes.

Example 1: Using the media attribute

The media attribute lets you specify a media query that the user agent will evaluate to select a {{HTMLElement("source")}} element. If the media query evaluates to false, the {{HTMLElement("source")}} element is skipped.

<picture>
 <source srcset="mdn-logo-wide.png" media="(min-width: 600px)">
 <img src="mdn-logo-narrow.png" alt="MDN">
</picture>

Example 2: Using the type attribute

The type attribute lets you specify a MIME type for the resource(s) given in the {{HTMLElement("source")}} element's srcset attribute. If the user agent does not support the given type, the {{HTMLElement("source")}} element is skipped.

​<picture>
 <source srcset="mdn-logo.svg" type="image/svg+xml">
 <img src="mdn-logo.png" alt="MDN">
</picture>

Specifications

Specification Status Comment
{{SpecName('HTML WHATWG', 'embedded-content.html#the-picture-element', '<picture>')}} {{Spec2('HTML WHATWG')}} Initial definition

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 38 {{CompatGeckoDesktop("38")}} Edge 13 25 9.1
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 38 {{CompatGeckoMobile("38")}} {{CompatNo}} 25 iOS 9.3

See also

  • {{HTMLElement("img")}} element

Revision Source

<div>{{HTMLRef}}{{SeeCompatTable}}</div>

<p>The <strong>HTML <code>&lt;picture&gt;</code> element</strong> is a container used to specify multiple {{HTMLElement("source")}} elements for a specific {{HTMLElement("img")}} contained in it. The browser will choose the most suitable source according to the current layout of the page (the constraints of the box the image will appear in) and the device it will be displayed on (e.g. a normal or hiDPI device.)</p>

<h2 id="Usage_Context">Usage Context</h2>

<table class="properties">
 <tbody>
  <tr>
   <th scope="row"><a href="/en-US/docs/Web/HTML/Content_categories">Content categories</a></th>
   <td><a href="/en-US/docs/Web/HTML/Content_categories#Flow_content">Flow content</a>, phrasing content, embedded content</td>
  </tr>
  <tr>
   <th scope="row">Permitted content</th>
   <td>Zero or more {{HTMLElement("source")}} elements, followed by one {{HTMLElement("img")}} element, optionally intermixed with script-supporting elements.</td>
  </tr>
  <tr>
   <th scope="row">Tag omission</th>
   <td>{{no_tag_omission}}</td>
  </tr>
  <tr>
   <th scope="row">Permitted parent elements</th>
   <td>Any element that allows embedded content.</td>
  </tr>
  <tr>
   <th scope="row">DOM interface</th>
   <td>{{domxref("HTMLPictureElement")}}</td>
  </tr>
 </tbody>
</table>

<h2 id="Attributes">Attributes</h2>

<p>This element includes only <a href="/en-US/docs/Web/HTML/Global_attributes">global attributes</a>.</p>

<h2 id="Example_1_Using_the_media_attribute">Example 1: Using the <code>media</code> attribute</h2>

<p>The <code>media</code> attribute lets you specify a media query that the user agent will evaluate to select a {{HTMLElement("source")}} element. If the media query evaluates to <code>false</code>, the {{HTMLElement("source")}} element is skipped.</p>

<pre class="brush: html">
&lt;picture&gt;
 &lt;source srcset="mdn-logo-wide.png" media="(min-width: 600px)"&gt;
 &lt;img src="mdn-logo-narrow.png" alt="MDN"&gt;
&lt;/picture&gt;
</pre>

<h2 id="Example_2_Using_the_type_attribute">Example 2: Using the <code>type</code> attribute</h2>

<p>The <code>type</code> attribute lets you specify a MIME type for the resource(s) given in the {{HTMLElement("source")}} element's srcset attribute. If the user agent does not support the given type, the {{HTMLElement("source")}} element is skipped.</p>

<pre class="brush: html">
​&lt;picture&gt;
 &lt;source srcset="mdn-logo.svg" type="image/svg+xml"&gt;
 &lt;img src="mdn-logo.png" alt="MDN"&gt;
&lt;/picture&gt;
</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('HTML WHATWG', 'embedded-content.html#the-picture-element', '&lt;picture&gt;')}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>38</td>
   <td>{{CompatGeckoDesktop("38")}}</td>
   <td>Edge 13</td>
   <td>25</td>
   <td>9.1</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>38</td>
   <td>{{CompatGeckoMobile("38")}}</td>
   <td>{{CompatNo}}</td>
   <td>25</td>
   <td>iOS 9.3</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{HTMLElement("img")}} element</li>
</ul>
Revert to this revision