jekyll-before-after
A jekyll-before-after demo: a vertical drag-to-reveal comparison of Egypt’s new capital, desert in 2017 and a city under construction in 2024. NASA Landsat imagery, public domain.
Open Source Plugin ∙

jekyll-before-after

A Jekyll plugin that adds a before_after Liquid tag for drag-to-reveal image comparison sliders, built on the img-comparison-slider web component.

jekyll-before-after adds a before_after Liquid tag for drag-to-reveal image comparisons in Jekyll. It wraps the proven img-comparison-slider web component, which has zero dependencies, is fully accessible, and works on GitHub Pages. You get horizontal or vertical layouts, keyboard navigation, touch support, and theming with CSS custom properties.

Installation

Add to your Gemfile:

gem "jekyll-before-after"

Add to _config.yml:

plugins:
  - jekyll-before-after

Then run bundle install. That’s it. There’s nothing else to configure, and the plugin adds the library script to every page for you.

Usage

{% before_after
  before="/images/before.jpg"
  after="/images/after.jpg"
%}

Options

Option Default Description
before (required) Path to the “before” image
after (required) Path to the “after” image
orientation horizontal horizontal or vertical

Horizontal comparison

{% before_after
  before="/images/main-street-2018.jpg"
  after="/images/main-street-2024.jpg"
%}

Vertical comparison

{% before_after
  before="/images/building-2015.jpg"
  after="/images/building-2025.jpg"
  orientation="vertical"
%}

You can put more than one slider on the same page.

Demo

Horizontal: Limerick Facade Restoration

Before After

Vertical: Egypt’s New Capital (NASA Landsat)

Before After

Styling

Every visual property is set with a CSS custom property. Target the img-comparison-slider element:

img-comparison-slider {
  --divider-width: 4px;
  --divider-color: #fff;
  --handle-width: 60px;
  --handle-height: 60px;
  --handle-opacity: 0.3;
  --handle-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

See the img-comparison-slider docs for the full list of CSS custom properties.

Interaction

  • Drag the divider to reveal
  • Click anywhere on the image to jump the slider to that position
  • Keyboard: focus the slider and use arrow keys
  • Touch and stylus supported via Pointer Events API

How it works

The plugin wraps the lightweight img-comparison-slider web component and loads it from a CDN. The Liquid tag turns your <img-comparison-slider> <img slot="first" src="" alt="Before"> <img slot="second" src="" alt="After"> </img-comparison-slider> markup into the web component’s format, and the plugin adds the library script to the page for you.

There’s no configuration required. Add the gem to your Gemfile, register it in your _config.yml, and use the tag. The library script and styles get added to every page that has a slider.