Fade Through Color
A show/hide that goes through your brand color: the element melts into a flat tint of its own size, then the tint fades out; on the way back, the color comes first, the content next. 0.7 s to leave, 0.6 s to enter, and an element truly taken out of the keyboard path while hidden. CSS and 2.7 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 .ftc-frame frame (160 × 100 px) stacks two layers of the same size: .ftc-content, your content, and beneath it .ftc-color, a flat tint that is invisible at rest. The .ftc-btn button moves nothing: it takes the frame through four phase classes, and each phase only sets two opacities.
To leave, .ftc-out brings the color up in 0.2 s while the content fades out in 0.35 s: at 200 ms you see the color almost full (98%) and only 22% of the content is left. At 350 ms, .ftc-gone fades the color out in turn; at 700 ms everything is transparent. To enter, .ftc-color-in brings back the color alone for 250 ms, then .ftc-in crosses the two: content at 43% and color at 57% around 350 ms, full content at 600 ms. So the entrance is a little brisker than the exit, and both ways there is an instant where only the color shows.
The frame keeps its place while the content is hidden: the paragraph that follows does not move up by one pixel (read before and after). It is hiding in place, not a panel that folds; plan what shows in the gap, or put a placeholder text there as the examples do. During the animation the button turns aria-disabled and ignores clicks: two clicks 120 ms apart make a single exit.
Accessibility
- Button: a native
<button>carryingaria-expanded, updated at the end of each animation. Tab reaches it, Enter and Space trigger it in all three engines. During the animation it is markedaria-disabledrather thandisabled: keyboard focus stays on it. - Hidden content: it gets
aria-hidden="true"andinert. Checked with a link placed inside: hidden, Shift+Tab skips it; shown, it is back in the tab order. - Reading order: in the HTML, the content comes before the button. A keyboard user who has just revealed the content must therefore go back (Shift+Tab) to enter it. If the content holds links or fields, put the button before the frame in the HTML.
- Reduced motion: the color layer is removed, the content fades out or back in over 150 ms, done before 320 ms. State attributes change at once, the function is whole.
- Demo contrast: button label at 4.9:1, content text at 5.5:1 on the lightest end of the green gradient. The button is 35 px high: raise it to 44 px if it is a frequent touch control.
Browser compatibility
CSS (opacity transitions, inset) + 2.7 KB of JavaScript (classList, toggleAttribute, two timers each way). Exit, entrance, lock, keyboard, link made unreachable, emulated touch, hidden start and reduced motion give the same readings in Chromium 149, Firefox 151 and WebKit 26.5. The fade works from Chrome 87, Firefox 66 and Safari 14.1 (inset). The inert attribute, though, is only understood from Chrome 102, Firefox 112 and Safari 15.5: before that, hidden content is no longer read but its links can still be reached with Tab.
Without JavaScript, the content stays shown and the button does nothing: nothing is lost. So do not write ftc-gone in the HTML of essential content, it would stay hidden without script.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="ftc-stage">
<div class="ftc-frame">
<div class="ftc-layer ftc-content">…</div>
<div class="ftc-layer ftc-color" aria-hidden="true"></div>
</div>
<button type="button" class="ftc-btn" aria-expanded="true">…</button>
</div>
One-time payment, no subscription — the code is yours forever
Customize
Options passed to the API or data-* attributes:
| Option / property | Default | Effect |
|---|---|---|
Passing color (CSS — background of .ftc-color) |
#6366f1 |
Your brand color. A bold hue shows in a single pass; a hue close to the content's background makes the effect almost invisible. |
Starting state (HTML — ftc-gone class on .ftc-frame) |
absent: content shown | With the class, the element starts hidden: the script reads it on load and sets inert, aria-hidden and aria-expanded="false" itself. The first click brings it in. |
Frame size (CSS — .ftc-frame { width; height }, rounding on .ftc-layer) |
160 × 100 px, 14 px rounding | Both layers fill the frame: a 100 × 44 px label or a 216 × 272 px panel is set there, without touching the script. |
Exit durations (CSS — .ftc-out and .ftc-gone rules; JS — both 350 values) |
color 0.2 s, content 0.35 s, then color 0.35 s | The script's timers must equal the longest transition of the phase, or the next phase cuts the previous one short. |
Entrance durations (CSS — .ftc-color-in and .ftc-in; JS — 250 then 350) |
color alone 0.25 s, then a 0.35 s cross | Lengthen the first beat so the color holds the screen longer before the content returns. |
Button label (HTML — text of .ftc-btn) |
"Toggle the fade" | Keep a label that stays true in both states ("Details", "Balance"): aria-expanded already says whether it is open or closed. |
FAQ
aria-expanded, inert). The first to move between two views, the second to show or hide a block.button.click() on the .ftc-btn: the script plays the animation and updates aria-expanded, aria-hidden and inert as for a real click. The button can be hidden with the hidden attribute if nothing is meant to be clicked, as in the draughts example. A call made during an animation is ignored: wait 0.7 s between two calls.