Products / Before/After Slider / Docs

Evergreen Before/After Slider

A drag-to-compare before/after photo slider for any website. One small script, no dependencies.

Visitors drag the divider (or use the arrow keys) to reveal the change: remodels, landscaping, turf, cleaning, detailing, design work and results photos.

What's in the download

File or folderWhat it's for
INSTALL.mdStep-by-step setup for Squarespace (every plan), WordPress, Wix, Webflow, Shopify, Ghost, Carrd and plain HTML
embed/Ready-to-paste snippets. Start here.
evergreen-before-after.zipThe WordPress plugin. Upload it under Plugins → Add New → Upload Plugin.
dist/before-after-slider.min.jsThe compact script, about 5 KB gzipped. Use it if you upload the file to your site.
dist/before-after-slider.jsThe readable script, for anyone who wants to look inside
demo/index.htmlDouble-click to try it offline
LICENSE.txtWhat your license allows

The whole idea in two lines

<div class="eg-ba" data-before="before.jpg" data-after="after.jpg"></div>
<script src="before-after-slider.min.js" defer></script>

Every option is another data- attribute on that div. See Options in INSTALL.md.

For developers

Sliders start automatically, including ones added to the page later (Squarespace AJAX pages, page builders, tabs).

EvergreenBA.init();            // scan the whole page again
EvergreenBA.init(element);     // scan inside one element
sliderDiv.egBA.set(25);        // move a slider's divider to 25%

Questions or installation help: use the contact page at evergreencode.store.

Installation

Every install has the same two parts:

  1. The script: loaded once per page (or once for the whole site).
  2. A slider: one line of HTML wherever you want a slider, with your two photo links.

Step 1: Prepare your photos

  • Take both photos from the same spot and angle.
  • Crop them to the same size, for example 1600 × 1000 pixels.
  • Keep each one under about 400 KB so the page loads fast.

Then put them online so each has a web address. Upload them to your site's media library or file manager, or anywhere that gives you a direct image link (ending in .jpg, .png or .webp).

Step 2: Choose a snippet

File in embed/Use it when
1-code-block-embed.htmlYou want one paste that does everything: the slider plus the script. Easiest.
2-site-wide-script.htmlYour builder has a site-wide footer code box (Squarespace Code Injection, Wix Custom Code, Webflow, Shopify theme). Paste it there once.
3-slider-only.htmlThe script is already loaded (by file 2, the WordPress plugin, or another slider on the page), and you're adding another slider.
4-hosted-file-embed.htmlYou can upload files to your site and want the shortest code.

In every snippet, replace PASTE-BEFORE-IMAGE-LINK and PASTE-AFTER-IMAGE-LINK with your two photo links.

Most builders only run custom code on the published page, not inside the editor. If you see a blank box while editing, check the live page or preview.

Squarespace

Works on Squarespace 7.1 and 7.0, in any template, on every plan.

Core, Plus or Advanced plans (legacy Business and Commerce)

Getting photo links: edit any text block, highlight a word, click the link icon, then choose File → Upload file and upload your photo. Squarespace hosts it at an address like /s/before.jpg. Remove the temporary link afterward. Or add an Image Block, publish, right-click the photo on your live site and choose Copy Image Address.

One slider: add a Code Block where the slider should go, paste embed/1-code-block-embed.html, and put in your two photo links.

Several sliders across your site:

  1. Go to Settings → Advanced → Code Injection (or Website → Pages → Custom Code → Code Injection). Paste embed/2-site-wide-script.html into Footer and save.
  2. For each slider, add a Code Block and paste embed/3-slider-only.html.

In Fluid Engine, drag the Code Block's corner to make it as wide as you want. The slider fills the block and sets its own height from your photos.

Basic plan (legacy Personal): no upgrade needed

Basic and Personal plans don't run Code Blocks or Code Injection, but Markdown Blocks accept HTML on every plan.

This is a widely used workaround, but Squarespace doesn't officially support it and could change how Markdown Blocks behave in the future.

  1. Upload the script file. Use the same link → File → Upload file trick to upload dist/before-after-slider.min.js. It will be at /s/before-after-slider.min.js.
  2. Load it from your footer. Click Edit, hover over the footer, click Edit Footer, add a Markdown block and paste: ``html <script src="/s/before-after-slider.min.js" defer></script> `` The block looks empty on the page. That's normal. If your site has no footer, put this line in a Markdown block on each page that has a slider.
  3. Add a slider. Add a Markdown block where the slider should go and paste the line from embed/3-slider-only.html. Keep it on one line, so Markdown leaves it alone.

Don't paste the whole script into a Markdown block. Markdown can change symbols in the code, so always load it from the uploaded file.

WordPress

Works with the Block Editor, Classic Editor, Elementor, Divi, Beaver Builder and any theme. Needs WordPress 5.8+ and PHP 7.4+.

  1. Go to Plugins → Add New → Upload Plugin, choose evergreen-before-after.zip from your download, click Install Now, then Activate.
  2. Add a Shortcode block (or your page builder's shortcode widget) and paste: `` [evergreen_before_after before_id="123" after_id="124"]

Finding an image ID: go to Media → Library and click the photo. The number after item= in the address bar is its ID. With IDs, WordPress serves a properly sized image and uses the alt text from your Media Library.

Or use image links: [evergreen_before_after before="https://…/before.jpg" after="https://…/after.jpg"]

The script only loads on pages that contain a slider.

Shortcode options: before_label, after_label, before_alt, after_alt, start, orientation, mode, ratio, intro (same as the options below, with _ instead of -), plus size (medium_large, large or full, when using IDs) and class.

[evergreen_before_after before_id="123" after_id="124" orientation="vertical" ratio="4/3" intro="true" before_label="Day 1" after_label="Day 90"]

Without the plugin: paste embed/1-code-block-embed.html into a Custom HTML block.

If a caching or speed plugin breaks the slider, exclude before-after-slider.min.js from its "delay JavaScript" or "combine JS" settings.

Wix

Add Embed Code → Embed HTML (an HTML iframe element), paste embed/1-code-block-embed.html and use full photo links starting with https://. Drag the element to the size you want. Upload photos to the Wix Media Manager and copy each one's link.

Webflow

Add an Embed element and paste embed/3-slider-only.html. Paste embed/2-site-wide-script.html into Site settings → Custom code → Footer code once. Custom code needs a paid site plan.

Shopify

Online Store 2.0 themes: add a Custom Liquid section and paste embed/1-code-block-embed.html. Upload photos under Content → Files and copy their links.

Ghost

In the editor, add an HTML card and paste embed/1-code-block-embed.html. For many sliders, paste embed/2-site-wide-script.html into Settings → Code injection → Site Footer once and use embed/3-slider-only.html in each card.

Carrd

Add an Embed element, set its type to Code, and paste embed/1-code-block-embed.html. Embeds need a Carrd Pro plan.

Any website (HTML)

Upload dist/before-after-slider.min.js and use embed/4-hosted-file-embed.html.

Options

Add any of these to the <div class="eg-ba" …> tag:

AttributeWhat it doesExample
data-before / data-afterYour two photo links (required)data-before="/s/before.jpg"
data-before-alt / data-after-altPhoto descriptions for screen readers and search enginesdata-after-alt="New patio"
data-before-label / data-after-labelText on each side; use "" to hidedata-after-label="Day 90"
data-startWhere the divider starts, 0–100data-start="30"
data-orientationvertical for a top/bottom revealdata-orientation="vertical"
data-modehover to follow the mouse on desktop (phones still drag)data-mode="hover"
data-ratioForce a shape; both photos are cropped to fitdata-ratio="16/9"
data-introA quick wiggle the first time it scrolls into view, so visitors know to dragdata-intro="true"

Brand colors

Add this to your site's custom CSS (Squarespace: Design → Custom CSS, available on every plan; WordPress: Appearance → Customize → Additional CSS) and change the values:

.eg-ba {
  --eg-ba-line: #ffffff;          /* divider line */
  --eg-ba-line-width: 3px;
  --eg-ba-handle-bg: #ffffff;     /* round handle */
  --eg-ba-handle-fg: #1d1d1f;     /* arrows on the handle */
  --eg-ba-handle-size: 46px;
  --eg-ba-label-bg: rgba(0,0,0,.55);
  --eg-ba-label-fg: #ffffff;
  --eg-ba-radius: 8px;            /* rounded corners; 0 for square */
  --eg-ba-font: inherit;          /* uses your site's font */
}

To style one slider differently, add a class (class="eg-ba gold") and target .eg-ba.gold { … }.

Troubleshooting

A red box says to add both images. One of the photo links is missing or misspelled.

Nothing shows. Check the published page, not the editor. Make sure the script is loaded on that page. On Squarespace Basic or Personal, use the Markdown Block method.

The code shows up as text. On Squarespace, use a Markdown block (not a Text block) and keep the slider on one line. In WordPress, use a Shortcode or Custom HTML block.

The two photos don't line up. Crop both to identical dimensions, or add data-ratio="16/9" so both are cropped to the same shape.

Still stuck? Use the contact page at evergreencode.store. Installation help is included for 6 months.

Changelog

1.0.0 (2026-10-30)

First release.

  • Drag-to-compare before/after slider; horizontal or vertical; optional hover mode.
  • Labels that fade out of the divider's way, starting position, fixed aspect ratio, and an optional first-view "wiggle" hint.
  • Touch dragging that doesn't block page scrolling; keyboard and screen-reader support; respects reduced motion.
  • Brand colors through CSS variables; customer CSS always wins over the defaults.
  • WordPress plugin with an [evergreen_before_after] shortcode that takes Media Library image IDs.
  • Install guides for Squarespace (every plan, including Basic/Personal via Markdown Blocks), WordPress, Wix, Webflow, Shopify, Ghost, Carrd and plain HTML.