Weekend in Lisbon
Three days of tiles, tarts and trams.
A flat, unedited version of the photo on the left and the finished one on the right, split by a handle. Hover and the handle sweeps left, wiping the whole frame to the edited shot. No JavaScript.
Also known as: before after slider css, image comparison hover, photo edit reveal.
<figure class="hfx-image-before-after" role="img" aria-label="Photo before and after editing">
<div class="hfx-image-before-after-after"></div>
<span class="hfx-image-before-after-handle" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="m9 7-5 5 5 5M15 7l5 5-5 5"/></svg>
</span>
<span class="hfx-image-before-after-label">Before</span>
<span class="hfx-image-before-after-label">After</span>
</figure>.hfx-image-before-after {
--c: var(--hfx-color, #3b82f6);
font-size: var(--hfx-size, 16px);
position: relative;
width: 15em;
height: 9.5em;
margin: 0;
border-radius: 0.75em;
overflow: hidden;
font-family: system-ui, sans-serif;
}
.hfx-image-before-after::before,
.hfx-image-before-after-after {
content: "";
position: absolute;
inset: 0;
background:
radial-gradient(70% 40% at 16% 110%, color-mix(in srgb, var(--c) 18%, #0b0a1f) 99%, transparent),
radial-gradient(66% 38% at 88% 108%, color-mix(in srgb, var(--c) 24%, #0b0a1f) 99%, transparent),
conic-gradient(from 128deg at 68% 44%, transparent 0, color-mix(in srgb, var(--c) 32%, #1e1b4b) 0.4deg 103.6deg, transparent 104deg),
conic-gradient(from 119deg at 90% 52%, transparent 0, color-mix(in srgb, var(--c) 32%, #1e1b4b) 0.4deg 121.6deg, transparent 122deg),
conic-gradient(from 123deg at 24% 40%, transparent 0, color-mix(in srgb, var(--c) 42%, #6b2159) 0.4deg 113.6deg, transparent 114deg),
conic-gradient(from 125deg at 46% 54%, transparent 0, color-mix(in srgb, var(--c) 42%, #6b2159) 0.4deg 109.6deg, transparent 110deg),
radial-gradient(circle at 38% 58%, #fef3c7 0 1em, rgb(254 215 170 / 0.55) 1.1em, transparent 4.2em),
linear-gradient(color-mix(in srgb, var(--c) 58%, #1e1b4b), color-mix(in srgb, var(--c) 34%, #f472b6) 52%, color-mix(in srgb, var(--c) 12%, #fdba74) 76%);
}
.hfx-image-before-after::before {
filter: saturate(0.15) contrast(0.8) brightness(1.1);
}
.hfx-image-before-after-after {
clip-path: inset(0 0 0 50%);
transition: clip-path 0.6s cubic-bezier(0.65, 0, 0.35, 1);
}
.hfx-image-before-after-handle {
position: absolute;
z-index: 1;
top: 0;
bottom: 0;
left: 50%;
width: 0.14em;
margin-left: -0.07em;
background: #fff;
transition: transform 0.6s cubic-bezier(0.65, 0, 0.35, 1), opacity 0.3s ease 0.3s;
}
.hfx-image-before-after-handle svg {
position: absolute;
top: 50%;
left: 50%;
width: 1.9em;
height: 1.9em;
padding: 0.35em;
box-sizing: border-box;
border-radius: 50%;
background: #fff;
color: var(--c);
box-shadow: 0 0.2em 0.6em rgb(2 6 23 / 0.35);
transform: translate(-50%, -50%);
}
.hfx-image-before-after-label {
position: absolute;
z-index: 1;
top: 0.6em;
left: 0.6em;
padding: 0.25em 0.55em;
border-radius: 99em;
background: rgb(2 6 23 / 0.5);
color: #fff;
font-size: 0.65em;
font-weight: 600;
letter-spacing: 0.06em;
transition: opacity 0.3s ease;
}
.hfx-image-before-after-label:last-child {
left: auto;
right: 0.6em;
}
.hfx-image-before-after:hover .hfx-image-before-after-after {
clip-path: inset(0 0 0 0);
}
.hfx-image-before-after:hover .hfx-image-before-after-handle {
transform: translateX(-7.5em);
opacity: 0;
}
.hfx-image-before-after:hover .hfx-image-before-after-label:not(:last-child) {
opacity: 0;
}
@media (prefers-reduced-motion: reduce) {
.hfx-image-before-after, .hfx-image-before-after *, .hfx-image-before-after::before, .hfx-image-before-after::after, .hfx-image-before-after *::before, .hfx-image-before-after *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--hfx-color on the element or a parent.
Currently previewing #3b82f6.--hfx-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 16px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.