Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

HTML Responsive Images Image Delivery with Srcset and Sizes Using Srcset

I can not figure out what I am coding wrong, can anyone point me in the right direction?

Can not figure out what to input into the srcset, can anyone tell me what and why I need to input in the code?

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Responsive Images</title>
    <link rel="stylesheet" href="normalize.css" />
    <link href='http://fonts.googleapis.com/css?family=Nunito:400,300' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="main.css" />
    <script src="picturefill.min.js" async></script>
  </head>
  <body>

    <div class="wrapper">

      <img
        srcset="banner-large.jpg 2048w,
                banner-medium.jpg 1400w,
                banner-small.jpg  800w"
        src="banner-medium.jpg"
        alt="Photograph of Nick Pettit in front of trees."
        class="banner-image"
        />

      <div class="content-block">

        <div class="profile-description">

          <div class="profile-image">
            <img
              srcset="photo-@2x.jpg"
              src="photo-@1x.jpg"
              alt="Photograph of a flower."
              />
          </div>

          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas posuere nec quam vitae aliquet. Etiam sodales feugiat gravida. Donec tincidunt facilisis arcu, ut sagittis eros iaculis a. Nam fringilla erat id lorem pellentesque ornare. Curabitur sed interdum tellus. Etiam imperdiet, dui id condimentum ullamcorper, lectus nibh venenatis lectus, id ullamcorper nibh nibh id dolor. Suspendisse tempor turpis vel commodo consequat. Phasellus at posuere velit. Sed vehicula lacinia mauris sit amet mollis. Etiam semper leo blandit massa molestie congue. Sed ac purus ipsum.</p>
          <p>Integer dignissim ultrices lacus tincidunt aliquet. Cras maximus eleifend felis. Pellentesque in nulla condimentum, aliquet orci sed, gravida velit. Pellentesque mattis ex at magna consectetur porta. Aenean eget volutpat urna. Maecenas sed nisl sit amet tortor vulputate vulputate non nec elit. Mauris bibendum erat nec purus finibus, eget molestie dolor placerat. Pellentesque at massa et ligula sagittis gravida. Nunc libero dolor, luctus ac imperdiet ac, suscipit nec nibh. Ut non diam urna.</p>
          <p>Cras blandit at urna sagittis consequat. Integer tristique mollis metus, at varius leo imperdiet vitae. Donec a porta tellus. Sed sit amet euismod urna. Vestibulum varius urna vitae odio eleifend, et consectetur felis congue. Sed vulputate mattis mauris, eget euismod ante condimentum nec. Integer augue ex, pharetra vitae rutrum a, tristique vitae mauris.</p>
        </div>

      </div>

    </div>


  </body>
</html>

2 Answers

Steven Parker
Steven Parker
221,450 Points

The instructions say that "the @1x image that's already present comes second", so instead of replacing it, leave it in there and put the new image in front of it. A "srcset" can have number of images separated by commas.

Also include a descriptor after the name so the browser will know when to use the new image. The image already there is followed by a pixel density descriptor that can serve as an example.

You can refer to the MDN page if you need more details on the "img" element or the "srcset" attribute.

Happy coding!

Mr. Parker, what is incorrect about this code? "photo-@2x.jpg, @1x.jpg"

Steven Parker
Steven Parker
221,450 Points

The original code had "photo-@1x.jpg 1x", which should remain as-is. And the new filename needs a descriptor so the browser will known when to apply it (it is treated as "1x" by default).