This document captures the use cases and requirements for standardizing a solution for responsive images.
Hi! If you find any bugs, typos, or issues please or !
To visually communicate effectively, developers require a means to explicitly control which image, from a set of images, is shown to a user in response to the environmental conditions of the user agent. In a [[HTML5]] user agent, environmental conditions are expressed as CSS media features (e.g., max-width, orientation, monochrome, etc.) and CSS media types (e.g., print, screen, etc.). Many media features are dynamic in nature (e.g., a browser window is re-sized, a device is rotated from portrait to landscape, and so on), thus a user agent constantly responds to events that cause the properties of media features to change. These changes in media features and media type can reduce an image's ability to communicate effectively (e.g. images become blurry or pixelated).
As the number and varieties of high-density screens has increased (both on mobile and desktop devices), web developers have created custom techniques for serving images that best match a user's browsing environment. For a list of examples of the range of techniques in use in 2012, see Chris Coyier's article "". However, these techniques have a number of shortcomings, which are discussed below (and these shortcomings serve as the motivation to reach out to the and for standardization).
The 's goal for this document is to capture a complete set of developer requirements for responsive images. The group intends to deliver the document to the HTMLWG and for comment (see ). The use cases and requirements were gathered by consultation with and participants, community group members, and the general public. The RICG's goal for this document is to make sure that developer's requirements for responsive images have been formally captured.
The RICG expects that a technical specification can be created to formally address each of the requirements (i.e., the solution). To date, two such specifications are currently under development:
Proposed solutions are not mutually exclusive. They may work together to address the complete set of use cases and requirements.
There are a number of problems with the currently being relied on by web developers:
Large images incur unnecessary download and processing time, slowing the experience for users. To solve this problem, web developers 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 developers lack the markup to do so for images in HTML without hacking together a solution. This means that developers have resorted to using div and other container elements to achieve the desired functionality.
In other words, developers are being forced to work around, or completely ignore, authoring requirements of [[!HTML5]].
The rely on either JavaScript or a server-side solution (or both), which adds complexity and redundant HTTP requests to the development process. Furthermore, the script-based solutions will be unavailable to users who have turned off JavaScript.
The RICG believes that standardization of a browser-based solution can overcome these problems.
The following use cases represent situations in which Web developers see a need for a browser-based solution for working with responsive images.
Web developers often need to provide different versions of the same image in order to communicate effectively across the wide range of screen resolutions and pixel densities available on today's devices. If the screen is small and the image is scaled down, its details cannot be seen. Conversely, if the screen is large a larger image that depicts more information can be shown.
For example, in the left-most image in Figure 1, it is difficult to discern the man's facial expressions, where in the center image his face and gestures are clear. The image on the far right show the poor quality of an over-scaled image.
In a responsive design, it is typical to change the crop of an image so it can be targeted towards the features of a particular display (or set of displays):
This is illustrated in the figure below.
A related use case is when orientation determines the source of the image, the crop, and how text flows around the image based on the size of the viewport. For example, on the Nokia Lumia site where it describes the , the Nokia Lumia is shown . As the screen narrows, the Nokia Lumia is then shown . Bryan and Stephanie Rieger, the designers of the site, explained that on a wide screen, showing the full phone horizontally showed the browser best; but on small screens, changing the image to vertical made more sense because it allowed the reader to still make out the features of the browser in the image.
In Web development, a breakpoint is one of a series of CSS Media Queries that update the styles of a page based on logical matching of media features. A single breakpoint represents a rule (or set of rules) that determines the point at which the contents of that media query are applied to a pageâs layout. For example:
@media screen and (max-width: 16em) { ... }
@media screen and (max-width: 32em) { ... }
@media screen and (max-width: 41em) { ... }
Developers currently match specific breakpoints for images to the breakpoints that they have defined in the CSS of their responsive designs. Being able to match the breakpoints ensures that images are operating under the same rules that define the layout of a design. It also helps developers verify their approach by ensuring that the same viewport measurement tests are being used in both HTML and CSS.
If a breakpoint in the design is specified in as "max-width: 41em", then web developers 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 developer cannot specify breakpoints for images in the same manner that they are defined for the design, developers 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 of errors on the part of developers.
Printed web documents generally have pixelated images due to printers having a higher DPI than most images currently served on the web. According to Wikipedia's article on "":
"An inkjet printer sprays ink through tiny nozzles, and is typically capable of 300-600 DPI. A laser printer applies toner through a controlled electrostatic charge, and may be in the range of 600 to 1,800 DPI."
Defining higher resolution images for printing would increase the abilities of web developers to define 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 monochrome media (e.g., paper and e-ink displays) can be problematic; different colors with similar luminosity are impossible to distinguish on monochrome media. Currently, server side solutions exist to adapt web content to e-ink displays. For example, . Or custom services have been created specifically for accessing popular websites, like . However, there is currently no convient means to change the source of an image for print media.
Additionally, Microsoft has proposed a , which would enable developers to know if the user agent is operating in a high-contrast mode. Knowing if the user agent is operating in high-contrast mode allows developers to serve appropriate images, which could potentially assists visually impaired users. To be able to use this feature with images on the Web, developers would currently need to rely on the problematic previously discussed.
A common practice in creating flexible layouts is to specify the size values in media queries as relative units: em, rem, vw/vh etc. See, for example, Lyza Gardner's article . This approach 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.
In flexible layout designs, when a user zooms into a design, proportionally scaled images can be blurry or pixelated, affecting the image's impact and function. Swapping to a more suitable image is used to overcome this problem.
There are cases where the image data is dynamically generated (e.g., using canvas element and related APIs) or is acquired from the device itself (e.g., from the camera on a phone or tablet). Developers need practical means to interface programmatically with the source of an image or a set of images. Without having a suitable API, it will be difficult for developers to manipulate the sources of images.
Some images are best suited to a specific file type, for reasons such as file size optimization, alpha transparency, scalability, animation, etc. For example, a photo usually requires good color depth, but does not require alpha transparency or animation; JPEG or WebP are well-suited to these needs and offer good optimization between image quality and file size. Icons are often simpler in terms of colour depth, but may require alpha transparency; the PNG format is better-suited to these needs.
In a responsive design, images need to be displayed at different sizes. When possible, a vector format such as SVG might be most appropriate. There have also been proposals for new responsive image formats (see, for example, ).
Although a web developer may want to use a specific image format, new or otherwise, the browser may not always support it. Currently developers must often abandon the best image format in favor of one that has good support.
The use cases give rise to the following requirements:
The solution MUST afford developers the ability to match image sources with particular media features and/or media types - and have the user agent update the source of an image as the media features and media types of the browser environment change dynamically over time.
The solution MUST degrade gracefully on legacy user agents by, for example, falling back on the img element and by relying on [[HTML5]] built-in fallback mechanisms. Additionally, the solution SHOULD afford developers the ability to define which version of the image needs to be used as the fallback image.
For accessiblity, the solution MUST afford developers with the ability to provide textual alternatives to images.
The solution MUST adhere to akin solutions already in [[HTML5]], such img or those used by audio and video elements.
The solution MUST NOT require server-side processing to work.
The solution MUST provide developers with a means to programmatically interface with the displayed image, as well as access relevant attributes and methods that make solution easy to work with. In addition, the solution MUST provide means to hook into relevant events (e.g., loading, errors, etc.). In any case, an API SHOULD provide a means to:
Determine the current source of the image.
Determine what environmental condition caused the current source to be selected (reflected as, for example, a CSS Media Query).
Add, remove, and update image sources.
The solution MUST afford developers the ability to explicitly define different image versions as opposed to simply different resolutions of the same image.
The solution MUST afford developers the ability to define fallback image as the smallest image (mobile first) or the largest image (desktop first).
The solution MUST afford developers the ability 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.
The solution MUST function in such a way that is is responsive to environmental changes in relative units (e.g., when the user increases the base font size of the browser by pressing ctrl+ or ctrl-).
The solution MAY allow developers to specify images in different formats (or specify the format of a set of image sources).
To provide compatibility with legacy user agents, it SHOULD be possible for developers to the solution.
We are tracking open issues on Github. !
A is available on Github.
You can also see relating to this document.
We would like to thank the following people for reviewing the specification: Mike Taylor, Doug Shults, David Newton, Eileen Webb.