1. Home
  2. Productivity tools
  3. Before & After Slider Generator

Before & After Slider Generator

For site owners who show a result, such as a renovation or a retouch, with a draggable slider.

Free, no sign-up. Runs in your browser; see “Private by design” for the one online step.

Free workspace included. Docs, spreadsheets, notes and tasks that save on your device. No sign-up.Take a look

How to use Before & After Slider Generator

  1. Enter the two image addresses and the alt text.
  2. Drag the slider in the preview.
  3. Copy the HTML and CSS.

Features

  • One range input clips the top image with CSS
  • Labels on both sides
  • Alt text for both images
  • Start position and aspect ratio
  • Preview with files from your device before you upload anything

Supported formats

Input

  • Typed addresses

You get

  • HTML and CSS

Private by design

The snippet is built locally and files you choose from your device are never uploaded. If you type an https image address, your browser loads that image from its own site to draw the preview; nothing else is sent. How local processing works

Good to know

  • The snippet uses a one-line oninput attribute; sites with a strict Content-Security-Policy need to move it into a script file.
  • Both images should have the same proportions.

Guide

Adding a before and after image slider with plain HTML and CSS

A before and after slider shows a change by letting the visitor drag a handle across two pictures. It suits renovations, retouching, restorations and product improvements. Many ready-made sliders are plugins that load scripts and libraries. This generator writes a small block of HTML and CSS that does the same job with a single range input.

How it works

Two images are stacked in a box of the same size. The top image is clipped with clip-path: inset(0 0 0 var(--pos)), which hides the left part up to the position and reveals the image below. A range input covers the box with zero opacity, so the visitor drags anywhere and the value changes. The input’s oninput attribute copies its value into the --pos variable on the container, which moves the clip and the white divider line.

What to enter

Give the address of the before image and of the after image, as you will use them on your site, such as images/before.jpg. Add alt text for each that describes what the picture shows. Set the left and right labels, which default to Before and After, the starting position from 0 to 100 and the aspect ratio, such as 16 / 9. Both images should have the same proportions so that features line up when the divider moves.

The preview

To try the slider before you upload anything, choose files from your device in the preview fields. They are used only to draw the preview here, so the code keeps the addresses you typed. If you type an https address, your browser loads that image from its own site to draw the preview. Drag across the preview to see how it behaves, and use “Clear files” to reset.

Accessibility and loading

Alt text is the most important part for accessibility and search, so the tool warns when either is empty. The range input is real, so the keyboard works. For speed, use images of a sensible size and format, such as WebP or optimised JPEG, and consider adding loading="lazy" if the slider is far down the page.

A worked example

The defaults describe a living room: before images/before.jpg with the alt text “Living room before the renovation”, after images/after.jpg with “Living room after the renovation”, labels Before and After, a start of 50 and a 16 / 9 ratio. The output has a div with the class ba-slider and --pos: 50%, two img elements, two labels, a divider and the range input, followed by a style block with the rules. Dragging the preview to 20% changes the variable to 20% and moves the divider.

Limits

The snippet uses one inline event handler, so sites with a strict content security policy need to move it into a script file. It supports one slider per snippet and does not include touch-specific tuning, vertical sliders or labels that follow the divider. The tool does not host images or check that the addresses work. Test the finished slider on a phone as well as a computer.

Choosing good pictures

Take both photos from the same position, with the same framing and lighting, so that the only difference is the change you want to show. Crop them to the same size before you add them. A subtle change shows better when the viewer can drag slowly, so start the slider near the middle and label the sides clearly.

Checked against the current version of the Before & After Slider Generator on .

Frequently asked questions

Why does my site block the slider?

A strict Content-Security-Policy forbids inline event handlers, which the snippet’s oninput attribute is. Move that one line into your own script file: select the range input, listen for the input event and set the --pos variable on the container. The rest of the snippet is plain CSS.

Can the slider be used with the keyboard?

Yes. It is a normal range input, so the arrow keys move it, and screen readers announce it by its label. The label says to drag to compare before and after, and you can change the wording in the code if you prefer.

Does it need a script?

Only a one-line oninput attribute. Sites with a strict Content-Security-Policy need to move that line into their own script file.

Should both images be the same size?

Yes. Use the same proportions so features line up when the slider moves.

Is anything sent over the internet?

The snippet is built locally and files you choose from your device are never uploaded. If you type an https image address, your browser loads that image from its own site to draw the preview; nothing else is sent.

Keep working with the result

openWorkstand also includes a free workspace with documents, spreadsheets, tasks, projects and a calendar that save to a folder on your computer.