Responsive Images for web

Aneeqa Khan
2 min readSep 2, 2022

Recently I learned a new thing about responsive images and want to share it here.

As we all know, we can create responsive images through CSS and media queries but <picture> element allow us to show multiple images according to the browser viewport.

With CSS

First, let's see an example of a responsive image using CSS

<img
src="./src/desktop-img.png"
alt="desktop"
class="responsive"
width="100%"
/>

and give it CSS properties

.responsive {
width: 100%;
height: auto;
}

As you can see, image will get adjusted according to the width of the screen but this solution is not very convenient on smaller screens if the image is designed for large screens and also if the image contains text then that information can get lost.

With Picture element

<picture> element gives us the flexibility to use different images for different screens.
The <picture> element contains two tags: one or more <source> tags…

--

--

Aneeqa Khan
Aneeqa Khan

Written by Aneeqa Khan

I’m a frontend web and mobile developer specialized in web/mobile designs and frontend frameworks. I usually work with React, React Native, Next and TypeScript.

Responses (1)