Skip to content

Swatch deck fanning out in React

An offer card topped with a deck of colour swatches that fans out on hover or keyboard focus.

Here is an excerpt of this component's code in React. The full code is free for members, ready to copy into your project.

This component also comes in

Open in a new tab

The code in React

SwatchFan.tsx
export function SwatchFan() {
  return (
    <article
      className="group/efev grid max-w-[28rem] justify-items-center gap-3 rounded-[1.25rem] border border-[#e7e5e4] bg-white p-[clamp(1.5rem,5vw,2.5rem)] text-center text-[#1c1917] dark:border-[#44403c] dark:bg-[#1c1917] dark:text-[#fafaf9]"
      aria-labelledby="efev-titre"
    >
      <span className="pointer-events-none relative mb-3 h-38 w-full" aria-hidden="true">
        <span className="absolute bottom-0 left-1/2 -ml-[2.75rem] h-34 w-[5.5rem] origin-bottom rounded-[0.9rem] border border-[#e7e5e4] shadow-[0_0.5rem_1rem_-0.5rem_rgb(28_25_23/0.22)] transition-[rotate] duration-500 ease-[cubic-bezier(0.2,0.8,0.2,1)] motion-reduce:transition-none dark:border-[#44403c] dark:shadow-[0_0.5rem_1rem_-0.5rem_rgb(0_0_0/0.55)] bg-[linear-gradient(to_bottom,#b45309_0_72%,#ffffff_72%)] dark:bg-[linear-gradient(to_bottom,#b45309_0_72%,#292524_72%)] rotate-[-6deg] group-focus-within/efev:rotate-[-32deg] group-hover/efev:rotate-[-32deg] motion-reduce:rotate-[-32deg]"></span>
        <span className="absolute bottom-0 left-1/2 -ml-[2.75rem] h-34 w-[5.5rem] origin-bottom rounded-[0.9rem] border border-[#e7e5e4] shadow-[0_0.5rem_1rem_-0.5rem_rgb(28_25_23/0.22)] transition-[rotate] duration-500 ease-[cubic-bezier(0.2,0.8,0.2,1)] motion-reduce:transition-none dark:border-[#44403c] dark:shadow-[0_0.5rem_1rem_-0.5rem_rgb(0_0_0/0.55)] bg-[linear-gradient(to_bottom,#0f766e_0_72%,#ffffff_72%)] dark:bg-[linear-gradient(to_bottom,#0f766e_0_72%,#292524_72%)] rotate-[-3deg] group-focus-within/efev:rotate-[-16deg] group-hover/efev:rotate-[-16deg] motion-reduce:rotate-[-16deg]"></span>
        <span className="absolute bottom-0 left-1/2 -ml-[2.75rem] h-34 w-[5.5rem] origin-bottom rounded-[0.9rem] border border-[#e7e5e4] shadow-[0_0.5rem_1rem_-0.5rem_rgb(28_25_23/0.22)] transition-[rotate] duration-500 ease-[cubic-bezier(0.2,0.8,0.2,1)] motion-reduce:transition-none dark:border-[#44403c] dark:shadow-[0_0.5rem_1rem_-0.5rem_rgb(0_0_0/0.55)] bg-[linear-gradient(to_bottom,#be123c_0_72%,#ffffff_72%)] dark:bg-[linear-gradient(to_bottom,#be123c_0_72%,#292524_72%)] rotate-[0deg] group-focus-within/efev:rotate-[0deg] group-hover/efev:rotate-[0deg] motion-reduce:rotate-[0deg]"></span>
        <span className="absolute bottom-0 left-1/2 -ml-[2.75rem] h-34 w-[5.5rem] origin-bottom rounded-[0.9rem] border border-[#e7e5e4] shadow-[0_0.5rem_1rem_-0.5rem_rgb(28_25_23/0.22)] transition-[rotate] duration-500 ease-[cubic-bezier(0.2,0.8,0.2,1)] motion-reduce:transition-none dark:border-[#44403c] dark:shadow-[0_0.5rem_1rem_-0.5rem_rgb(0_0_0/0.55)] bg-[linear-gradient(to_bottom,#1d4ed8_0_72%,#ffffff_72%)] dark:bg-[linear-gradient(to_bottom,#1d4ed8_0_72%,#292524_72%)] rotate-[3deg] group-focus-within/efev:rotate-[16deg] group-hover/efev:rotate-[16deg] motion-reduce:rotate-[16deg]"></span>
        <span className="absolute bottom-0 left-1/2 -ml-[2.75rem] h-34 w-[5.5rem] origin-bottom rounded-[0.9rem] border border-[#e7e5e4] shadow-[0_0.5rem_1rem_-0.5rem_rgb(28_25_23/0.22)] transition-[rotate] duration-500 ease-[cubic-bezier(0.2,0.8,0.2,1)] motion-reduce:transition-none dark:border-[#44403c] dark:shadow-[0_0.5rem_1rem_-0.5rem_rgb(0_0_0/0.55)] bg-[linear-gradient(to_bottom,#4d7c0f_0_72%,#ffffff_72%)] dark:bg-[linear-gradient(to_bottom,#4d7c0f_0_72%,#292524_72%)] rotate-[6deg] group-focus-within/efev:rotate-[32deg] group-hover/efev:rotate-[32deg] motion-reduce:rotate-[32deg]"></span>

Free component: copy it freely, including for commercial projects.

Visual effects components in React
  • Cards that fade in as they enter the screen, one after another in each row, without a line of JavaScript and with a static fallback.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A translucent card with a saturated blur whose sharper edge refracts the colourful shapes drifting behind it, with an opaque fallback when transparency is reduced.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A help block shaped like a conversation: bubbles, three animated typing dots and clickable quick replies that show your answers to frequent questions, frozen under prefers-reduced-motion.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A paragraph whose words turn from grey to full ink, one by one, as the page scrolls, in pure CSS with a plain-text fallback.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Four offset, translucent sine waves gently roll along the bottom of a section, each at its own pace.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component