{"id":255,"date":"2020-10-27T10:13:55","date_gmt":"2020-10-27T15:13:55","guid":{"rendered":"https:\/\/wowfall2020.londietmartin.com\/?p=255"},"modified":"2020-10-27T10:13:55","modified_gmt":"2020-10-27T15:13:55","slug":"strategies-for-responsive-images","status":"publish","type":"post","link":"https:\/\/wowfall2020.londietmartin.com\/?p=255","title":{"rendered":"Strategies for Responsive Images"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Images are important pieces of information and how they are shared on the web should vary across different devices.&nbsp; A large image may look great on a desktop, but may appear differently on a smaller screen.&nbsp; Without responsive design, that image may cover too much real estate on a smaller screen.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Responsive images have always been a concern for developers. When presenting images on the web, we want to enable the browser to resize the images appropriately. Responsive images refers to a method for providing the browser with a list of image sources depending on resolution, the size of the image on the webpage, or other cases.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There are many methods to solve responsive images. But, Write Here, Write Now, we\u2019ll focus on two major methods and their use cases: responsive images using the &lt;picture&gt; element and responsive images using srcset.<\/p>\n\n\n\n<h2 class=\"has-large-font-size wp-block-heading\">Responsive Images Using Picture Element<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Sometimes you need to make changes to the content or aspect ratio of an image to show a particular feature of an image. This method is referred to as art direction. Typically art direction is used:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>To crop an image<\/li><li>To change the orientation of an image<\/li><li>To change how text flow on an image<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">A large image may show plenty of detail on a large screen, but is reduced to show only relevant information for smaller screens like the example of the image from Nokia\u2019s website.<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<div class=\"wp-block-jetpack-tiled-gallery aligncenter is-style-rectangular\"><div class=\"tiled-gallery__gallery\"><div class=\"tiled-gallery__row\"><div class=\"tiled-gallery__col\" style=\"flex-basis:100%\"><figure class=\"tiled-gallery__item\"><img decoding=\"async\" srcset=\"https:\/\/i1.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/nokia-desktop-2.png?strip=info&#038;w=600&#038;ssl=1 600w,https:\/\/i1.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/nokia-desktop-2.png?strip=info&#038;w=900&#038;ssl=1 900w,https:\/\/i1.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/nokia-desktop-2.png?strip=info&#038;w=1200&#038;ssl=1 1200w,https:\/\/i1.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/nokia-desktop-2.png?strip=info&#038;w=1500&#038;ssl=1 1500w,https:\/\/i1.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/nokia-desktop-2.png?strip=info&#038;w=1800&#038;ssl=1 1800w,https:\/\/i1.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/nokia-desktop-2.png?strip=info&#038;w=2000&#038;ssl=1 2000w\" alt=\"\" data-height=\"1803\" data-id=\"274\" data-link=\"https:\/\/wowfall2020.londietmartin.com\/?attachment_id=274\" data-url=\"https:\/\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/nokia-desktop-2.png\" data-width=\"3801\" src=\"https:\/\/i1.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/nokia-desktop-2.png?ssl=1\" \/><\/figure><\/div><\/div><div class=\"tiled-gallery__row\"><div class=\"tiled-gallery__col\" style=\"flex-basis:59.08230192623187%\"><figure class=\"tiled-gallery__item\"><img decoding=\"async\" srcset=\"https:\/\/i0.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/nokia-tablet-4.png?strip=info&#038;w=600&#038;ssl=1 600w,https:\/\/i0.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/nokia-tablet-4.png?strip=info&#038;w=900&#038;ssl=1 900w,https:\/\/i0.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/nokia-tablet-4.png?strip=info&#038;w=1143&#038;ssl=1 1143w\" alt=\"\" data-height=\"1574\" data-id=\"280\" data-link=\"https:\/\/wowfall2020.londietmartin.com\/?attachment_id=280\" data-url=\"https:\/\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/nokia-tablet-4.png\" data-width=\"1143\" src=\"https:\/\/i0.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/nokia-tablet-4.png?ssl=1\" \/><\/figure><\/div><div class=\"tiled-gallery__col\" style=\"flex-basis:40.917698073768136%\"><figure class=\"tiled-gallery__item\"><img decoding=\"async\" srcset=\"https:\/\/i0.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/nokia-phone-2.png?strip=info&#038;w=600&#038;ssl=1 600w,https:\/\/i0.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/nokia-phone-2.png?strip=info&#038;w=867&#038;ssl=1 867w\" alt=\"\" data-height=\"1725\" data-id=\"281\" data-link=\"https:\/\/wowfall2020.londietmartin.com\/?attachment_id=281\" data-url=\"https:\/\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/nokia-phone-2.png\" data-width=\"867\" src=\"https:\/\/i0.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/nokia-phone-2.png?ssl=1\" \/><\/figure><\/div><\/div><\/div><\/div>\n<\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">This same image has been cropped to fit a particular viewport (screen size) to effectively communicate their message.&nbsp; As the viewport gets smaller, the image is cropped to remove some of the background and emphasize the woman. If they just scaled the image down to fit the screen, then the woman would be barely visible.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Art direction can mean changing the orientation like you see in the following example.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Each image changes from portrait on a large screen, to landscape on a smaller screen so the content isn\u2019t lost as the screen size changes.<\/p>\n\n\n\n<figure class=\"wp-block-gallery columns-0 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"774\" height=\"676\" src=\"https:\/\/i0.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/orientation-1.jpg?resize=774%2C676&#038;ssl=1\" alt=\"\" data-id=\"298\" data-full-url=\"https:\/\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/orientation-1.jpg\" data-link=\"https:\/\/wowfall2020.londietmartin.com\/?attachment_id=298\" class=\"wp-image-298\" srcset=\"https:\/\/i0.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/orientation-1.jpg?resize=1024%2C894&amp;ssl=1 1024w, https:\/\/i0.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/orientation-1.jpg?resize=300%2C262&amp;ssl=1 300w, https:\/\/i0.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/orientation-1.jpg?resize=768%2C671&amp;ssl=1 768w, https:\/\/i0.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/orientation-1.jpg?w=1088&amp;ssl=1 1088w\" sizes=\"auto, (max-width: 774px) 100vw, 774px\" \/><\/figure><\/li><\/ul><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For images that contain text, we can change the content (text and picture) and aspect ratio, like in the following example.<\/p>\n\n\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If Nokia just resized the image, then the text would be too small to read. Instead, they used a different picture for smaller viewports, moved the text, and changed the aspect ratio to make the picture taller.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"has-normal-font-size wp-block-heading\">Now let\u2019s get coding!<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To solve the art direction problem, you need the following elements and attributes:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&lt;picture&gt;                         To specify different images depending on device characteristics.<br>&lt;img&gt; and srcset              To dictate what image the browser must use.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<figure class=\"wp-block-gallery aligncenter columns-1 is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"774\" height=\"494\" src=\"https:\/\/i0.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/picture-element-1024x653.png?resize=774%2C494&#038;ssl=1\" alt=\"\" data-id=\"262\" class=\"wp-image-262\" srcset=\"https:\/\/i0.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/picture-element.png?resize=1024%2C653&amp;ssl=1 1024w, https:\/\/i0.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/picture-element.png?resize=300%2C191&amp;ssl=1 300w, https:\/\/i0.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/picture-element.png?resize=768%2C490&amp;ssl=1 768w, https:\/\/i0.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/picture-element.png?w=1104&amp;ssl=1 1104w\" sizes=\"auto, (max-width: 774px) 100vw, 774px\" \/><\/figure><\/li><\/ul><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"has-normal-font-size wp-block-heading\">What does this mean?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The largest image size is the first source <strong>(min-width: 900px)<\/strong>. It\u2019s media attribute tells the browser that this first source should be used if the viewport is 900px or greater.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The media attribute of the smallest image size tells the browser to use the second source, <strong>(min-width: 750px)<\/strong>, if the viewport is equal to or greater than 750px, and less than 900px.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If no media query matches the list, then the &lt;img&gt; is used.&nbsp;&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"has-large-font-size wp-block-heading\">Responsive Images Using SRCSET<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If you want to provide different sizes of an image, but not change its content or aspect ratio, then consider using the resolution switching method. Unlike the picture element used in art direction, srcset presents a choice of multiple images and their true widths to enable the browser to select the best image.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">View the Guardian website as an example.<\/p>\n\n\n\n<div class=\"wp-block-jetpack-tiled-gallery aligncenter is-style-rectangular\"><div class=\"tiled-gallery__gallery\"><div class=\"tiled-gallery__row\"><div class=\"tiled-gallery__col\" style=\"flex-basis:100%\"><figure class=\"tiled-gallery__item\"><img decoding=\"async\" srcset=\"https:\/\/i1.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/guardian-desktop.png?strip=info&#038;w=600&#038;ssl=1 600w,https:\/\/i1.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/guardian-desktop.png?strip=info&#038;w=900&#038;ssl=1 900w,https:\/\/i1.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/guardian-desktop.png?strip=info&#038;w=1200&#038;ssl=1 1200w,https:\/\/i1.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/guardian-desktop.png?strip=info&#038;w=1500&#038;ssl=1 1500w,https:\/\/i1.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/guardian-desktop.png?strip=info&#038;w=1800&#038;ssl=1 1800w,https:\/\/i1.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/guardian-desktop.png?strip=info&#038;w=2000&#038;ssl=1 2000w\" alt=\"\" data-height=\"1853\" data-id=\"286\" data-link=\"https:\/\/wowfall2020.londietmartin.com\/?attachment_id=286\" data-url=\"https:\/\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/guardian-desktop.png\" data-width=\"3772\" src=\"https:\/\/i1.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/guardian-desktop.png?ssl=1\" \/><\/figure><\/div><\/div><div class=\"tiled-gallery__row\"><div class=\"tiled-gallery__col\" style=\"flex-basis:65.45447588484376%\"><\/div><div class=\"tiled-gallery__col\" style=\"flex-basis:34.54552411515624%\"><figure class=\"tiled-gallery__item\"><img decoding=\"async\" srcset=\"https:\/\/i1.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/guardian-phone-1.png?strip=info&#038;w=600&#038;ssl=1 600w,https:\/\/i1.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/guardian-phone-1.png?strip=info&#038;w=900&#038;ssl=1 900w,https:\/\/i1.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/guardian-phone-1.png?strip=info&#038;w=906&#038;ssl=1 906w\" alt=\"\" data-height=\"1719\" data-id=\"291\" data-link=\"https:\/\/wowfall2020.londietmartin.com\/?attachment_id=291\" data-url=\"https:\/\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/guardian-phone-1.png\" data-width=\"906\" src=\"https:\/\/i1.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/guardian-phone-1.png?ssl=1\" \/><\/figure><\/div><\/div><\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">They use resolution switching to tell the browser what the size of the image will be in relation to the screen size and how that relationship changes as the size of the screen changes.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"has-normal-font-size wp-block-heading\">Now let\u2019s get coding!<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To get started, you must include the srcset and sizes attribute. The sizes attribute contains a list that describes the size of the image in relation to the viewport size.<\/p>\n\n\n\n<figure class=\"wp-block-gallery columns-1 is-cropped wp-block-gallery-3 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"774\" height=\"223\" src=\"https:\/\/i0.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/srcset.png?resize=774%2C223&#038;ssl=1\" alt=\"\" data-id=\"264\" class=\"wp-image-264\" srcset=\"https:\/\/i0.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/srcset.png?resize=1024%2C295&amp;ssl=1 1024w, https:\/\/i0.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/srcset.png?resize=300%2C86&amp;ssl=1 300w, https:\/\/i0.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/srcset.png?resize=768%2C221&amp;ssl=1 768w, https:\/\/i0.wp.com\/wowfall2020.londietmartin.com\/wp-content\/uploads\/2020\/10\/srcset.png?w=1185&amp;ssl=1 1185w\" sizes=\"auto, (max-width: 774px) 100vw, 774px\" \/><\/figure><\/li><\/ul><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"has-normal-font-size wp-block-heading\">What does it mean?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When the browser reads the list of values, it selects the value that meets the media condition.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If the viewport is 400 pixels or smaller, <strong>(max-width: 400px) 55vw<\/strong>, then the image will be 55% of the viewport width (vw). When none of the media conditions are met, then the default value, <strong>250px<\/strong>, is used.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"has-large-font-size wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There are so many methods to solving responsive images that it can be challenging to figure out the best method for your image. To know what method works best, you must know what use case you\u2019re planning for. Art direction and Resolution Switching are key methods to use. For more use cases to help you build responsively, check out <a href=\"http:\/\/usecases.responsiveimages.org\/#use-cases\" target=\"_blank\" rel=\"noreferrer noopener\">The W3C Working Group.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Images are important pieces of information and how they are shared on the web should vary across different devices.&nbsp; A large image may look great&hellip;<\/p>\n","protected":false},"author":37,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_monsterinsights_skip_tracking":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1],"tags":[],"class_list":["post-255","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/wowfall2020.londietmartin.com\/index.php?rest_route=\/wp\/v2\/posts\/255","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wowfall2020.londietmartin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wowfall2020.londietmartin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wowfall2020.londietmartin.com\/index.php?rest_route=\/wp\/v2\/users\/37"}],"replies":[{"embeddable":true,"href":"https:\/\/wowfall2020.londietmartin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=255"}],"version-history":[{"count":7,"href":"https:\/\/wowfall2020.londietmartin.com\/index.php?rest_route=\/wp\/v2\/posts\/255\/revisions"}],"predecessor-version":[{"id":477,"href":"https:\/\/wowfall2020.londietmartin.com\/index.php?rest_route=\/wp\/v2\/posts\/255\/revisions\/477"}],"wp:attachment":[{"href":"https:\/\/wowfall2020.londietmartin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wowfall2020.londietmartin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wowfall2020.londietmartin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}