Two images that keep the same crop
CaveatBoth images must keep their full box while the upper one is clipped. Changing its width would resize its contents and make the facade drift away from the base image. Grid stacks the pair in the same cell; clip-path: inset() reveals a percentage without changing layout. The radio group gives three keyboard-operable stops rather than pretending to be a continuous slider. Switch from 25% to 75% and watch the door edges stay aligned. The two original SVG illustrations are included in the demo; replace both image URLs with your own registered pair.
FallbackWithout :has(), this remains a static 50/50 comparison. Without clip-path, the upper image covers the lower one, so provide separate originals if both versions must always be inspectable. Use matching aspect ratios and matching object-position for real photographs; CSS cannot register two shots taken from different viewpoints. For a continuous drag handle, add a native range input and a small script instead of an inaccessible draggable div. Reference: MDN documentation.
<fieldset class="d-compare">
<legend>Restoration preview</legend>
<div class="d-compare-controls">
<label><input type="radio" name="wc-reveal"
value="25">25% restored</label>
<label><input type="radio" name="wc-reveal"
value="50" checked>50%</label>
<label><input type="radio" name="wc-reveal"
value="75">75%</label>
</div>
<div class="d-compare-frame">
<img src="/assets/restoration-before.svg"
width="600" height="360"
alt="Faded workshop before restoration">
<img src="/assets/restoration-after.svg"
width="600" height="360"
alt="Workshop with restored blue doors">
</div>
</fieldset>
.d-compare {
--cut: 50%; border: 0; padding: 0; margin: 0;
width: 100%; max-width: 26rem;
color: var(--paper, #e6eaf1);
}
.d-compare legend { margin-bottom: .75rem; }
.d-compare-controls {
display: flex; flex-wrap: wrap; gap: .8rem;
margin-bottom: .75rem; font-size: .75rem;
}
.d-compare input { accent-color: #6fa8dc; }
.d-compare:has([value="25"]:checked) {
--cut: 75%;
}
.d-compare:has([value="75"]:checked) {
--cut: 25%;
}
.d-compare-frame { display: grid; }
.d-compare img {
grid-area: 1 / 1; width: 100%; height: auto;
aspect-ratio: 5 / 3; object-fit: cover;
}
.d-compare img + img {
clip-path: inset(0 var(--cut) 0 0);
}
.d-compare-frame::after {
content: ""; grid-area: 1 / 1;
z-index: 1; pointer-events: none;
width: 2px; background: white;
margin-left: calc(100% - var(--cut));
}
.d-compare label:has(:focus-visible) {
outline: 2px solid currentColor;
outline-offset: 3px;
}