<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Responsive Image - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Responsive Image - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Thu, 21 May 2026 16:11:44 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/responsive-image/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ Responsive Web Design – Modern Website Code for Beginners ]]>
                </title>
                <description>
                    <![CDATA[ When the internet was still young, website visitors used desktop and then laptop computers with wide screens to access websites.  Then when smart phones were developed, mobile phone users had to endlessly zoom and scroll to access and view different ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/responsive-web-design-modern-website-code-for-beginners/</link>
                <guid isPermaLink="false">66adf203f452caf50fb1fe1c</guid>
                
                    <category>
                        <![CDATA[ Responsive Image ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ responsive design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Kolade Chris ]]>
                </dc:creator>
                <pubDate>Fri, 27 Aug 2021 16:33:18 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/08/responsive-web-design.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>When the internet was still young, website visitors used desktop and then laptop computers with wide screens to access websites. </p>
<p>Then when smart phones were developed, mobile phone users had to endlessly zoom and scroll to access and view different parts of those same websites. </p>
<p>Thankfully, this is no longer the case these days due to the revolutionary introduction of Responsive Web Design.</p>
<p>In this article, I will take you through the evolution of Responsive Web Design, the various integrations that have made it possible, and how you can start to use it in your coding projects for a better user experience.</p>
<h2 id="heading-what-is-responsive-web-design">What is Responsive Web Design?</h2>
<p>Responsive web design makes web pages render properly on a wide variety of device screen sizes without cutting short or distorting the content. </p>
<p>This doesn't mean a website will appear exactly the same way on a phone as on a laptop, for example. Rather, it means that the content of the web page adapts to different screen sizes – from large screens (desktops and laptops) to medium screens (tablets) to mobile screens (phones of various screen sizes). </p>
<p>And it does this all while retaining the same content (just perhaps arranged differently to fit each screen).</p>
<h2 id="heading-the-evolution-of-responsive-web-design">The Evolution of Responsive Web Design</h2>
<p>In the past, people mostly used desktops and laptops to view content online, because websites were optimized for those screens only. </p>
<p>But as more and more people started using mobile phones to surf the web, people started grumbling about the poor display and layouts they were seeing. </p>
<p>This meant one thing for web designers and developers: websites needed to be optimized for mobile, too! </p>
<p>In the last decade, the number of website users on mobile began to surpass that of desktops and laptops for the first time. So everyone from tech giants to small businesses started embracing a responsive web design approach.</p>
<p>Developers and designers also created the shiny new mobile-first design as well. This meant that the developers made the websites for mobile devices first, and desktop later. </p>
<p>This often meant a separate website for mobile devices and larger screens, with the same server system but different domains. </p>
<p>The original website, for example, could be <code>examplewebsite.com</code>, and the mobile version would be <code>examplewebsite.mobi</code>, or <code>m.examplewebsite.com</code>. </p>
<p>The user's device would be detected by ready-made scripts and then the appropriate domain would be rendered. This practice still exists today.</p>
<p>Apart from the two-domain method, web designers and developers can create a website for a particular screen size first (it could be desktop, tablet, or mobile), and then add what are called media queries to make the website adapt to different screen sizes. This is the mobile-first approach.</p>
<h2 id="heading-how-to-make-your-site-responsive">How to Make Your Site Responsive</h2>
<p>Integrating responsive web design approaches into a project includes every part of the code – within the HTML <code>&lt;head&gt;</code> element, the HTML structure, the CSS, and even the JavaScript. </p>
<p>I will describe these processes as clearly and in as much detail as possible.</p>
<h3 id="heading-set-the-viewport-in-the-head">Set the Viewport in the Head</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;</span>
</code></pre>
<p>Since HTML plays a huge role in defining the structure of a web page, then it definitely has something to do with making websites respond (adapt) to different screen sizes.</p>
<p>You'll need to include the meta viewport empty element in the head section of any web page that you want to optimize for different screen sizes. </p>
<p>This tells the browser to render the width of the web page to the exact width of the device. So, if the device has a width of 1200px, the web page width will be 1200px. If the device has a width of 720px, the web page width will be 720px, and so on.</p>
<p>This prevents annoying zooming in and zooming out that mobile phone users experienced in the past, which wasn't good for user experience. </p>
<p>Below is how a website looks on small phones without the <code>&lt;meta&gt;</code> viewport element: </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/without-meta-viewport.gif" alt="without-meta-viewport" width="600" height="400" loading="lazy"></p>
<p>And here's how the same website with the <code>&lt;meta&gt;</code> viewport element looks on small phones:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/with-meta-viewport.gif" alt="with-meta-viewport" width="600" height="400" loading="lazy"></p>
<p>If you are wondering which website this is, it’s a free portfolio website template I made for beginners. I will make it available to all freeCodeCamp readers very soon – so, stay tuned. :)</p>
<p>But the <code>&lt;meta&gt;</code> viewport element is not all you need to make a website adapt to different screen sizes. There's more.</p>
<h3 id="heading-css-media-queries">CSS Media Queries</h3>
<p>The most crucial tool you'll use to make your sites responsive is CSS3 Media Queries. Media queries let you write the same CSS code in different ways for multiple screens. </p>
<p>With media queries, you tell the browser to display the content in a particular way on a particular screen.</p>
<p>The basic syntax of a media query looks like this: </p>
<pre><code class="lang-css"><span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">720px</span>) {
  <span class="hljs-comment">/*CSS codes go here*/</span>
}
</code></pre>
<p>This tells the browser to execute the CSS code written within the media query when the screen width is below a 720 pixel breakpoint. The breakpoint can usually be any value between 1200 pixels and 320 pixels. </p>
<p>In the code snippets below, I’m instructing the browser to change the <code>background-color</code> to dark-grey, and the <code>color</code> to blue when the screen width is below 768 pixels.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>
      Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam
      mollitia, consequuntur aliquid nobis vitae soluta maiores expedita ipsam
      delectus molestiae!
    <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>
      Lorem ipsum dolor sit amet consectetur adipisicing elit. Consectetur
      architecto temporibus sed officiis vero, quisquam, corrupti quis veritatis
      dolor amet nostrum quam! Voluptates nam architecto enim neque nemo
      consectetur molestias unde fugit dolorum alias temporibus expedita
      doloribus deserunt laborum asperiores illum saepe, voluptate rerum quia
      sit facilis consequuntur perferendis aperiam. Nobis reiciendis debitis
      consequuntur placeat maiores voluptas, quos esse eum.
    <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>
      Lorem ipsum dolor sit amet consectetur, adipisicing elit. Minus fugiat,
      nemo rem facere cumque error. Aliquam consequatur nobis cupiditate atque!
      Fugiat amet facere magni, nulla pariatur ut ullam, vel est eum voluptatum
      dicta quis dignissimos labore repellendus. Maiores deserunt quas tempore
      impedit, corporis quae amet blanditiis voluptatum laudantium magni ipsa!
    <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
</code></pre>
<pre><code class="lang-css"> <span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">768px</span>) {
        <span class="hljs-selector-tag">body</span> {
          <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#333</span>;
          <span class="hljs-attribute">color</span>: <span class="hljs-number">#3498db</span>;
        }
     }
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/media-queries.gif" alt="media-queries" width="600" height="400" loading="lazy"></p>
<p>Several other breakpoints exist for different devices. </p>
<ul>
<li><p>320 - 480px for small phones such as iPhone 6, 7, and 5 </p>
</li>
<li><p>478 - 768px for Tablets and iPads</p>
</li>
<li><p>1025 - 1200px for desktops and large screens</p>
</li>
</ul>
<p>Some extra-large screens and TVs can take more than 1200px.</p>
<h3 id="heading-responsive-text">Responsive Text</h3>
<p>Since text size won't be the same on a mobile phone as it is on a desktop, text must be made to scale down as the device screen width reduces.</p>
<p>You can do this within the media query for each screen. And one of the ways to make it easier is to use relative units (%, rem, and em) instead of an absolute unit such as px. </p>
<p>In the HTML and CSS code snippets below, I instruct the browser to make the font size of the text 3rem on big screens, and 1.5rem on screens below a width of 768pixels:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>
   Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam
   mollitia, consequuntur aliquid nobis vitae soluta maiores expedita ipsam
   delectus molestiae!
<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>
   Lorem ipsum dolor sit amet consectetur adipisicing elit. Consectetur
   architecto temporibus sed officiis vero, quisquam, corrupti quis veritatis
   dolor amet nostrum quam! Voluptates nam architecto enim neque nemo
   consectetur molestias unde fugit dolorum alias temporibus expedita
   doloribus deserunt laborum asperiores illum saepe, voluptate rerum quia
   sit facilis consequuntur perferendis aperiam. Nobis reiciendis debitis
   consequuntur placeat maiores voluptas, quos esse eum.
<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>
   Lorem ipsum dolor sit amet consectetur, adipisicing elit. Minus fugiat,
   nemo rem facere cumque error. Aliquam consequatur nobis cupiditate atque!
   Fugiat amet facere magni, nulla pariatur ut ullam, vel est eum voluptatum
   dicta quis dignissimos labore repellendus. Maiores deserunt quas tempore
   impedit, corporis quae amet blanditiis voluptatum laudantium magni ipsa!
<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">768px</span>) {
        <span class="hljs-selector-tag">p</span> {
          <span class="hljs-attribute">font-size</span>: <span class="hljs-number">1.5rem</span>;
        }
      }
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/responsive-text.gif" alt="responsive-text" width="600" height="400" loading="lazy"></p>
<h3 id="heading-responsive-images">Responsive Images</h3>
<p>Just like text, images must scale down as screen width reduces, too. </p>
<p>Images have a fixed width and height, so when they are larger than the viewport width (screen width), a user typically has to scroll to see the whole thing, which creates a bad user experience. </p>
<p>Developers get around this by setting a max-width of 100% for all images and displaying them as block-level elements (images are inline elements by default). </p>
<p>You can set this for the images in your code individually, but to foster DRY (Do not repeat yourself) principles, you should do it in your resets for all images.</p>
<pre><code class="lang-css"> <span class="hljs-selector-tag">img</span> {
        <span class="hljs-attribute">display</span>: block;
        <span class="hljs-attribute">max-width</span>: <span class="hljs-number">100%</span>;
      }
</code></pre>
<p>Another way to make images responsive is to use the picture element in HTML. With this element, you can tell the browser to display different images that correlate to the width on different devices.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">picture</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">source</span>
        <span class="hljs-attr">media</span>=<span class="hljs-string">"(max-width: 1100px)"</span>
        <span class="hljs-attr">srcset</span>=<span class="hljs-string">"freecodecamp-large-logo.jpg"</span>
      /&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">source</span>
        <span class="hljs-attr">media</span>=<span class="hljs-string">"(max-width: 900px)"</span>
        <span class="hljs-attr">srcset</span>=<span class="hljs-string">"freecodecamp-medium-logo.jpg"</span>
      /&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">source</span> <span class="hljs-attr">media</span>=<span class="hljs-string">"(max-width: 760px)"</span> <span class="hljs-attr">srcset</span>=<span class="hljs-string">"freecodecamp-small-logo.jpg"</span> /&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">img</span>
        <span class="hljs-attr">src</span>=<span class="hljs-string">"freecodecamp-large-logo.jpg"</span>
        <span class="hljs-attr">alt</span>=<span class="hljs-string">"freeCodeCamp"</span>
        <span class="hljs-attr">style</span>=<span class="hljs-string">"max-width: 100%"</span>
      /&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">picture</span>&gt;</span>
</code></pre>
<ul>
<li>On a screen of size 1100px width and below, freecodecamp-large-logo will be shown</li>
<li>On a screen of size 900px width and below, freecodecamp-medium-logo will be shown</li>
<li>On a screen of size 760px width and below, freecodecamp-small-logo will be shown </li>
</ul>
<p>If the screen width meets none of the conditions, freecodecamp-large-logo will be shown. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/responsive-image.gif" alt="responsive-image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-responsive-layout">Responsive Layout</h3>
<p>The layout of any web page determines how the content is displayed in the browser. </p>
<p>In the past, developers had to use tables, which were not easy to control. Then came <code>float</code> and <code>clearfix</code>, which were also difficult to manage.</p>
<p>The introduction of CSS Grid and Flexbox revolutionized layouts and gave more relevance to responsive design.</p>
<h4 id="heading-flexbox">Flexbox</h4>
<p>With CSS flexbox, responsive design gained more relevance because, with it, you don't have to add too many media queries unlike when you use floats for a layout. </p>
<p>Immediately when a display of flex is assigned to the containing element, the element direction is rendered on the row by default. </p>
<p>You can later use a media query to set the direction to a column for smaller screens with the flex-direction property. The flex-direction property value has to be explicitly set to a column.</p>
<p>You can also layout the way you want the content on the web page to render with properties such as flex-grow and flex-shrink. These two properties make the element they contain grow as the screen viewport (width) increases and shrink as the viewport decreases. How cool is that? </p>
<p>In the code snippets below, the direction of the different pieces of text in their respective containers will be a row on screens higher than 768 pixels in width, and a column when the width is lower than 768 pixels. </p>
<p>I was able to do it by displaying the whole items inside the body element as flex.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container-one"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>
            Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam
            mollitia, consequuntur aliquid nobis vitae soluta maiores expedita ipsam
            delectus molestiae!
        <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container-two"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>
        Lorem ipsum dolor sit amet consectetur adipisicing elit. Consectetur
        architecto temporibus sed officiis vero, quisquam, corrupti quis veritatis
        dolor amet nostrum quam! Voluptates nam architecto enim neque nemo
        consectetur molestias unde fugit dolorum alias temporibus expedita
        doloribus deserunt laborum asperiores illum saepe, voluptate rerum quia
        sit facilis consequuntur perferendis aperiam. Nobis reiciendis debitis
        consequuntur placeat maiores voluptas, quos esse eum.
        <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container-three"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>
        Lorem ipsum dolor sit amet consectetur, adipisicing elit. Minus fugiat,
        nemo rem facere cumque error. Aliquam consequatur nobis cupiditate atque!
        Fugiat amet facere magni, nulla pariatur ut ullam, vel est eum voluptatum
        dicta quis dignissimos labore repellendus. Maiores deserunt quas tempore
        impedit, corporis quae amet blanditiis voluptatum laudantium magni ipsa!
        <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span> 
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-tag">body</span> {
          <span class="hljs-attribute">display</span>: flex;
      }

      <span class="hljs-selector-tag">div</span> {
          <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid <span class="hljs-number">#2ecc71</span>;
          <span class="hljs-attribute">margin-left</span>: <span class="hljs-number">6px</span>;
      }

      <span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">768px</span>) {
        <span class="hljs-selector-tag">body</span> {
          <span class="hljs-attribute">flex-direction</span>: column;
        }
    }
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/flexbox.gif" alt="flexbox" width="600" height="400" loading="lazy"></p>
<h4 id="heading-css-grid">CSS Grid</h4>
<p>CSS grid is more or less a hybrid and more powerful form of flexbox. Many have argued that whatever you're doing with Flexbox, you can do in fewer lines of code with Grid.</p>
<p>With CSS grid, you get to create flexible grids in a more straightforward way as you can define the columns and rows you want with the grid-auto-flow property set to either column or row.</p>
<p>You can do the same thing that we did in the Flexbox example this way with Grid: </p>
<pre><code class="lang-css"><span class="hljs-selector-tag">body</span> {
          <span class="hljs-attribute">display</span>: grid;
          <span class="hljs-attribute">grid-auto-flow</span>: column;
          <span class="hljs-attribute">gap</span>: <span class="hljs-number">6px</span>;
      }

      <span class="hljs-selector-tag">div</span> {
          <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid <span class="hljs-number">#2ecc71</span>;
          <span class="hljs-attribute">margin-left</span>: <span class="hljs-number">6px</span>;
      }

      <span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">768px</span>) {
        <span class="hljs-selector-tag">body</span> {
            <span class="hljs-attribute">grid-auto-flow</span>: row;
        } 
     }
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/grid-1.gif" alt="grid-1" width="600" height="400" loading="lazy"></p>
<p>You can learn more about Flexbox and Grid in the freeCodeCamp CSS curriculum.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>As internet users now access websites on mobile phones more than on desktops and laptops, responsive design is the way to go when it comes to making modern websites.</p>
<p>Knowing Responsive Design best practices will set you apart from other developers as you will be able to make websites that adapt to different screen sizes within the same HTML, CSS, and JavaScript files. </p>
<p>I hope this article has given you the insights you need to make responsive real-world websites.</p>
<p>Thank you for reading, and keep coding.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Your complete guide to truly responsive images ]]>
                </title>
                <description>
                    <![CDATA[ By Dane Stevens There is a lot that goes into making a website responsive, and images are a major factor and can make or break your site. With that out of the way, let's dig in: <img src="giraffe.jpg" /> Whoa! That's not quite right, let's fix tha... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/your-complete-guide-to-truly-responsive-images/</link>
                <guid isPermaLink="false">66d84e8d39c4dccc43d4d47e</guid>
                
                    <category>
                        <![CDATA[ Progressive Images ]]>
                    </category>
                
                    <category>
                        <![CDATA[ image optimization  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Image Placeholder ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Responsive Image ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 11 Jun 2019 18:30:57 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/06/giraffe-NOT-responsive-image-medium.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Dane Stevens</p>
<p><img src="https://cdn.tueri.io/274877906986/giraffe-family.jpg" alt="Responsive Images" width="4294" height="2859" loading="lazy"></p>
<p>There is a lot that goes into making a website responsive, and images are a major factor and can make or break your site. With that out of the way, let's dig in:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"giraffe.jpg"</span> /&gt;</span>
</code></pre>
<p><img src="https://cdn.tueri.io/274877906980/giraffe-NOT-responsive-image.jpg?w=700&amp;crop.width=700&amp;h=467&amp;crop.height=467&amp;crop.x=1100&amp;crop.y=700" alt="Non-responsive Girafee" width="700" height="467" loading="lazy"></p>
<p>Whoa! That's not quite right, let's fix that.</p>
<h2 id="heading-percentage-width-images-using-css">Percentage width images using CSS</h2>
<p>By definition, a responsive site has no fixed width. We can account for this by setting our image width using percentages. A percentage width can be set on the image directly using inline CSS or set globally using a CSS style sheet.</p>
<pre><code class="lang-html"><span class="hljs-comment">&lt;!-- Inline CSS --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"giraffe.jpg"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"max-width: 100%;"</span> /&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-comment">/* Global CSS style sheet */</span>
<span class="hljs-selector-tag">img</span> {
    <span class="hljs-attribute">max-width</span>: <span class="hljs-number">100%</span>;
}
</code></pre>
<p>Our image set to 100% maximum width now looks like this. Feel free to resize your browser window and see the image width change automatically.</p>
<p><img src="https://cdn.tueri.io/274877906980/giraffe-NOT-responsive-image.jpg?w=700&amp;h=467" alt="Fully-responsive Giraffe" width="700" height="467" loading="lazy"></p>
<p>Awesome! Our images are now responsive, but let's not get too excited. CSS percentage widths have a major downside: This reading pane has a maximum width of 700 pixels and our image is 3742 pixels wide or 532% larger than what we need. It's also consuming 1.55 MB of bandwidth.</p>
<h3 id="heading-so-the-image-is-huge-whats-the-big-deal">So the image is huge, what's the big deal?</h3>
<p>On a standard ADSL internet connection it is going to take 2 seconds to download that single image.</p>
<p>I'm going to assume you have more than one image on your website. If every image takes 2 seconds to download, your site will be very slow and your search ranking will take a big hit.</p>
<h3 id="heading-how-can-we-fix-this-problem">How can we fix this problem?</h3>
<p>Since we only need an image that is 700 pixels wide, let's pop open Photoshop and resize it.</p>
<p><img src="https://cdn.tueri.io/274877906980/giraffe-NOT-responsive-image.jpg?w=700&amp;h=467" alt="Giraffe Eating" width="700" height="467" loading="lazy"></p>
<p>That's better! Our image is now 700 pixels wide and weighs in at 264 KB with no loss of quality.</p>
<h3 id="heading-what-about-mobile-devices">What about mobile devices?</h3>
<p>Great question! On mobile devices, 700 pixels can be more than double what you need and 264 KB on is still slow on a mobile internet connection.</p>
<p>What if we could display different size images for different size devices?</p>
<p>Now you're thinking!</p>
<h2 id="heading-different-image-sizes-using-the-srcset-attribute">Different image sizes using the srcset attribute</h2>
<p>Let's downsize our original image and save it as three versions of 700 pixels, 480 pixels and 360 pixels. We'll name them as follows:</p>
<ul>
<li>giraffe-small.jpg - 360px @ 101 KB</li>
<li>giraffe-medium.jpg - 480px @ 151 KB</li>
<li>giraffe-large.jpg - 700px @ 264 KB</li>
</ul>
<p><img src="https://cdn.tueri.io/274877906987/giraffe-family.jpg" alt="Small Medium and Large Giraffe" width="933" height="467" loading="lazy"></p>
<p>We'll use the srcset attribute to tell the browser about our different image sizes. This tells the browser that we have three versions of this image in the sizes 360w, 480w and 700w. The "w" in this case is the same as "px".</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">img</span> 
    <span class="hljs-attr">style</span>=<span class="hljs-string">"max-width: 100%;"</span>
    <span class="hljs-attr">srcset</span>=<span class="hljs-string">"giraffe-small.jpg 360w, giraffe-medium.jpg 480w, giraffe-large.jpg 700w"</span>
/&gt;</span>
</code></pre>
<p>Some older browsers will ignore the srcset attribute. We can use the src attribute as a fallback for these browsers.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">img</span> 
    <span class="hljs-attr">style</span>=<span class="hljs-string">"max-width: 100%;"</span>
    <span class="hljs-attr">srcset</span>=<span class="hljs-string">"giraffe-small.jpg 360w, giraffe-medium.jpg 480w, giraffe-large.jpg 700w"</span>
    <span class="hljs-attr">src</span>=<span class="hljs-string">"giraffe-large.jpg"</span>
/&gt;</span>
</code></pre>
<p><img src="https://cdn.tueri.io/274877906980/giraffe-NOT-responsive-image.jpg?w=700&amp;h=467" alt="Giraffe Eating" width="700" height="467" loading="lazy"></p>
<p>Great! Now we are saving bandwidth by delivering different images to different devices.</p>
<p>This goes without saying, but you know what this means right? You'll need to create a minimum of three versions of every image on your site. If you want to support hi-dpi or retina displays, you'll need even more variations. That is an incredible amount of time that none of us have. In addition, if you re-design your site at different breakpoints, you'll need to do this all over again.</p>
<p>At Tueri, we're developers too and recognize that your time is valuable. In the next section I'll show you how we solved this problem for you.</p>
<h2 id="heading-real-time-image-processing-with-tueriiohttpstueriio">Real-time image processing with <a target="_blank" href="https://tueri.io">Tueri.io</a></h2>
<p><a target="_blank" href="https://tueri.io">Tueri.io</a> is a real-time image processing platform. We store, process, and deliver your image perfectly sized to every device.</p>
<h3 id="heading-heres-what-you-do">Here's what you do</h3>
<ol>
<li>Upload your image to <a target="_blank" href="https://tueri.io">Tueri.io</a></li>
<li>Change the image <code>src</code> to <code>tueri-src</code></li>
<li>Include <a target="_blank" href="https://github.com/tueriapp/vanilla-tueri">tueri.js</a> in your code</li>
</ol>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">tueri-src</span>=<span class="hljs-string">"https://cdn.tueri.io/274877906982/giraffe-family.jpg"</span>/&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"tueri.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<p><img src="https://cdn.tueri.io/274877906982/giraffe-family.jpg" alt="Giraffe Family" width="4562" height="3650" loading="lazy"></p>
<h3 id="heading-its-like-magic">It's like magic!</h3>
<p>Oh, and we also do:</p>
<ul>
<li>Low-quality image placeholders</li>
<li>Image lazy-loading</li>
<li>Image compression</li>
<li>Image conversion</li>
</ul>
<hr>
<p>_Originally published at <a target="_blank" href="https://tueri.io/blog/2019-03-27-your-complete-guide-to-truly-responsive-images/?utm_source=Freecodecamp&amp;utm_medium=Post&amp;utm_campaign=">Tueri.io</a>_</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
