Smooth Fade
Two stacked skins of the same card hand over in a 0.7 s crossfade, while one's icon spins and shrinks and the other's comes to take its place: the moon seems to become a sun. The whole card is the button. CSS + 0.9 KB of JavaScript.
Updated
This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Transitions has 52 effects, including 9 free. Explore the category →
3 usage examples



How it works
The .sfd-scene (300 × 220 px) holds two .sfd-layer elements laid exactly on top of each other: .sfd-dark, visible at the start, and .sfd-light, at opacity 0. Each has its background, its text colors, its heading, its sentence and its icon. A click on the scene adds the .sfd-on class: the first layer goes from 1 to 0 opacity, the second from 0 to 1, over the same duration and the same curve (cubic-bezier(.4, 0, .2, 1)). The next click goes the other way.
What sets the effect apart from a plain fade is the icon. Both .sfd-icon elements sit in the same spot. The one in the leaving layer turns 120° while shrinking to 40% of its size; the one in the arriving layer starts at −120° and 40% and comes back upright and full size. Since one fades out while the other fades in, the eye reads a single icon transforming as it pivots.
The curve is not symmetrical: the two layers cross at 245 ms, not at half the duration (opacities of 0.67 and 0.33 at 200 ms, 0.15 and 0.85 at 400 ms, same values in the three engines tested). At that instant both are half transparent, so a quarter of whatever lies behind the card shows through it; on a dark background that goes unnoticed, on a light one the card pales for a short moment. The FAQ gives the rule to add to avoid it. The script itself only toggles the class and keeps the ARIA attributes up to date, for every .sfd-scene on the page.
Accessibility
- Reduced motion: a fade is not a movement, so it is kept but brought down to 150 ms; the icon no longer turns or changes size. Read 60 ms after the click: layers at 0.41 and 0.59 opacity, toggle finished before 320 ms.
- Keyboard: the scene carries
role="button"andtabindex="0". Tab reaches it, including in WebKit with no special setting; Enter and Space toggle it, and pressing Space does not scroll the page (checked). 2 px yellow outline on keyboard focus. - Screen readers:
aria-pressedfollows the state and the masked layer getsaria-hidden="true". The button is therefore named by the visible layer's text. That text is read in full: keep a short heading and a brief sentence. - No interactive element inside the card: a button must not contain a link or a field. For about 0.3 s the two layers' texts overlap and cannot be read; put nothing there that must be read at that moment.
Browser compatibility
CSS (transition on opacity and transform, inset, flexbox with gap) + 0.9 KB of JavaScript. Nothing but 2D: crossing at 245 ms, state held, return, keyboard and reduced motion give the same readings in Chromium 149, Firefox 151 and WebKit 26.5. The minimum versions come from inset: Chrome 87, Firefox 66, Safari 14.1; flexbox gap, which spaces the icon, the heading and the sentence, is covered by the same versions.
Without JavaScript, the dark layer stays on screen, text and icon included. Without transition support, the change is immediate: the card goes from one skin to the other in one go, with no content lost.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="sfd-stage">
<div class="sfd-scene" role="button" tabindex="0" aria-pressed="false">
<div class="sfd-layer sfd-dark">
<div class="sfd-icon" aria-hidden="true"><svg viewBox="0 0 24 24">…</svg></div>
<h3>…</h3>
<p>…</p>
</div>
<div class="sfd-layer sfd-light" aria-hidden="true">
<div class="sfd-icon" aria-hidden="true"><svg viewBox="0 0 24 24">…</svg></div>
<h3>…</h3>
<p>…</p>
</div>
</div>
</div>
One-time payment, no subscription — the code is yours forever
Customize
Options passed to the API or data-* attributes:
| Option / property | Default | Effect |
|---|---|---|
Duration (CSS — .7s in the .sfd-layer transition and in the .sfd-icon one) |
0.7 s for both | Keep the same value in both places, otherwise the icon finishes turning before or after the fade. 0.4 s for a small tile, 1.2 s for a mood change on a large screen. |
Icon rotation and shrink (CSS — rotate(120deg) scale(.4) and rotate(-120deg) scale(.4)) |
120° and 40% | 90° and 60% give a subtle switch; 180° and 0 make the icon vanish in a spin. Keep opposite signs between the two rules so the movement looks continuous. |
Layer skins (CSS — background on .sfd-dark and .sfd-light, colors of their h3 and p) |
indigo #1e1b4b and cream #fefce8 |
The class names constrain nothing: two status colors, two photos or two gradients will do, as long as each layer has an opaque background. |
Scene size (CSS — .sfd-scene { width; height; border-radius }) |
300 × 220 px, 16 px rounding, max-width: 100% |
Layers follow the scene (inset: 0). The sentence has a reserved height of two lines (min-height: 2.8em) so heading and icon do not move from one layer to the other: adapt it to your texts. |
Starting state (HTML — sfd-on class on .sfd-scene) |
absent: dark layer shown | To start on the light layer, also write aria-pressed="true", aria-hidden="true" on .sfd-dark and aria-hidden="false" on .sfd-light. |
FAQ
.sfd-scene.sfd-on .sfd-dark { opacity: 1 }. Checked on a white background: the card no longer pales, the light layer simply settles over the dark one..sfd-dark and .sfd-light are only names: the first is the layer shown at the start, the second the one that arrives. On and off, day and night, normal and alert work the same way, with the icons of your choice in .sfd-icon. However, the effect does not change your page's theme: it fades two contents inside a card, and it is up to you to hook a real theme change to the click.