Style Library
Line Shadow Text
AnimationanimationA text component with a moving line shadow.
Prompt
Paste into any AI assistant before describing what to build — or attach it to a project below.
# Animation pattern — Line Shadow Text
A text component with a moving line shadow.
Build it in React with `motion` (motion/react) and Tailwind CSS. Respect `prefers-reduced-motion` (render the final state without movement), keep it under ~400 ms for UI feedback, and animate only transform and opacity where possible.
Reference implementation (Magic UI, MIT):
```tsx
"use client"
import { type CSSProperties, type HTMLAttributes } from "react"
import {
motion,
type DOMMotionComponents,
type MotionProps,
} from "motion/react"
import { cn } from "@/lib/utils"
const motionElements = {
article: motion.article,
div: motion.div,
h1: motion.h1,
h2: motion.h2,
h3: motion.h3,
h4: motion.h4,
h5: motion.h5,
h6: motion.h6,
li: motion.li,
p: motion.p,
section: motion.section,
span: motion.span,
} as const
type MotionElementType = Extract<
keyof DOMMotionComponents,
keyof typeof motionElements
>
interface LineShadowTextProps
extends Omit<HTMLAttributes<HTMLElement>, keyof MotionProps>, MotionProps {
children: string
shadowColor?: string
as?: MotionElementType
}
export function LineShadowText({
children,
shadowColor = "black",
className,
as: Component = "span",
...props
}: LineShadowTextProps) {
const MotionComponent = motionElements[Component]
return (
<MotionComponent
style={{ "--shadow-color": shadowColor } as CSSProperties}
className={cn(
"relative z-0 inline-flex",
"after:absolute after:top-[0.04em] after:left-[0.04em] after:content-[attr(data-text)]",
"after:bg-[linear-gradient(45deg,transparent_45%,var(--shadow-color)_45%,var(--shadow-color)_55%,transparent_0)]",
"after:-z-10 after:bg-size-[0.06em_0.06em] after:bg-clip-text after:text-transparent",
"after:animate-line-shadow",
className
)}
data-text={children}
{...props}
>
{children}
</MotionComponent>
)
}
```Use it in an app
Create a free account to attach this style to a project: the hub adds it to the prompt your AI assistant gets, so it builds every page in this look.
From Magic UI (MIT, commit d7207e5).View source