Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Design

What is the best way to maintain and handle Retina Graphics (@2x) on your website?

When I'm making a website, how do I make sure that non-retina devices get their normal 1x images and retina devices get their @2x or even @3x images on specific devices?

1 Answer

Ryan Field
PLUS
Ryan Field
Courses Plus Student 21,242 Points

Hi, Zack. For logos and icons and other small images, using SVGs will keep the images sharp regardless of device pixel density. If you are unable to use SVGs or are using images for something other than menu icons or logos, then you can usually ensure sharp images and prevent pixellation by ensuring that the images are at least twice the size of the desired display size. (I.e.: If you have a 50px by 50px logo, make sure the source image is 100px by 100px and then scale it down with CSS.) This still doesn't account for devices with resolutions higher than 2x normal, but those types of screens are not yet used that widely in devices, so this is a safe practice for now.

The other method is to use a new feature called srcset for img tags. This is not yet supported that widely (but can be used with a polyfill), but it works by allowing you to state which src the browser should use depending on pixel density. You can get more information about srcset here.

Thanks, Ryan! That's awesome. Exactly what I was looking for.

Ryan Field
Ryan Field
Courses Plus Student 21,242 Points

You're welcome! I just learned about srcset a few weeks ago, and it should be a great way to ensure nice images once it's gotten wider support! :)