Specifying multiple slot widths  |  Articles  |  web.dev Skip to main content Resources Web Platform Dive into the web platform, at your pace. HTML CSS JavaScript User experience Learn how to build better user experiences. Performance Accessibility Identity Learn Get up to speed on web development. Learn HTML Learn CSS Learn JavaScript Learn AI Learn Performance Learn Accessibility More courses Additional resources Explore content collections, patterns, and more. AI and the web Explore PageSpeed Insights Patterns Podcasts & shows Developer Newsletter About web.dev Discover Baseline How to use Baseline Blog Case Studies / English Deutsch Español – América Latina Français Indonesia Italiano Polski Português – Brasil Tiếng Việt Türkçe Русский עברית العربيّة فارسی हिंदी বাংলা ภาษาไทย 中文 – 简体 中文 – 繁體 日本語 한국어 Sign in Articles Resources More Discover Baseline How to use Baseline Blog Case Studies Web Platform HTML CSS JavaScript User experience Performance Accessibility Identity Learn Learn HTML Learn CSS Learn JavaScript Learn AI Learn Performance Learn Accessibility More courses Additional resources AI and the web Explore PageSpeed Insights Patterns Podcasts &amp; shows Developer Newsletter About web.dev Home Articles Specifying multiple slot widths Stay organized with collections Save and categorize content based on your preferences. Katie Hempenius X To follow this codelab, open this Glitch in a second tab. Try out this demo To preview the site, press View App. Then press Fullscreen . Reload the app in differently sized browser windows to see the browser load different images and use different layouts at different browser sizes. View the code Checkout index.html for the code that makes this work: <img src="flower.jpg" srcset="flower-small.jpg 480w, flower-large.jpg 800w" sizes="(max-width: 480px) 100vw, (max-width: 1024px) 50vw, 800px"> What's going on here? The value of the sizes attribute dictates that image display width will be: "100% of the viewport width" on viewports up to 480px wide, "50% of the viewport width" on screens 481–1024px wide, and 800px on screens wider than 1024px. These widths match the widths specified in the CSS. The ability to specify multiple slot widths accommodates page layouts that use different styling (that is, image widths) for different viewport sizes. How to specify multiple slot widths Use a comma-separated list to specify multiple slot widths. Each list item, except for the last item, consists of a media condition (e.g. max-width or min-width) and a slot width. The last item in this list is the default slot width. It is the default, so you do not need to specify a media condition. You can list as many slot widths as you want - the number of images listed in srcset does not matter. Slot width can be specified using a variety of units. The following are all valid widths: 100px 33vw 20em calc(50vw-10px) The following is not a valid width: 25% (percentages cannot be used with the sizes attribute) Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Last updated 2018-11-05 UTC. [[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2018-11-05 UTC."],[],[]] web.dev web.dev We want to help you build beautiful, accessible, fast, and secure websites that work cross-browser, and for all of your users. This site is our home for content to help you on that journey, written by members of the Chrome team, and external experts. Contribute File a bug See open issues Related Content Chrome for Developers Chromium updates Case studies Podcasts & shows Follow @ChromiumDev on X YouTube Chrome for Developers on LinkedIn RSS Terms Privacy Manage cookies English Deutsch Español – América Latina Français Indonesia Italiano Polski Português – Brasil Tiếng Việt Türkçe Русский עברית العربيّة فارسی हिंदी বাংলা ภาษาไทย 中文 – 简体 中文 – 繁體 日本語 한국어