The Before & After Slider (BAS) allows you to compare content side-by-side, either horizontally or vertically. This solution is built entirely using Webflow elements in the Designer, so you can fully customize it to match your preferences. The slider works by applying attributes to specific elements, making it robust, modular, and customizable.
You can implement the slider in a few different ways:
To quickly add a Before and After Slider, simply clone the project or visit Flowbase to copy-paste our prebuilt component into your project. This component has the structure, attributes and script all set up for you. All you need to do is click publish and view the live site to see your BAS in action!
The Booster app offers a user-friendly interface for adding components, customizing attributes and simplifying script installation and updates.
We’ll walk you through creating a horizontal slider similar to the one in the live preview. You’ll add the elements and attributes yourself, and the script will handle the functionality for you.
Copy and paste the script into your Project Settings, Page Settings, or an Embed Element on your page
<!-- Flowbase Booster [Before & After Slider] -->
<script src="https://cdn.jsdelivr.net/npm/@flowbase-co/boosters-before-after-slider@1/dist/before-after-slider.min.js"></script>
This will be the main container for all the slider elements, including images, the drag handle, and labels. To add this, drag a div-block to your page and add the attributes and styles as described below.
position: relative
width: 100%
max-width: 600px
(adjust as needed)height: 400px
(adjust as needed)fb-before-after: true
fb-before-after-direction: horizontal
fb-before-after-start: 50
Inside the Slider Wrapper, add the images for comparison. For best results, ensure both images are exported at the same size. The Before & After image will need their own classes, as each of these elements have slightly different styles. If you're unsure of anything, make sure to check out our demos and examples linked above.
display: block
width: 100%
height: 100%
fit: cover
display: block
margin-left: auto
width: 50%
height 100%
fit: cover
position: absolute
fb-before-after-side = after
To add a draggable handle, click on the BAS Wrapper, and add another nested div-block. Add the required styles below, and be sure to add a transform move property with a -50% value for the X & Y fields.
width: 50px
height: 50px
position: absolute
z-index: 2
left: 50%
top: 50%
transform: translate(-50%, -50%)
fb-before-after-handle = true
Add a line that divides your two images.
width: 2px
background-color: white
position: absolute
z-index: 1
left: 50%
top: 0px
bottom: 0px
transform: translate(-50%, 0)
Add labels to indicate the “Before” and “After” sides of the slider. Clicking on these will reveal the full image.
background-color: white
position: absolute
left: 24px
top: 24px
fb-before-after-label = before
background-color: white
position: absolute
right: 24px
top: 24px
fb-before-after-label = after
Publish your site to test the slider. You should now be able to drag the After Image to reveal the Before Image.