Different images for mobile than desktop web

Topic summary

A Shopify store owner seeks to display different banner images on mobile versus desktop views.

Initial Solution Provided:

  • Use CSS media queries with .mobile-image and .desktop-image classes
  • Hide/show images based on screen width (992px breakpoint)
  • Add both image pickers to theme schema
  • Insert corresponding HTML with class names in appropriate liquid files

Key Implementation Challenges:

  • Users struggle identifying correct liquid files (theme.liquid, banner.liquid, slideshow.liquid vary by theme)
  • Placement of <style> tags and HTML snippets differs across themes (Debut, Venture, Brooklyn, Minimal, Turbo, Boundless, etc.)
  • Schema modifications work, but HTML integration remains confusing for non-developers

Simplified Solution (Page 6):
A basic static section called “desktop-mobile-banner” with:

  • Two image pickers accessible via Customize editor
  • CSS media queries at 767px breakpoint
  • Optional link field for clickable banners
  • No optimization for different resolutions/screen widths

Ongoing Issues:

  • Page speed concerns (lazy loading suggested via lazysizes library)
  • Padding/spacing adjustments needed
  • Theme-specific implementations require custom code
  • Some users report both images displaying simultaneously
  • Request for slideshow versions with multiple slides

Status: Thread remains active with users requesting theme-specific guidance. The basic section code provides a starting point but requires customization per theme architecture.

Summarized with AI on November 9. AI used: claude-sonnet-4-5-20250929.

How would you handle it @DariusWS ? Typically on my website’s I’ll use the picture element and source elements to swap out my images, but due to having a fallback for older browsers the fallback is always downloaded anyway, so two images are still downloaded:

<picture>
<source media="(min-width: 767px)" srcset="/path-for-double-resolution-desktop-image.jpg 2x,
                                         /path-for-normal-resolution-desktop-image.jpg">
<source media="(min-width: 320px)" srcset="/path-for-double-resolution-mobile-image.jpg 2x,
                                         /path-for-normal-resolution-mobile-image.jpg">
<img src="/path-for-fallback-image.jpg" alt="Some alt text for SEO">
</picture>

In this case on screens larger than 767px would download the normal resolution desktop image as well as the fallback image. The only way I really know around this is to have a parent div of an element and set a background image for the child and set the parent div to display none:

<style>
  .child {
    background-image: url('/path-to-image.jpg')
  }
  .parent {
    display: none;
  }
  </style>
<div class="parent">
<div class="child">
</div>
</div>

Personally I find working with background images irritating because you always have to give them a width and height, and for my general use I want the image to define the dimensions of the container.

I know there are some way to avoid the image loading with the picture element by using or instead of , but it’s hacky. I would like to hear your approach though if it can make me a better developer.

Most of all, these solutions are an attempt to make it as easy as possible for the users who aren’t too familiar with HTML or CSS to achieve what they want to do and arent too concerned with the background processes, as well as easier on myself by not having to rewrite theme code to work with picture elements or background images if they don’t already use them.