Slide Transition
Horizontal push: content A leaves to the left while B comes in from the right, both on a synchronized translateX over 0.6 s, with no layer between them; going back reverses the direction. CSS + 0.9 KB of JavaScript, click, Enter or Space, final state at once when the user reduces motion.
Updated
This effect is part of Effect.Labs — 840 vanilla effects, some free, some premium. Transitions has 52 effects, including 9 free. Explore the category →
3 usage examples



How it works
The .sld-frame (280 × 180 px, 16 px corners, 8% white border) clips whatever sticks out (overflow: hidden). It holds two .sld-panels of the same size, with position: absolute; inset: 0: A is in place (translateX(0)), B waits just to the right, outside the frame (translateX(100%)). Both carry transition: transform .6s cubic-bezier(.4, 0, .2, 1).
When .active toggles, A moves to translateX(-100%) while B comes to translateX(0). The two contents move themselves, side by side, at the same speed: no layer covers them, nothing hides A while it leaves. Measured in Chromium 151: 250 ms after the click, A is at −172 px and B at +106 px, a 278 px gap, the frame's inner width (Firefox 153: −164 and +114); at 1.1 s, A is at −278 px and B at 0, and the state still holds three seconds later. The second click runs the reverse path: B leaves to the right, A comes back from the left. Same result in WebKit 26.5.
The script adds or removes .active on click, Enter or Space on every .sld-frame of the page, keeps aria-pressed up to date and sets aria-hidden on the panel that left. Everything is prefixed sld-, with no global name: several frames coexist on the page, each with its own state. The direction is set by the CSS; for a multi-screen flow, the FAQ shows how to pick the direction depending on going forward or back.
Accessibility
- Reduced motion: under
prefers-reduced-motion: reduce, the transition is removed and the target panel is in place with no delay (read at 60 ms, Chromium and Firefox alike: B already at 0, A at −278 px). A full-width slide is a large motion; that is what gets removed. - Keyboard and screen readers: the frame has
role="button",tabindex="0"andaria-pressed; Enter and Space toggle like a click (measured). The panel outside the frame getsaria-hidden="true", so its text is not read. 2 px outline on keyboard focus. - In a real navigation, move focus to the heading of the incoming panel and announce the step ("Step 2 of 4"): the slide alone says nothing to someone who did not see the screen move.
- Reading direction: in Arabic or Hebrew (
dir="rtl"), swap the two values so "next" comes in from the left.
Browser compatibility
CSS (transform: translateX(), transition, inset) + 0.9 KB of JavaScript, no dependency. Measured in Chromium 151, Firefox 153 and WebKit 26.5: push in both directions, state B held, return on the second click; keyboard and reduced motion measured in Chromium and Firefox. Only transform is animated: the browser hands it to the compositor, with no layout recalculation. inset sets the floor (Chrome 87, Firefox 66, Safari 14.1).
Without JavaScript, panel A stays on screen. Without inset, write top: 0; right: 0; bottom: 0; left: 0 on .sld-panel.
The code
HTML structure to paste into your page (the CSS + JS come with Premium):
<div class="sld-stage">
<div class="sld-frame" role="button" tabindex="0" aria-pressed="false">
<div class="sld-panel sld-panel-a">…</div>
<div class="sld-panel sld-panel-b" aria-hidden="true">…</div>
</div>
<span class="sld-hint">…</span>
</div>
The full HTML + CSS + JS of Slide Transition, ready to paste — plus all 840 effects. Or $299 once, lifetime access.
Customize
Options passed to the API or data-* attributes:
| Option / property | Default | Effect |
|---|---|---|
Duration and curve (CSS — transition on .sld-panel) |
0.6 s, cubic-bezier(.4, 0, .2, 1) |
0.35 s for a snappy carousel; cubic-bezier(.2, .8, .2, 1) gives a fast start and a braked landing, close to a finger swipe. |
Axis (CSS — translateX) |
horizontal | Replace with translateY(100%) / translateY(-100%) for a vertical push, a message thread for instance. |
Gap between panels (CSS — the 100% values) |
the panels touch | translateX(calc(100% + 16px)) for B and calc(-100% - 16px) for A leave a strip of background visible during the change, like separate cards. |
Frame size (CSS — .sld-frame) |
280 × 180 px | width: 100%; height: 420px for a full screen: the translateX percentages follow the width, nothing else to change. |
Panel colors (CSS — .sld-panel-a, -b) |
sky-blue and green gradients | Use your screen's background; keep it opaque, otherwise the other panel shows through during the slide. |
FAQ
translateX(-100%) for past screens, 0 for the current one, 100% for screens to come. Going forward, the current screen moves left and the next comes from the right; going back, the opposite. The JavaScript only changes the position classes.overflow: hidden and hidden from screen readers by aria-hidden. If a panel contains form fields, also add inert to the panel that left so the Tab key does not stop there.transform, which the browser animates off the main thread: no layout recalculation on each frame. Avoid animating left or margin-left instead, which recalculate the page, and keep shadows light inside the panels.