Home / Snippets / How To Implement Responsive Images For Different Screen Sizes
How To Implement Responsive Images For Different Screen Sizes cover

How To Implement Responsive Images For Different Screen Sizes

663

2 years ago

0 comments

In this short snippet, you will learn the ways to Implement Responsive Images For Different Screen Sizes and ensure that your images are well optimized for the right screen size.
Let's right away jump into the code.
<picture>
	<source srcset="xl-img.jpg" media="(min-width: 1200px)">
	<source srcset="lg-img.jpg" media="(min-width: 1000px)">
	<source srcset="md-img.jpg" media="(min-width: 800px)">
	<source srcset="sm-img.jpg" media="(min-width: 600px)">
	<img src="xs-img.jpg" alt="Small Image Alt Tag Here" style="width: auto;">
</picture>
The code above makes use of the picture tag with multiple source tag that has different image media query. Now depending on the screen size, the image source will be automatically updated.
notion avatar

Alaz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

If you like our tutorial, support us by being our Patreon or buy us some coffee ☕️

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this