My website images look blurry for users with retina displays. (For example, on the Retina MacBook Pro).
How do I serve high-resolution images to visitors with retina displays, but standard-sized images to everyone else, while keeping the image the same apparent size?
In your HTML, create a
<div>like so:And in your CSS, add:
The magic here is in the CSS
@mediaquery. We have a double-sized image (ninja-devices@2x.png) that we sub-in when the device reports a ‘device pixel ratio’ of 1.5 (144 dpi) or more. Doing it this way allows you to save on bandwidth by delivering the original, smaller image to non-retina devices, and of course it looks great on retina devices.Note:
This answer was updated in 2016 to reflect best-practice.
min-device-pixel-ratiodid not make it in to the standard. Instead,min-resolutionwas added to the standard, but desktop and mobile Safari don’t support it at the time of writing, (thus the-webkit-min-device-pixel-ratiofallback). You can check the latest information at: http://caniuse.com/#feat=css-media-resolution.