Skip to content

Compare Examples

The examples below assume that you have imported the component and set up the theme.

Basic

Compare two versions of the same picture by dragging a divider across them. The before and after slots take the two contents, and the divider clips both of them.

--active
Layout
Range
0
100
Pointer
A hovering mouse or pen moves the divider without a press.
Content
Captions in the before-label and after-label slots. The divider hides each one with its content.
An SVG in the handle slot.
State
<div class="compare-basic">
<sv-compare aria-label="Outline and color">
<!-- Outline -->
<svg
class="outline"
aria-label="An outline of the mountains and the sun"
role="img"
slot="before"
viewBox="0 0 640 400"
>
<circle cx="460" cy="200" r="46" />
<path d="M0 260 130 120l90 90 110-130 140 150 80-60 90 80" />
<path d="M0 280 100 210l110 60 120-90 130 110 80-50 100 60" />
</svg>
<!-- Color -->
<svg
class="color"
aria-label="The mountains and the sun in color"
role="img"
slot="after"
viewBox="0 0 640 400"
>
<circle cx="460" cy="200" fill="#ffe7a3" r="46" />
<path d="M0 260 130 120l90 90 110-130 140 150 80-60 90 80v150H0Z" fill="#8a76d6" />
<path d="M0 280 100 210l110 60 120-90 130 110 80-50 100 60v120H0Z" fill="#4f9a6b" />
</svg>
</sv-compare>
</div>
<style>
.compare-basic {
display: grid;
place-items: center;
sv-compare {
inline-size: min(100%, 30rem);
background: linear-gradient(#14213d, #3b4a7a);
}
.outline {
fill: none;
stroke: #fff;
stroke-width: 4;
stroke-linejoin: round;
}
.color {
opacity: 0.7;
}
}
</style>