Skip to content

Before and After Image Slider for Shopify

Drag-to-compare before and after image slider for Shopify with vertical or horizontal divider, touch and keyboard control, and optional side text.

Also known as: before after slider, image comparison slider, before and after comparison, drag to compare images

Preview with sample data

Open in new tab

Liquid code

A before and after image slider for Shopify that lets shoppers drag a divider across two photos of the same subject. It suits room makeovers, restorations and care products. Copy section.liquid into your theme's sections folder and add it from the theme editor as "WDS Before and after".

How it works

Both images fill the same frame. The "before" layer sits on top and is clipped at the divider, so moving the divider reveals more of the "after" image underneath. Shoppers can drag the handle, click anywhere on the image, or swipe on a touch screen. On touch screens, a mostly vertical swipe still scrolls the page.

An optional heading and text sit above the images or beside them. Side layouts stack on narrow screens. If both Heading and Text are empty, the images take the full width. Each image can show a small label in its corner.

Customization

All in the theme editor:

  • Heading, Text and Text position: choose Above the images, Left of the images or Right of the images.
  • Before image and After image: the focal point you set on an image in Shopify is respected when it is cropped.
  • Before label and After label: rename them to suit the comparison, or clear them to hide the labels.
  • Start position: where the divider rests on load, from 5% to 95%.
  • Divider: Vertical (drag left and right) or Horizontal (drag up and down).
  • Aspect ratio: Square, Standard, Photo, Wide, Portrait or Match the image.
  • Background, Text and Accent colors: the accent colors the keyboard focus ring.
  • Side padding, Top padding and Bottom padding.

Use cases

  • Home makeover and renovation shops: show a room before and after by dragging a divider across two photos
  • Restoration businesses: compare worn and restored items in a vertical or horizontal slider
  • Skincare and care products: show visible results with optional side text beside the images
  • Touch and keyboard users: drag with a finger or move the divider with the keyboard

Accessibility

The slider is a native range input, so arrow keys, Page Up, Page Down, Home and End all work. Slider label names it for screen readers, and the current position is announced with both labels, such as "Before 30%, After 70%". The handle shows a visible focus ring. Each image uses its alt text from Shopify, falling back to its label or the heading.

Usage notes

This section requires an Online Store 2.0 theme and does not depend on the theme's own CSS or JavaScript.

The preview uses sample data for an invented store. Its photos are from Unsplash, and the "before" image is the same photo with its colors reduced through URL parameters. section.liquid contains no photos, so upload your own. Until then, placeholder illustrations appear.

Each section holds one pair of images, so add the section again for more comparisons. There is no auto-play. With a horizontal divider on touch screens, only the handle drags the slider. Use two photos with the same framing and proportions, otherwise the comparison will not line up. With Match the image, the frame takes its ratio from the before image, or from the after image if there is no before image. Only use comparison photos that honestly show what your product does.

Before and After Image Slider for Shopify at a glance

Framework
Shopify
Code
Liquid
JavaScript
Not needed
Dependencies
fonts.googleapis.com
Layout
Responsive, works on mobile
Category
Galleries
License
Free for personal and commercial use

Questions about this section

Can I use the Before and After Image Slider for Shopify code for free?

Yes. You can copy or download the Liquid code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my Shopify store?

Create a new section named shopify-before-after in your theme code editor, paste the Liquid code and save. Then add the section to a page in the theme editor. It works with Online Store 2.0 themes.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

How to install

  1. In your Shopify admin, go to Online Store > Themes, open the theme's menu and choose Edit code.
  2. Under Sections, add a new section named shopify-before-after, replace its contents with the Liquid code above and save.
  3. Open the theme editor, choose Add section and add it to the page.

Requires an Online Store 2.0 theme. Try it on a copy of your theme first. WebDevSnippets is not affiliated with or endorsed by Shopify.

Before and After Image Slider for Shopify – Shopify galleries component screenshot
Before and After Image Slider for Shopify · Shopify Galleries

More Galleries

CSS Grid Bento Photo Gallery – Pure CSS galleries preview

CSS Grid Bento Photo Gallery

Bento-style photo gallery with mixed tile sizes from CSS Grid spans, hover captions and a keyboard-friendly dialog lightbox.

Masonry Image Gallery – Pure CSS galleries preview

Masonry Image Gallery

Pure CSS masonry image gallery using multi-column layout, with hover and focus captions that slide up over each photo. No JavaScript needed.

Polaroid Photo Gallery – Pure CSS galleries preview

Polaroid Photo Gallery

Pure CSS polaroid gallery on a cork board: tilted photo frames with tape and handwritten captions that straighten and lift on hover or focus.

Filterable Portfolio Gallery – Bootstrap 5 galleries preview

Filterable Portfolio Gallery

Dark Bootstrap 5 portfolio gallery with pill filter buttons, automatic category counts, fade-in tiles and a screen reader status message.

Gallery with Lightbox – Tailwind CSS galleries preview

Gallery with Lightbox

Tailwind CSS mosaic image gallery that opens an accessible lightbox with captions, arrow-key and swipe navigation, focus trap and preloading.