@amalkarim
Posted
Hi Bryan,
You can achieve that using <picture>
element tag.
Instead of
<img src="/static/media/some-image.png" alt="creations card">
You can use this:
<picture>
<source media="(min-width:768px)" srcset="/static/media/desktop-image.png">
<img src="/static/media/mobile-image.png" alt="creations card">
</picture>
You can add more than one <source>
element if you want several breakpoints.
"The browser will look for the first <source> element where the media query matches the current viewport width, and then it will display the proper image (specified in the srcset attribute). The <img> element is required as the last child of the <picture> element, as a fallback option if none of the source tags matches." (HTML Tag Pictures)
Hope this helps. Happy coding!
Marked as helpful