From a4707d6660e1c028a17c85c37141a0cfa224cf0f Mon Sep 17 00:00:00 2001 From: Marcos Caceres Date: Tue, 2 Oct 2012 16:11:27 +0100 Subject: [PATCH] =?UTF-8?q?Deleted=20spec!=20OMG!!!!=E2=80=A6=20we=20are?= =?UTF-8?q?=20using=20the=20gh-pages=20branch:)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + ResponsiveImages.html | 309 ------------------------------------------ 2 files changed, 2 insertions(+), 309 deletions(-) create mode 100644 .gitignore delete mode 100644 ResponsiveImages.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..9bea4330 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +.DS_Store diff --git a/ResponsiveImages.html b/ResponsiveImages.html deleted file mode 100644 index 9bf89697..00000000 --- a/ResponsiveImages.html +++ /dev/null @@ -1,309 +0,0 @@ - - - - The picture element and the srcset attribute - - - - - - -
-

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.

-
- -
-

Goals

-

The overarching goal is to give developers a way to provide user agents with sufficient information about each image, and applicable media, so that the user agent can select the most appropriate one for a dynamically changing browsing situations. This includes, but is not limited to, different screen pixel width/height, pixel densities, environmental lighting conditions, and potentially even situations where the network bandwith changes dymamically. By providing a graded set of image sources, UA discretion could similarly apply to situations where the network bandwith changes dymamically. Based on user settings and network latency calculated by the user agent, the UA may have the option of selecting lower density image sources.

-

In addition, this proposal is being worked on with the following goals in mind:

- -
- - -
-

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]].

-
-
-

Definitions

-

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]].

-
-
-

The picture element

-
-
Categories:
-
Flow content.
-
Phrasing content.
-
Embedded content.
-
Palpable content.
-
Contexts in which this element can be used:
-
Where embedded content is expected.
-
Content model:
-
If zero descendents, then transparent.
-
One or more source elements.
-
Zero or one img element, serving as fallback content.
-
Content attributes:
-
Global attributes
-
crossorigin
-
width
-
height
- -
DOM interface:
-
-
[NamedConstructor=Picture,
- NamedConstructor=Picture(unsigned long width),
- NamedConstructor=Picture(unsigned long width, unsigned long height)]
-HTMLPictureElement : HTMLImageElement{
-   readonly attribute DOMString media; 
-}
- -
-
-

The picture element used for displaying an image that can come from a range of sources (see srcset attribute). Which image the user agent displays depends on the - algorithm for deriving the source image.

-

On getting the media attribute, the user agent MUST return the

-

The chosen image is the embedded content.

-

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, documents must not use the picture 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="">
-   <p>Accessible text</p>
-</picture>
-
-

Differences from img element

-

Unlike 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 constraint. 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 adoption 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.

-
It should be codified that this is not a mechanism by which to swap disparate images depending on screen size. See bug 18384.
-
- - - -
- - -
-

The srcset attribute

-

The srcset attribute of the source element is is used to refer to alternate image resource for a single image at different resolutions. The expected value is a image candidate string.

-
-

Example

-

The following is an example of a valid-srcset.

-
large-1.jpg 1x, large-2.jpg 2x 
-
-
- - -
-

Algorithm for deriving the source image

-

The algorithm 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 equivalent of (a virtual stylesheet for the document?):

-
-
-//assume #pictureElement is magically scoped to the corresponding 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);
-   }
-}
-
-@media all and (min-width: 18em){
-   #pictureElement{      
-      background-image: image-set(med-1.jpg 1x, med-2.jpg 2x);
-   }
-}
-

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.

-
- - - -

A user agent MAY 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.

- -
- - - - -
-

Examples

-

TODO: add examples

-
- - -
-

Use cases

-

There are many use cases that are supported as listed below. There are two primary use cases:

-
    -
  1. The need for different image sources at different viewport sizes in responsive web designs.
  2. -
  3. The need for different image sources depending on the pixel density of the display.
  4. -
-

Most of the more specific use cases fall under one of these two umbrella needs.

-

Viewport Sizes

-

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.

-

Display Density

-

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.

-

Mobile-first and desktop-first responsive design

-

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:

-
    -
  • Authors need the ability to define fallback image as the smallest image (mobile first) or the largest image (desktop first).
  • -
  • Authors would like to define the breakpoints for images as either minimum values (mobile first) or maximum values (desktop first) to match the media queries used in their design.
  • -
-

Relative Units

-

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.

-

Matching image source breakpoints to design breakpoints

-

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:

-
    -
  • The default font size in most browsers is 16 pixels. So 41em can be calculated to be 41 * 16 = 656 pixels. Calculating this for every breakpoint, while possible, would be tedious and potentially error-prone for authors.
  • -
  • Unless the image break points support both max and min values, then the image breakpoint will need to be further modified from the layout breakpoint that it was derived from. For example, if the image format only supports minimum width tests, then instead of using a maximum width of 656 pixels, the document author would need to specify 657 pixels as a minimum width for the breakpoint.
  • -
-

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.

-

Mobile Networks

-

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.

-
-

User Zoom

-

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.

-
It's not clear whether the picture element is prescriptive (i.e. the user agent MUST show a particular image given certain device properties) or suggestive (i.e. the user agent has control over picking the best image).
-

Art Direction

-

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:

-
    -
  • a website wants to normally show a large image (e.g. of a figure with a broad background) on displays that are big enough.
  • -
  • when shown on a smaller device, simply shrinking the image may reduce its relevance, usefulness, or legibility, and thus the site may wish to show a different cropping or layout of the same image at the smaller size.
  • -
-

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:

-
    -
  • On the Nokia Browser site where it describes the Meego browser, the Nokia Lumia is shown horizontally on wide screens. As the screen narrows, the Nokia Lumia is then shown vertically and cropped. Bryan and Stephanie Rieger, the designers of the site, have talked about how on a wide screen, showing the full phone horizontally showed the browser best, but on small screens, changing the img to vertical made more sense because it allowed the reader to still make out the features of the browser in the image.
  • -
-

Alternate Print Sources

-

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.

-

Gray Scale and High Contrast Modes

-

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.

-
- - -
- - -
-

Open Issues

-

We are tracking issues on GitHub. Please help us out by filing bugs there!

- -

Reference implementations

-

We have a list of polyfills, prototypes, and reference implementations on GitHub.

-

Acknowledgements

-

TODO: add thanks

-
- - - - \ No newline at end of file