diff --git a/ResponsiveImages.html b/ResponsiveImages.html index 9802953f..51d19572 100644 --- a/ResponsiveImages.html +++ b/ResponsiveImages.html @@ -1,11 +1,10 @@
-Through the introduction of a picture
element, this specification adds functionality to HTML that allows authors to list a range of images which may be suitable for a range of device capabilities and different usage scenarios. The ability to adapt content to the constraints and capabilities of devices and different usage scenarios is commonly referred to as "responsive design".
- This allows user agents to be more responsive to a wide spectrum of browsing scenarios, ranging from simple mobile devices to desktop browsers scenarios, when selecting which image resources to download and display for an end-user. This includes, but is not limited to, the selection of images most suited for either high or low density displays and screen resolutions on range of devices, are well as responsive selection of images based on printer's dpi and color reproduction capabilities.
This document was proposed by the Responsive Images Community Group as a solution to bug 18384.
-This specification describes the conformance criteria for user agents (relevant to implementors) and documents (relevant to authors and authoring tool implementors).
-Implementations that use ECMAScript to expose the APIs defined in this specification MUST implement them in a manner consistent with the ECMAScript Bindings defined in the Web IDL specification [[!WEBIDL]].
+ + + +Through the combination of a new picture
element and a new the srcset
attribute for the existing source
element, this specification adds functionality to HTML that allows authors to list a range of images which may be suitable for a range of device capabilities and different usage scenarios. The ability to adapt content to the constraints and capabilities of devices and different usage scenarios is commonly referred to as "responsive design".
+ This allows user agents to be more responsive to a wide spectrum of browsing scenarios, ranging from simple mobile devices to desktop browsers scenarios, when selecting which image resources to download and display for an end-user. This includes, but is not limited to, the selection of images most suited for either high or low density displays and screen resolutions on range of devices, are well as responsive selection of images based on printer's dpi and color reproduction capabilities.
This document was proposed by the Responsive Images Community Group as a solution to bug 18384.
+This specification describes the conformance criteria for user agents (relevant to implementors) and documents (relevant to authors and authoring tool implementors).
+Implementations that use ECMAScript to expose the APIs defined in this specification MUST implement them in a manner consistent with the ECMAScript Bindings defined in the Web IDL specification [[!WEBIDL]].
+The following terms are used throughout this specification so they are gathered here for the readers convenience. The following list of terms is not exhaustive; other terms are defined throughout this specification.
-The follow terms are defined by the [[!HTML5]] specification: img
element,
- source
element,
- media
resource,
- resource selection algorithm,
- fallback content,
- valid non-empty URL potentially surrounded by spaces
- and valid media query.
The term media type is defined by the Multipurpose Internet Mail Extensions (MIME) Part Two: Media Types specification [[!RFC2046]].
- -The image-set notation - microsyntax is defined by the CSS Image Values and Replaced Content Module Level 4 Specification [[!CSS4-IMAGES]].
-The techniques for providing useful text alternatives for img
elements are defined by the HTML5: Techniques for providing useful text alternatives Specification [[!ALT-TECHNIQUES]].
The following terms are used throughout this specification so they are gathered here for the readers convenience. The following list of terms is not exhaustive; other terms are defined throughout this specification.
+The follow terms are defined by the [[!HTML5]] specification: img
element, source
element, media
resource, fallback content, valid non-empty URL potentially surrounded by spaces and valid media query.
The image-set notation microsyntax is defined by the CSS Image Values and Replaced Content Module Level 4 Specification [[!CSS4-IMAGES]].
+The techniques for providing useful text alternatives for img
elements are defined by the HTML5: Techniques for providing useful text alternatives Specification [[!ALT-TECHNIQUES]].
picture
elementpicture
elementsource
elements.img
element as fallback content.img
element, serving as fallback content.crossorigin
usemap
ismap
width
height
HTMLImageElement
.The picture
element used for displaying an image that can come from a range of sources. Which image the user agent displays depends on [forthcoming algorithm].
For user agents that don't support the picture
element, an author can provide an img
element as fallback content. User agents SHOULD NOT show this content to the user: it is intended for legacy user agents that do not support picture
, so that a legacy img
element can be shown instead.
Authoring requirement: as with the img
element, the picture
element must not be used as a layout tool. In particular, picture elements should not be used to display transparent images, as they rarely convey meaning and rarely add anything useful to the document.
Sample picture element markup:
- -<picture> +The
+picture
element used for displaying an image that can come from a range of sources (seesrcset
attribute). Which image the user agent displays depends on the + algoithm for deriving the source image.The chosen image is the embedded content.
+The
+crossorigin
attribute is a CORS settings attribute. Its purpose is to allow images from third-party sites that allow cross-origin access to be used with canvas.The width and height attributes represent the dimensions of the visual content of the element (the width and height respectively, relative to the nominal direction of the output medium), in CSS pixels. They are in everyway the same as those of an
+img
element. The value of attributes, if specified, are valid non-negative integers.For user agents that don't support the
+picture
element, an author can provide animg
element as fallback content. User agents SHOULD NOT show this content to the user: it is intended for legacy user agents that do not supportpicture
, so that a legacyimg
element can be shown instead.Authoring requirement: as with the
+img
element, documents must not use thepicture
element as a layout tool. In particular, picture elements should not be used to display transparent images, as they rarely convey meaning and rarely add anything useful to the document.Example of usage
+Sample picture element markup:
+<picture width="500" height="500"> <source media="(min-width: 45em)" srcset="large-1.jpg 1x, large-2.jpg 2x"> <source media="(min-width: 18em)" srcset="med-1.jpg 1x, med-2.jpg 2x"> <source srcset="small-1.jpg 1x, small-2.jpg 2x"> <img src="small-1.jpg" alt=""> -</picture>- -- + <p>Accessible text</p> +</picture>Differences from
-img
elementUnlike the
-img
element, which is limited to pointing to a single image resource, thepicture
element is intended to allow an author to reference many different image sources that the browser can then choose based on a media query or some other relevant condition. This means that a user agent can best select an image source that is most suitable for available display size, pixel density, or possibly even network bandwidth. Or the most suitable image source may be a different version of an image that has been modified by the author to be suitable for a particular use (see: art direction use case).It is also not possible to assign a source directly to a picture element. For that case, an author needs to use an
-img
element instead.
img
elementUnlike the img
element, which is limited to pointing to a single image resource, the picture
element is intended to allow an author to reference many different image sources that the browser can then choose based on a media query or some other relevant browsing situation or contraint. This means that a user agent can best select an image source that is most suitable for available display size, pixel density, or possibly even network bandwidth. Or the most suitable image source may be a different version of an image that has been modified by the author to be suitable for a particular use (see: art direction use case).
It is RECOMMENDED that for cases where a single image source is available, and where no responsive adaption is needed, authors use the img
element.
When used with the picture
element, a document SHOULD only contain source
elements need to represent the same subject matter, but cropping and zooming can differ.
When used with the picture
element, a document SHOULD only contain source
elements need to represent the same subject matter, while cropping and zooming can differ.
srcset
attribute The srcset
attribute of the source
element is is used to refer to alternate media resources for a single image at different resolutions. The expected value of the attribute is a comma-separated list of valid non-empty URL potentially surrounded by spaces that makes use of the image-set notation micosyntax.
srcset
attribute The srcset
attribute of the source
element is is used to refer to alternate media resources for a single image at different resolutions. The expected value of the attribute is a comma-separated list of valid non-empty URL potentially surrounded by spaces that matches the valid-srcset
production:
valid-srcset = [ <image-set-decl>, ]* [ <image-set-decl> | <color>] ) +<image-set-decl> = [ <image> | <string> ] <resolution>+
+
Editorial note: goals for the algorithm
-picture
element will render the fallback content (including any child img
element) per the behavior of existing HTML5 media elements.The basic algorithm for processing the picture
element is as follows:
The algoithm for deriving the source image as follows. The result is the image source to be used by the picture
element, which reflects the picture
element's src
IDL attribute:
What we want to do is have the picture
behave exactly the same as an img
element, but with the only difference being that it is source
elements is used to determine the value of the src
IDL attribute (and hence what image content is displayed). How that is determined is through using the media
attribute attribute of the source
element.
To avoid complexity, the type
attribute is all child source
elements is ignored in this context.
So, to derive the source image: we gather all the media queries from the source
elements' media
attributes into a "stylesheet", in document order. Any missing media
attributes are just assumed to mean "all". Any media attributes that are not valid media queries are ignored. So, given the following:
<picture id="pictureElement"> + <source media="(min-width: 45em)" srcset="large-1.jpg 1x, large-2.jpg 2x"> + <source media="(min-width: 18em)" srcset="med-1.jpg 1x, med-2.jpg 2x"> + + <!-- assume media all --> + <source srcset="small-1.jpg 1x, small-2.jpg 2x"> + + <!-- the following are ignored --> + <source media=" is the massage " srcset=""> + +</picture>+
Becomes the rough CSS equivelent of (a virtual stylesheet for the document?):
+-+-
-- Evaluate
-media
/src
/srcset
attributes on the parentpicture
element first. - --
-- If the
-media
attribute on thepicture
element should match, evaluatesrcset
( per the image-set notation algorithm ) or thesrc
attribute.- If not, continue to step two below.
-- Evaluate
-source
child elements per the resource selection algorithm already defined for themedia
attribute to select the appropriate source element.- Once the
-source
element has been identified, look to see if the element hassrcset
defined. Ifsrcset
exists, follow the the image-set notation algorithm. Ifsrc
is specified on thesource
element, let that be the chosenpicture
source.- The user agent will ignore any
-img
elements that are children of thepicture
element.It should be possible to determine from script which source was selected. For media elements, this is done with the- +//assume #pictureElement is magically scoped to the correspoding element. +@media all{ + #pictureElement{ + background-image: image-set(small-1.jpg 1x, small-2.jpg 2x); + } +} - - +@media all and (min-width: 45em){ + #pictureElement{ + background-image: image-set(large-1.jpg 1x, large-2.jpg 2x); + } +} -currentSrc
IDL attribute.- +@media all and (min-width: 18em){ + #pictureElement{ + background-image: image-set(med-1.jpg 1x, med-2.jpg 2x); + } +}Accessibility
-The
- - Thepicture
element relies on fallback content as representative alternate text, rather than calling for analt
attribute on both the parentpicture
element and the fallbackimg
. This provides a method for specifying short alternative text without requiring authors to specify an identical attribute on bothpicture
and the fallbackimg
, with the potential to reach the greatest number of end users without requiring a redundant effort on the part of authors.alt
attribute MUST be handled according to the techniques for providing useful text alternatives forimg
elements no different fromalt
attributes onimg
elements outside of thepicture
context. -The
-alt
attribute is NOT permissible onsource
elements. If the alternate text description of asource
element differs from othersource
elements, it would suggest that the listed sources are not different versions of the same image, but are likely to be different images entirely.--The eventual resolution of ISSUE-30: Should HTML 5 include a longdesc attribute for images will determine the method by which authors can provide semantically rich markup as accessible text.
-Further accessibility discussion can be viewed at http://lists.w3.org/Archives/Public/public-html/2012Sep/0029.html.
-
The API then just works the same as per images. Events are fired in the same way as if the image's src IDL attribute had been set manually by the author.
+The resource fetching behavior of then governed by CSS Image Values and Replaced Content Module Level 4.
+TODO: add examples
-This proposal was designed with the following goals in mind:
-img
element.There are many use cases that are supported as listed below. There are two primary use cases:
-Most of the more specific use cases fall under one of these two umbrella needs.
- -There are many different screen sizes that are in common daily usage, ranging from small phones to giant high-definition televisions. This change in how we access the web was the main reason for needing to make responsive websites in the first place.
-A common practice in responsive design is delivering images without height and width attributes and letting the browser resize the image. This technique is commonly called flexible images or fluid images.
-However, delivering an image at a size optimized for large displays to a small display is not ideal. Large images incur unnecessary download and processing time, slowing the experience for users.
-To solve this problem, web authors will provide multiple sources of the same image at different resolutions and then pick the correct size image based on the viewport size. This is commonly done for CSS background images in responsive designs, but web authors lack the tools to do so for images in HTML without the use of JavaScript.
-Since the high-density devices (e.g., Retina™ displays on Apple products) came out, the quality of images on the web has changed. Beforehand, even though we had a variety of device sizes, the DPI has always been the same. This is no longer the case and it is very likely that the current resolution/pixel density on Retina™ devices will not be the only one.
+A user agent may be able to override requests for higher-resolution images based on user preferences. For example: “always request high-resolution images,” “always request low-resolution images,” and “request high-resolution images as bandwidth permits” based on the bandwidth information available to the browser.
-We should be ready and able to support the current resolutions as well as any others that manufacturers may use in the future.
+A common approach in sites that cater to a wide range of devices using a single codebase is a “mobile-first” development pattern—starting with a simple, linear layout and increasing layout and functional complexity for larger screen sizes using media queries.
-“Desktop-first” responsive design takes the opposite approach and starts from the desktop design and simplifies it using media queries to support small displays. Authors retrofitting existing sites often take a desktop-first approach out of necessity because changing to a mobile-first approach would be a significant undertaking.
- -These two approaches require that a solution for images support the following:
-A common practice in creating flexible layouts is to specify the size values in media queries as relative units: em
, rem
, vw
/vh
etc. This is most commonly seen using ems in order to reflow layouts based on users’ zoom preferences, or to resize elements through JavaScript by dynamically altering a font-size value.
Web authors would like to be able to optionally match the breakpoints for images to the breakpoints that they have defined in their responsive designs. Being able to match the breakpoints ensures that images are operating under the same rules that define the layout. It also helps authors verify their approach by ensuring that the same viewport measurement tests are being used in both HTML and CSS.
- -This desire is a facet of the two preceding use cases (mobile/desktop-first responsive design and relative units). If a breakpoint in the design is defined as:
- -@media screen (max-width: 41em) {}
Then web authors would like to be able to define a similar breakpoint for images at a max-width of 41em and not have to translate that measurement into another unit like pixels even if it is possible to calculate that measurement:
- -When debugging a document, if the author cannot specify breakpoints for images in the same manner that they are defined for the design, authors will need to convert the breakpoints back to the values specified in the layout in order to verify that they match. This increases authoring time and the likelihood that math errors on the part of authors (possibly due to a different rounding scheme in a particular user agent) cause unexpected behavior.
- -It should be noted that many devices are used on mobile networks which are often very slow or exhibit high latency. Often times conferences suffer from slow networks as well due to many users attempting to use a single network connection simultaneously. Many people also have very slow or erratic connections in their homes and workplaces. While it may not be possible for a solution to be based on bandwidth, anything that can be done to reduce latency and HTTP requests should be done.
+TODO: add examples
+Allowing authors to specify different images for different viewport sizes and display densities is one step towards providing a better experience on slow networks. In the future, user agents may be able to select different images based on network speed or user preference.
- -Images blur when the user resizes the page. Users may zoom an image in order to see more detail. In these cases, user agents could select a higher-resolution version of an image to display.
-Web authors often want to provide different versions of the same image at different sizes depending on the viewport. We refer to this as the a rt direction use case.
-A simple example of this would be changing the crop of an image based on display area:
-Examples: Large photo of Obama at a Chrysler plant vs. tighter cropped thumbnail
-A more complex example that changes orientation of the image, crop, and how text flows around an image based on the size of the viewport:
-Printed web documents generally have pixelated images due to printers having a higher DPI than most images currently served on the web. Defining higher resolution images for printing would increase the abilities of web authors to define great printed versions of their documents. For example, a photo sharing site could provide a bandwidth-optimized image for display on screen, but a high-resolution image for print.
- -Displaying a color image on a monochrome display does not always work well, as two different colors of similar luminosity would be impossible to distinguish in a monochrome environment.
-Microsoft is proposing a media query which lets you detect that the user agent has been put in high contrast mode (for accessibility reasons), and that the content should follow along [http://msdn.microsoft.com/en-us/library/windows/apps/hh465764.aspx]. Being able to switch images based on high contrast mode would be nice.
-Extracted from WhatWG mailing list thread.
-div
elements in order to be used today: https://github.com/scottjehl/picturefill/tree/div-markup-currentpropThis proposal was designed with the following goals in mind:
+img
element.There are many use cases that are supported as listed below. There are two primary use cases:
+Most of the more specific use cases fall under one of these two umbrella needs.
+There are many different screen sizes that are in common daily usage, ranging from small phones to giant high-definition televisions. This change in how we access the web was the main reason for needing to make responsive websites in the first place.
+A common practice in responsive design is delivering images without height and width attributes and letting the browser resize the image. This technique is commonly called flexible images or fluid images.
+However, delivering an image at a size optimized for large displays to a small display is not ideal. Large images incur unnecessary download and processing time, slowing the experience for users.
+To solve this problem, web authors will provide multiple sources of the same image at different resolutions and then pick the correct size image based on the viewport size. This is commonly done for CSS background images in responsive designs, but web authors lack the tools to do so for images in HTML without the use of JavaScript.
+Since the high-density devices (e.g., Retina™ displays on Apple products) came out, the quality of images on the web has changed. Beforehand, even though we had a variety of device sizes, the DPI has always been the same. This is no longer the case and it is very likely that the current resolution/pixel density on Retina™ devices will not be the only one.
+We should be ready and able to support the current resolutions as well as any others that manufacturers may use in the future.
+A common approach in sites that cater to a wide range of devices using a single codebase is a “mobile-first” development pattern—starting with a simple, linear layout and increasing layout and functional complexity for larger screen sizes using media queries.
+“Desktop-first” responsive design takes the opposite approach and starts from the desktop design and simplifies it using media queries to support small displays. Authors retrofitting existing sites often take a desktop-first approach out of necessity because changing to a mobile-first approach would be a significant undertaking.
+These two approaches require that a solution for images support the following:
+A common practice in creating flexible layouts is to specify the size values in media queries as relative units: em
, rem
, vw
/vh
etc. This is most commonly seen using ems in order to reflow layouts based on users’ zoom preferences, or to resize elements through JavaScript by dynamically altering a font-size value.
Web authors would like to be able to optionally match the breakpoints for images to the breakpoints that they have defined in their responsive designs. Being able to match the breakpoints ensures that images are operating under the same rules that define the layout. It also helps authors verify their approach by ensuring that the same viewport measurement tests are being used in both HTML and CSS.
+This desire is a facet of the two preceding use cases (mobile/desktop-first responsive design and relative units). If a breakpoint in the design is defined as:
+@media screen (max-width: 41em) {}
Then web authors would like to be able to define a similar breakpoint for images at a max-width of 41em and not have to translate that measurement into another unit like pixels even if it is possible to calculate that measurement:
+When debugging a document, if the author cannot specify breakpoints for images in the same manner that they are defined for the design, authors will need to convert the breakpoints back to the values specified in the layout in order to verify that they match. This increases authoring time and the likelihood that math errors on the part of authors (possibly due to a different rounding scheme in a particular user agent) cause unexpected behavior.
+It should be noted that many devices are used on mobile networks which are often very slow or exhibit high latency. Often times conferences suffer from slow networks as well due to many users attempting to use a single network connection simultaneously. Many people also have very slow or erratic connections in their homes and workplaces. While it may not be possible for a solution to be based on bandwidth, anything that can be done to reduce latency and HTTP requests should be done.
+Allowing authors to specify different images for different viewport sizes and display densities is one step towards providing a better experience on slow networks. In the future, user agents may be able to select different images based on network speed or user preference.
+Images blur when the user resizes the page. Users may zoom an image in order to see more detail. In these cases, user agents could select a higher-resolution version of an image to display.
+Web authors often want to provide different versions of the same image at different sizes depending on the viewport. We refer to this as the a rt direction use case.
+A simple example of this would be changing the crop of an image based on display area:
+Examples: Large photo of Obama at a Chrysler plant vs. tighter cropped thumbnail
+A more complex example that changes orientation of the image, crop, and how text flows around an image based on the size of the viewport:
+Printed web documents generally have pixelated images due to printers having a higher DPI than most images currently served on the web. Defining higher resolution images for printing would increase the abilities of web authors to define great printed versions of their documents. For example, a photo sharing site could provide a bandwidth-optimized image for display on screen, but a high-resolution image for print.
+Displaying a color image on a monochrome display does not always work well, as two different colors of similar luminosity would be impossible to distinguish in a monochrome environment.
+Microsoft is proposing a media query which lets you detect that the user agent has been put in high contrast mode (for accessibility reasons), and that the content should follow along. Being able to switch images based on high contrast mode would be nice.
+Extracted from WhatWG mailing list thread.
+TODO: add thanks
-div
elements in order to be used today:TODO: add thanks
+