Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages

Free tool · Image tools

Before after image slider

Choose two photos and the page builds a draggable comparison, then gives you the code to paste into your own site. The code is plain HTML and CSS with a three-line script, and your photos never leave your device.

  • Free
  • No sign-up
  • Runs in your browser

By Maaz Zindani · Updated

JPG, PNG or WebP. It stays on your device.

Any size. It is cropped from the middle to match the before photo.

Save the pictures as
Example result
Sample landscape, dull colors Sample landscape, bright colors Before After

Drag the picture, or focus it and use the arrow keys.

1,200 x 900 pxTwo pictures at one size, so the divider lines up. The page makes them from your photos.
  • No library, no account
  • JPG
  • Example: choose two photos to make yours
<div class="ba-slider" style="--pos:50%;aspect-ratio:1200/900;max-width:1200px">
  <img src="before.jpg" alt="Before" width="1200" height="900">
  <img class="ba-after" src="after.jpg" alt="After" width="1200" height="900">
  <span class="ba-tag ba-tag-before">Before</span>
  <span class="ba-tag ba-tag-after">After</span>
  <span class="ba-line"></span><span class="ba-knob"></span>
  <input class="ba-range" type="range" min="0" max="100" value="50" aria-label="Drag to compare the before and after pictures">
</div>
<style>
.ba-slider{position:relative;width:100%;overflow:hidden;line-height:0;user-select:none;touch-action:pan-y}
.ba-slider img{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;pointer-events:none}
.ba-after{clip-path:inset(0 0 0 var(--pos,50%))}
.ba-line{position:absolute;top:0;bottom:0;left:var(--pos,50%);width:3px;margin-left:-1.5px;background:#ffffff;box-shadow:0 0 6px rgba(0,0,0,.45);pointer-events:none}
.ba-knob{position:absolute;top:50%;left:var(--pos,50%);width:40px;height:40px;margin:-20px 0 0 -20px;border-radius:50%;background:#ffffff;box-shadow:0 0 8px rgba(0,0,0,.5);pointer-events:none}
.ba-knob::before,.ba-knob::after{content:"";position:absolute;top:50%;margin-top:-5px;border:5px solid transparent}
.ba-knob::before{left:7px;border-right-color:#222}
.ba-knob::after{right:7px;border-left-color:#222}
.ba-tag{position:absolute;top:10px;padding:4px 10px;border-radius:4px;background:rgba(0,0,0,.6);color:#fff;font:600 14px/1.3 system-ui,sans-serif;pointer-events:none}
.ba-tag-before{left:10px}.ba-tag-after{right:10px}
.ba-range{position:absolute;inset:0;width:100%;height:100%;margin:0;opacity:0;cursor:ew-resize;-webkit-appearance:none;appearance:none}
.ba-range::-webkit-slider-thumb{-webkit-appearance:none;width:2px;height:100vh}
.ba-range::-moz-range-thumb{width:2px;height:100vh;border:0}
.ba-slider:focus-within{outline:3px solid #2684ff;outline-offset:2px}
</style>
<script>document.querySelectorAll('.ba-slider').forEach(function(s){var r=s.querySelector('.ba-range');r.addEventListener('input',function(){s.style.setProperty('--pos',r.value+'%')})});</script>
Code
2,131 characters
Pictures
before.jpg, after.jpg
Picture sizes
shown for your photos
One-file page
shown for your photos

How to use the Before After Slider Maker

  1. Pick the Before photo and the After photo. The preview appears as soon as both are loaded.
  2. Set the Divider starts at position, the labels and the Divider color, and write short Alt text for each photo.
  3. Press Download before and Download after, upload both files to your site, and type their folder under Where you will upload the pictures.
  4. Press Copy the code and paste it into an HTML block on your page. For a single file you can test anywhere, press Download page (.html).

How do I make a before and after image slider for my website?

Load the two photos here, check the preview, and copy the code the page shows under it. The code is one block of HTML, a short style rule set and a script of three lines. It needs no library, no account and no monthly plan, and it does not call any outside server when a visitor opens your page.

The slider holds two pictures stacked in one box. The after picture is cut with a CSS clip so that only the part to the right of the divider shows. An invisible range input spans the whole box. When someone drags a finger or the mouse across the picture, the input changes its value, the script copies that value into one CSS variable, and the clip and the divider move to that spot.

Because the control is a real range input, the keyboard works without extra code. Focus the picture and press the left and right arrow keys. MDN lists the range input's default minimum as 0, its maximum as 100 and its step as 1, so each key press moves the divider by one percent. Screen readers announce the control as a slider, and the code gives it a plain label so the announcement says what it does.

How do I embed the slider on a page?

Upload the two pictures to your site first, then paste the code where the comparison should appear. The code points at before.jpg and after.jpg, so the page makes both files for you to download under those names. If you keep images in a folder, type it into the folder field and the addresses in the code change to match, for example /img/before.jpg and /img/after.jpg. A full web address works too.

Most site builders have a block for custom HTML. Paste the whole code into it, in one piece, and publish. Some builders strip script tags from custom blocks. If the divider shows but does not move, allow scripts in that block. The style rules are all prefixed with ba-, so they cannot change anything else on your page.

The box scales with its container. The code sets a maximum width equal to the picture width and an aspect ratio equal to the picture shape, so the slider shrinks on a phone and keeps its height in proportion. For a quick test before touching your site, press Download page (.html). That file holds the slider and both pictures in one document, and it opens in any browser by double click.

The clipping uses the CSS clip-path property with an inset() shape. MDN marks clip-path as widely available across browsers since January 2020, so current phones and desktop browsers draw it correctly.

Why must both photos have the same size?

A divider only looks right when the two pictures line up pixel for pixel, so the page saves both at one size. The size comes from the before photo: the width you choose (1,200 pixels unless you type another number, and never more than the photo has) and the height that keeps its shape. A before photo of 4,000 by 3,000 pixels at a width of 1,200 becomes 1,200 by 900.

The after photo is then fitted to the same box by cropping it from the middle. Say the after photo is a 3,000 by 3,000 pixel square. A 4:3 box needs a strip of 3,000 by 2,250 pixels, so 375 pixels go from the top and 375 from the bottom, 750 in all or about 25% of the height. Nothing is stretched. If the crop would remove something that matters, retake or crop the after photo to the shape of the first one before loading it.

How big is the code, and can it be one file?

The code is about 2,141 characters when it points at image files, which is small enough to paste anywhere. Pictures are the weight. Inside the code they grow by a third, because base64 writes 4 characters for every 3 bytes, so the copied code points at files and only the downloaded page carries the pictures.

The table shows what that costs for two pictures of the same weight. A pair of 150 KB JPG files becomes about 400,046 characters of data, and a page that size is fine as a test file but heavy to paste into a site editor. Uploading the two files and linking to them keeps the page light and lets the browser cache them.

Choose JPG for photographs. It gives much lighter files than PNG for the same picture. Choose PNG when the picture has sharp edges, text or flat colors, such as a screenshot of a settings page before and after a change. A smaller width is the first thing to try if the page loads slowly. Compress Image can shrink the two downloaded files further.

Pictures inside the code (base64) compared with linked files
Each pictureCharacters per pictureCharacters for bothWhole page
80 KB106,691213,382216 KB
150 KB200,023400,046402 KB
300 KB400,023800,046802 KB
600 KB800,0231,600,0461,602 KB

Does the slider work on a phone and with a keyboard?

Yes. The code sets touch-action: pan-y on the box, so a sideways drag moves the divider while an up and down swipe still scrolls the page. The divider handle is large enough to see and the invisible input covers the entire picture, so a thumb does not have to hit a small target.

Write real alt text for both photos. Alt text is read by screen readers and shown when a picture fails to load. A phrase such as "Kitchen counter with chipped laminate" for the before photo and "Same counter after new quartz was fitted" for the after photo tells a person who cannot see the picture what changed. The labels on the picture are plain text too, so you can change them to "2019" and "2024" or any pair of words.

Use it with

Questions

How do I make a before and after slider without a plugin?

Load both photos on this page, then copy the code. It is HTML, CSS and a three-line script, so nothing has to be installed on your site.

Do the two images have to be the same size?

They are saved at the same size so the divider lines up. The before photo sets the shape, and the after photo is cropped from its middle to match.

Can I use the slider in WordPress, Wix or Squarespace?

Use a custom HTML block and paste the code. Upload the two pictures to the media library first and type their folder or address in the folder field. Some builders remove script tags, which stops the divider from moving.

How do I move the divider with a keyboard?

Focus the picture and press the left and right arrow keys. The control is a standard range input that goes from 0 to 100 in steps of 1.

Why does my one-file page weigh so much?

Pictures inside the page are written as base64 text, which is about one third larger than the files. Two 150 KB pictures become about 402 KB of page. Link to uploaded files for a lighter page.

Are my photos uploaded anywhere?

No. The browser reads them, resizes them on a canvas and builds the files on your device. The page makes no network request with your pictures.

Sources

The tool's results are computed in your browser by the code on this page, using the sources listed above; the explanations are checked against the tool's own output.