Text Effects
MaskFlow
Outlined letters with a band of solid fill flowing through them, filling and emptying as it passes.
Download
- React
- Tailwind CSS v4
- motion
components/ui/mask-flow.tsx
"use client";
import type { ReactNode } from "react";
import { motion, useReducedMotion } from "motion/react";
type MaskFlowProps = {
children: ReactNode;
className?: string;
/** Seconds for the band to cross once. */
duration?: number;
/** Outline width, in pixels. */
stroke?: number;
};
// A soft solid band in the middle of a mask three times the text width.
const MASK = "linear-gradient(90deg, transparent 30%, #000 42%, #000 58%, transparent 70%)";
/* MaskFlow: outlined letters with a band of solid fill flowing through them, filling and emptying as it passes. */
export function MaskFlow({ children, className = "", duration = 3, stroke = 1 }: MaskFlowProps) {
const reduce = useReducedMotion();
return (
<span className={`inline-grid ${className}`}>
<span className="[grid-area:1/1]" style={{ WebkitTextFillColor: "transparent", WebkitTextStroke: `${stroke}px currentColor` }}>
{children}
</span>
{!reduce && (
<motion.span
aria-hidden
className="[grid-area:1/1]"
style={{ maskImage: MASK, WebkitMaskImage: MASK, maskSize: "300% 100%", WebkitMaskSize: "300% 100%", maskRepeat: "no-repeat", WebkitMaskRepeat: "no-repeat" }}
animate={{ maskPosition: ["100% 0%", "0% 0%"] }}
transition={{ duration, repeat: Infinity, ease: "easeInOut" }}
>
{children}
</motion.span>
)}
</span>
);
}
1. Install the dependency.
npm i motion2. Paste the Code tab into
components/ui/mask-flow.tsx. The styles are Tailwind CSS v4 classes.3. Use it. This is the preview above:
app/mask-flow-demo.tsx
import { MaskFlow } from "@/components/ui/mask-flow"; export default function MaskFlowExample() { return ( <div className="grid h-full place-items-center bg-[#0d0c14] p-6"> <MaskFlow stroke={1.5} className="text-center text-[clamp(40px,8vw,96px)] font-black uppercase tracking-tight text-[#f472b6]"> Flow state </MaskFlow> </div> ); }
Props
| Name | Type | Default | What it does |
|---|---|---|---|
| children | ReactNode | — | Text to show. |
| duration | number | 3 | Seconds for the band to cross once. |
| stroke | number | 1 | Outline width, in pixels. |
| className | string | "" | Font and colour (outline and fill use currentColor). |