TransitionsPremium

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.

CSSJSColorTransition

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

Balance hidden by default — a meal voucher card app — Fade Through Color example 1

① Balance hidden by default — a meal voucher card app

WhenCapucine opens Midivelle in the bakery queue. Her card balance is replaced by dots. She taps the eye: an amber tint passes where the amount sits, then "€184.60" appears. A few seconds later, the amount leaves by the same path.
WhyGoing through the color draws the eye to the one spot that changes, without moving anything on the card; and a hidden amount is no longer read by a screen reader, which a mere blur does not guarantee.
Settings100 × 44 px frame set on the card, content on a solid background in the card's color, .ftc-color in amber #f4b860. The button becomes a 36 px round eye (aria-label "Show balance"). The frame carries ftc-gone in the HTML to start hidden; the placeholder dots are a scene element slipped under the layers. In the capture, the real mouse click lands on the eye; the scene then hides the balance again, as a privacy timer would.
"Your move" appearing on your turn — a club's online draughts game — Fade Through Color example 2

② "Your move" appearing on your turn — a club's online draughts game

WhenEdwige is thinking, the banner is empty. She pushes a black piece: the banner lights up mustard yellow, then reads "Your move". You play in turn, the banner goes back through yellow and goes out.
WhyIn a slow game, you look elsewhere. The flat tint makes a clear signal at the side of the screen, easier to catch than text fading in, and it does not cover the board.
Settings218 × 64 px frame, light content on two lines, .ftc-color in #e0a526. The button is there but hidden (hidden): the game triggers it through button.click(). In the scene, the game is simulated: a black piece then a white piece advance as the capture mouse moves, and each move clicks the real button.
"Where do I find the serial number?" — warranty registration for a dishwasher — Fade Through Color example 3

③ "Where do I find the serial number?" — warranty registration for a dishwasher

WhenThe form asks for twelve characters nobody knows by heart. Under the field, a small "Where do I find it?" button: the help area, on the right, turns the brand's blue then shows the diagram of the open door, with the label circled. A click on the diagram closes it.
WhyThe help area is reserved in advance: the form does not jump when the diagram arrives, and the button tells screen readers whether the help is open or closed.
Settings216 × 272 px frame, white content with the diagram drawn in CSS and its caption, .ftc-color in blue #2563eb. Button reduced to a pill in 12 px type, placed under the field with position: absolute. Hidden start through ftc-gone. In the capture, the mouse's two real clicks land on the button then on the diagram; the scene passes that second click on to the button.

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> carrying aria-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 marked aria-disabled rather than disabled: keyboard focus stays on it.
  • Hidden content: it gets aria-hidden="true" and inert. 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.

Chrome 102+✓ Full (measured in Chromium 149)
Firefox 112+✓ Full (measured in Firefox 151)
Safari 15.5+✓ Full (measured in WebKit 26.5)
Edge 102+✓ Full (Chromium engine)
Mobile iOS 15.5+✓ Not checked on a device
Android Chrome 102+✓ Full (emulated touch)

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):

index.html — structure
<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 / propertyDefaultEffect
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

Fade Through changes page: a black veil covers the whole screen, page B replaces page A underneath, the veil lifts. Fade Through Color replaces nothing: it makes one element disappear, which stays hidden until the next click, then brings it back. The passage goes through a flat tint the size of the element, not through full-frame black, and the hidden state is announced (aria-expanded, inert). The first to move between two views, the second to show or hide a block.
Not as is. An accordion folds the content and lets what follows move up; here the frame keeps its dimensions, hidden or not. It is made for content with a set place: an amount, a label, a help area, a banner. To free the space, you would have to animate the frame's height yourself after the exit, which the code does not do.
Call 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.