How To Use Responsive Images
Based on Andreas Bovens' article [Responsive Images: Use Cases and Documented Code Snippets to Get You Started](https://dev.opera.com/articles/responsive-images/) we will look at four use cases for responsive images: - Change image sizes based on responsive design rules (the sizes use case) - Optimize for high-dpi screens (the dpi use case) - Serve images in different image formats to browsers that support them (the mime use case) - Serve different art depending on certain contextual factors (the art direction use case) We'll look at some example native responsive images and how they apply to these use cases. ## Viewport Size Based The most basic case is to provide different images based on the width of the viewport. The idea is to not load huge images for devices that don't need or want them. Since we're only worried about sizes we can use `srcset` to indicate the sizes that we want to use. ```css
src="opera-400.jpg" alt="My House"
```
## DPR based
We can also use responsive images to handle images that will look good regardless of the DPR factor of the device.
Some modern displays have up to 5x resolution so the standard image can range from 1x1 to o5x5 pixels per logical pixel
```css
```
## Media Query-like conditions
```css
```
When you use the srcset and sizes attributes on an `