Working with Responsive Images
Key Takeaways
Optimizes images for web performance and responsiveness using various techniques
Full Transcript
[Music] On average, images consume by far the most bytes on most web pages. We can do better. Responsive images are a huge topic. So, I'm just going to give a whistle stop tour. First though, some general principles for using images on the web. The goal here is to increase performance and reduce data cost. Now the first step in that is to avoid images wherever possible, text, CSS and so on. Use vector formats where possible, SVG. You could use icon fonts, but there are good reasons not to use them. I I won't go into that here. Anyway, always use the lowest possible resolution and quality image. Use the right format for the image type, WEBP, PNG, JPEG, and so on. Speaking of image formats, there are also a few use cases for inline images with data URIs. When you're using responsive design with PWAs, be especially careful about aspect ratio with images width and height. If you specify height as well as width, which may be good for performance, make sure to get it right. You can incorporate lossless compression tools in your workflow. And remember to use online tools and to add testing to your workflow. Page speed insights, web page test, and many other free tools are available. It's a great time to be doing responsive image design on the web. You have really powerful elements and attributes for sizing, resolution, and to reduce data cost. This chart is for picture and source set. As you can see, there's great support across modern browsers. There is also a picture polyfill available for older browsers. So what makes responsive images responsive? Firstly, the resolution of the screen. You need to serve images with more pixels to devices with higher resolution screens and vice versa. Secondly, image display size. This is the size at which the image is actually displayed and that can vary significantly even on the same device. 100% width in a maximized browser window on a big monitor is going to need an image with much larger dimensions than if the image is displayed at say 30% width in a smaller window. Think about format support. Different browsers support different formats. For example, you might want to serve WEBP images to browsers that support WEBP and provide a fallback to browsers that don't. Art direction. Now, you might even want to serve a different version of an image depending on display size, just like we mentioned earlier. Let's take a look at the source set attribute. This example shows what are called pixel density descriptors. The source set attribute tells the browser which image to choose depending on the pixel density of the display. This might be 1x for a desktop monitor, 2x for a laptop screen, or even more on a phone, for example. Note that fallback to source. So this will work on browsers that don't support source set. Also note the use of the alt attribute to improve accessibility. Now unfortunately we're not going to cover a lot of accessibility in this course, but the alt attribute is fundamental for those using screen readers or for users with images turned off. For a browser, there's a catch 22 when it comes to choosing which image to download. The browser needs to know the dimensions of each image, but it can't know that without downloading each image to check. Enter the Wunit. The Wunit tells the browser the width of each image in pixels, thereby enabling the browser to choose the right image to retrieve depending on the screen pixel density and the viewport size. Just to be clear, the source set attribute is giving the browser information about the image width. It does not specify the size to display the image. You still need CSS for that. Now, note that we can't specify both a pixel density and width descriptor in the same source set. It must be all pixel densities or all width descriptors. You can go further than just telling the browser the image width. The sizes attribute describes the display size of the image element. The sizes attribute here is telling the browser this walabe will always be displayed at 50% of viewport width. Given the image files available, please choose appropriately. This enables the browser to select the smallest possible image size to download. The picture and source elements enable us to provide alternative sources for the same resource. the browser will stop and load the first source element that it understands and load that image. If the browser can't read the files specified in the source elements or if the browser doesn't support the picture and source elements, the default image will be loaded from the source. The source elements can include different file formats. In this example, we use WEBP first and then JPEG as a fallback and provide the same JPEG file as the default image in the image element. You can also use picture for art direction. That means choosing different images for different display sizes. The source element can take an optional media attribute where you can specify a media query. When that media query is triggered, then the image in the associated source set attribute will be loaded. Only one image will be loaded at a time. Kitten large when the window width is 650 pixels or larger. Kitten medium when the window width is at least 465 but no more than 650 pixels and kitten small when the window is less than 465 pixels wide. If the browser doesn't support picture and source then only the image tag will be used and you will see the small kitten image. The live demo link will take you to an example of this code for you to test in practice. Okay, hold on to your hat. Here's everything put together where we've combined media queries and source set to specify images for smaller and larger viewports with different images for different pixel densities. Don't forget there are tools for making this part of your workflow. So you don't need to manually code all this. There are lots of resources to help you get started in the materials that go with this video. The lab exercises will help you get started with responsive elements and attributes.
Original Description
There are two major issues to consider when working with images on the web: performance and responsiveness. This video describes a set of techniques to make your images load as quickly as possible and work well in any form factor.
Codelabs, slides and more information are available from the Progressive Web Apps Training home page: https://developers.google.com/web/ilt/pwa
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Chrome for Developers · Chrome for Developers · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Polymer Performance Patterns (The Polymer Summit 2015)
Chrome for Developers
Polymer Power Tools (The Polymer Summit 2015)
Chrome for Developers
Chrome Dev Summit 2014 – Chrome Case Studies
Chrome for Developers
Web Directions Code 2015 round up
Chrome for Developers
Maintainable Code - HTTP203
Chrome for Developers
iron-ajax… wat?! -- Polycasts #26
Chrome for Developers
The Guardian - Supercharged
Chrome for Developers
ES2015 (next version of JavaScript), Totally Tooling Tips (S2 Ep1)
Chrome for Developers
#AskPolymer: Rob answers all the questions ever -- Polycasts #27
Chrome for Developers
The Future of JavaScript - HTTP203
Chrome for Developers
Data Binding 101 -- Polycasts #28
Chrome for Developers
The Guardian part 2 - Supercharged
Chrome for Developers
The Future of Web Audio: with Chris Wilson and Chris Lowis
Chrome for Developers
Chrome 46: New motion-path animations, client hints and service worker improvements
Chrome for Developers
Sublime Snippets, Totally Tooling Tips (S2 Ep2)
Chrome for Developers
#AskPolymer: How do you make the show? -- Polycasts #29
Chrome for Developers
Critical Path CSS, Totally Tooling Tips (S2 Mini Tip #1)
Chrome for Developers
Binding to Objects -- Polycasts #30
Chrome for Developers
Player FM - Supercharged
Chrome for Developers
Where’s the Designer? #AskPolymer -- Polycasts #31
Chrome for Developers
Jake Beats Wikipedia - HTTP203
Chrome for Developers
Supercharged Observers! -- Polycasts #32
Chrome for Developers
Jai's Web blog - Supercharged
Chrome for Developers
Windows Command-line Tooling, Totally Tooling Tips (S2, Ep4)
Chrome for Developers
What about internationalization? #AskPolymer -- Polycasts #33
Chrome for Developers
Developing for Billions (Chrome Dev Summit 2015)
Chrome for Developers
Google+ Performance Improvement Comparison
Chrome for Developers
Deploying HTTPS: The Green Lock and Beyond (Chrome Dev Summit 2015)
Chrome for Developers
Progressive Web Apps (Chrome Dev Summit 2015)
Chrome for Developers
Instant Loading with Service Workers (Chrome Dev Summit 2015)
Chrome for Developers
Increase Engagement with Web Push Notifications (Chrome Dev Summit 2015)
Chrome for Developers
Engaging with the Real World: Web Bluetooth and Physical Web (Chrome Dev Summit 2015)
Chrome for Developers
Asking for Permission: respectful, opinionated UI (Chrome Dev Summit 2015)
Chrome for Developers
Polymer - State of the Union (Chrome Dev Summit 2015)
Chrome for Developers
Building Progressive Web Apps with Polymer (Chrome Dev Summit 2015)
Chrome for Developers
Introduction to RAIL (Chrome Dev Summit 2015)
Chrome for Developers
DevTools in 2015: Authoring to the max (Chrome Dev Summit 2015)
Chrome for Developers
RAIL in the real world (Chrome Dev Summit 2015)
Chrome for Developers
#ChromeDevSummit talks are up - W00T! -- Polycast #34
Chrome for Developers
V8 Performance from the Driver's Seat (Chrome Dev Summit 2015)
Chrome for Developers
Quantify and improve real-world RAIL (Chrome Dev Summit 2015)
Chrome for Developers
Owning your performance: RAIL (Chrome Dev Summit 2015)
Chrome for Developers
HTTP/2 101 (Chrome Dev Summit 2015)
Chrome for Developers
Leadership Panel (Chrome Dev Summit 2015)
Chrome for Developers
Build Processes, Totally Tooling Tips (S2, Ep 5)
Chrome for Developers
Accessibility (Chrome Dev Summit 2015)
Chrome for Developers
Binding to Arrays -- Polycasts #35
Chrome for Developers
HTTP2 - HTTP203
Chrome for Developers
Chrome 47: Splash Screens, requestIdleCallback and better desktop notifications (New in Chrome)
Chrome for Developers
Call For Submissions - Supercharged
Chrome for Developers
Cross Device Testing, Totally Tooling Tips (S2 Ep6)
Chrome for Developers
Testing AJAX with Web Component Tester -- Polycasts #37
Chrome for Developers
Slack: Extended Xmas Special - Supercharged
Chrome for Developers
Browser testing with Travis & Sauce Labs -- Polycasts #38
Chrome for Developers
Optimize for production with Vulcanize -- Polycasts #39
Chrome for Developers
Highlights from Chrome Dev Summit 2015
Chrome for Developers
Chrome 48: Custom buttons in notifications, DevTools Security panel, and Presentation mode
Chrome for Developers
Crisper: Protecting your Polymer app with CSP -- Polycasts #40
Chrome for Developers
How do I use Sass with Polymer? #AskPolymer -- Polycasts #41
Chrome for Developers
Colors – DevTools Tonight #0 (Pilot)
Chrome for Developers
Related Reads
📰
📰
📰
📰
Angular vs React: Key Differences, Pros & Cons Compared
Dev.to · Elsie Rainee
Next.js Web App Development: Complete Guide for Fast, Scalable Applications (2026)
Dev.to · Avanexa Technologies
Next.js Quietly Fixed the Prefetch Problem Nobody Wanted to Talk About
Medium · JavaScript
A Fast Request, a Fast Parse and a Slow Page
Medium · JavaScript
🎓
Tutor Explanation
DeepCamp AI