Shopify Development

Smooth Product Galleries: Troubleshooting Image Flickering on Shopify Themes

Hey everyone, it's your friendly Shopify expert dropping in with some insights from a recent community discussion! We've all been there: you launch a beautiful new product page, only to notice a tiny, annoying flicker or blink from your product images. It's a small detail, but it can really impact how professional your store feels and even deter potential customers. This exact issue popped up recently with the Purity theme, specifically the product gallery's secondary images, and the community had some fantastic ideas on how to tackle it.

Our fellow store owner, Iulia1, kickstarted the conversation, noticing that when their product page first loaded, the second image in the gallery would briefly flicker/flash before settling. This wasn't happening due to interaction; it was right there on initial page load. Sound familiar? Iulia1 even shared a helpful GIF to illustrate the problem:

Animated GIF showing a product image flickering on a mobile screen

Browser developer tools inspecting Shopify product gallery CSS for flicker issues
Browser developer tools inspecting Shopify product gallery CSS for flicker issues

Understanding the Flicker: The Flash of Unstyled Content (FOUC)

So, what's actually going on here? As sadik_ShopiDevs and HamidEjaz pointed out in the forum, this kind of flicker is typically a classic case of what we in the web world call FOUC – Flash of Unstyled Content. Essentially, your browser renders the HTML and images first in their default state. Then, a split second later, the theme's JavaScript kicks in to initialize the product gallery (think sliders, carousels, etc.). During that brief gap, the browser might show all your gallery images laid out, or the second image in an unintended position, before the JavaScript applies its final styling and positioning. It's like seeing behind the curtains for a moment!

This often happens because the product gallery's JavaScript initializes after the gallery HTML and images have already been rendered. The browser briefly displays the second slide in its default, unstyled state, and then the theme’s slider script applies its final position, visibility, or opacity settings. This can be particularly noticeable on slower connections or devices, or with themes that have complex gallery scripts.

First Steps: Theme Integrity & App Conflicts

Before diving into code, it's always smart to rule out the simpler, more common culprits. These initial troubleshooting steps can save you a lot of time and effort:

1. Test an Untouched Copy of Your Theme

As sadik_ShopiDevs wisely suggested, the first diagnostic step is to isolate the problem. Go to your Shopify admin:

  • Online Store → Themes → Add theme → Visit Theme Store

Install a fresh copy of your current theme (like Purity) or ensure your existing theme is fully updated. Preview the same product without publishing the new theme. If the flicker still appears, it's highly likely a core theme issue. In this case, gather details (screen recording, product URL, browser, device, theme version) and report it to your theme developer's support team (e.g., NextSky for Purity).

2. Disable Recently Added App Embeds

Shopify apps are fantastic for extending functionality, but they can sometimes interfere with core theme scripts. Temporarily disable any apps that interact with product images or the product page layout. This includes:

  • Image zoom apps
  • Variant image apps
  • Product gallery enhancement apps
  • Review apps that inject elements onto the product page
  • Page optimization or caching apps

An app script might be re-rendering the gallery after the theme initializes it, leading to the flicker. If disabling an app resolves the issue, you've found your culprit and can then seek an alternative app or contact the app developer for a fix.

Diving Deeper: Code-Level Solutions

If the above steps don't resolve the flicker, it's time to look under the hood. This usually involves custom CSS or JavaScript adjustments.

Browser developer tools inspecting Shopify product gallery CSS for flicker issues

3. Implement CSS to Hide Inactive Slides Until Initialized

This is a common and effective fix for FOUC. The idea, as highlighted by sadik_ShopiDevs and HamidEjaz, is to hide non-active slides until the gallery's JavaScript has fully initialized and applied its styling. Once the slider script adds a specific class (e.g., is-initialized, flickity-enabled, or swiper-wrapper[aria-live]) to the gallery container, the CSS can then reveal the active slide.

A general approach might look like this:

.product-media-gallery:not(.is-initialized) .product-media-item:not(:first-child) {
  visibility: hidden;
  opacity: 0;
}

Important: The class names (.product-media-gallery, .is-initialized, .product-media-item) must precisely match those used in your specific theme's markup. Use your browser's developer tools to inspect the product gallery and identify the correct selectors and initialization classes. Adding incorrect code could hide your gallery permanently!

For mobile-specific flickers, tim_tairli provided an excellent solution for the Purity theme that targets the media gallery on smaller screens:

@media (max-width:767px) {  /* on mobile */
  media-gallery {
    opacity: 0;             /* make media gallery transparent */
    transition: opacity 0.3s linear;
  }

  media-gallery:has(.swiper-wrapper[aria-live]) {
    opacity: 1;             /* when slider initializes, make it visible */
  }
}

This code makes the entire media gallery transparent on mobile until the slider (identified by the .swiper-wrapper[aria-live] class) has initialized, then smoothly fades it in. This prevents the visible redraw that can occur when theme code replaces the entire media gallery HTML on mobile.

4. Check Image Loading Attributes

Image loading attributes, particularly loading="lazy", can sometimes contribute to flickering if not implemented correctly. As Moeed and devcoders pointed out:

  • The first product image should typically load eagerly because it's immediately visible.
  • Secondary images can use lazy loading to improve page load performance, but lazy loading itself shouldn't cause repeated visibility changes.
  • Check whether the second image has conflicting loading, animation, opacity, or transition attributes that might cause it to briefly appear before the gallery script takes over.

You can often find and modify these settings within your theme customization options. If not, you might need to edit theme files like main-product.liquid or product-media-gallery.liquid to adjust the loading="lazy" attribute.

5. Inspect Product Gallery Files

For advanced users, directly inspecting the theme's liquid, CSS, and JavaScript files can reveal the root cause. Look for files with names similar to:

  • main-product.liquid
  • product-media-gallery.liquid
  • product-gallery.liquid
  • component-slider.css
  • product-media.js
  • theme.js

In these files, pay close attention to:

  • Whether inactive gallery slides have a visible default state before the slider receives its initialized class.
  • Any JavaScript that re-renders images or swaps placeholder images.
  • CSS transitions or opacity animations applied during page load that might be causing the flash.

When to Call in the Experts

If you've tried these solutions and the flicker persists, or if you're uncomfortable making direct code edits, it's always best to seek professional help. Your theme developer (e.g., NextSky for the Purity theme) is often the first point of contact for theme-specific bugs.

For broader Shopify development issues, complex theme customizations, or if you're looking to start a new Shopify store and want to ensure a flawless setup from day one, don't hesitate to reach out to Shopify experts like the team at Shopping Cart Mover. We specialize in ensuring your store not only looks great but performs flawlessly, providing a smooth and professional experience for all your customers.

Conclusion

A flickering product image might seem like a minor detail, but it can significantly detract from your store's professionalism and user experience. By understanding the causes (like FOUC) and systematically troubleshooting – from checking theme integrity and app conflicts to implementing targeted CSS and inspecting code – you can achieve smooth, seamless product galleries. A polished, high-performing store builds trust and encourages conversions, making these optimizations well worth the effort.

Share:

Use cases

Explore use cases

Agencies, store owners, enterprise — find the migration path that fits.

Explore use cases