Getting Started
Components
Special Effects
Animations
Text Animations
Backgrounds
An animated gradient background which transitions between colors for text.
🎉
Introducing Magic UI
Introducing Magic UI
animated-text-badge.svelte
<script lang="ts"> import { AnimatedGradientText } from "$lib/components/magic/animated-gradient-text/index.js"; import { cn } from "$lib/utils.js"; import { ChevronRight } from "@lucide/svelte";</script>
<div> <div class="group relative mx-auto flex items-center justify-center rounded-full px-4 py-1.5 shadow-[inset_0_-8px_10px_#8fdfff1f] transition-shadow duration-500 ease-out hover:shadow-[inset_0_-5px_10px_#8fdfff3f]" > <span class={cn( "animate-gradient absolute inset-0 block h-full w-full rounded-[inherit] bg-gradient-to-r from-[#ffaa40]/50 via-[#9c40ff]/50 to-[#ffaa40]/50 bg-[length:300%_100%] p-[1px]" )} style=" -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0); -webkit-mask-composite: destination-out; mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0); mask-composite: subtract; -webkit-clip-path: padding-box;" ></span> 🎉 <hr class="mx-2 h-4 w-px shrink-0 bg-neutral-500" /> <AnimatedGradientText class="text-sm font-medium"> Introducing Magic UI </AnimatedGradientText> <ChevronRight class="ml-1 size-4 stroke-neutral-500 transition-transform duration-300 ease-in-out group-hover:translate-x-0.5" /> </div></div>Installation
pnpm dlx shadcn-svelte@latest add /r/animated-gradient-text.json
Copy the Source Code
Copy and paste the following code into your project:
AnimatedGradientText.svelte
<script lang="ts"> import type { ClassValue } from "svelte/elements"; import { cn } from "#lib/utils.js"; import type { Snippet } from "svelte";
type AnimatedGradientTextProps = { speed?: number; colorFrom?: string; colorTo?: string; children: Snippet; class?: ClassValue; rest?: Record<string, any>; };
let { speed = 1, colorFrom = "#ffaa40", colorTo = "#9c40ff", children, class: className = "", ...rest }: AnimatedGradientTextProps = $props();</script>
<span style="--color-from:{colorFrom}; --color-to:{colorTo}; --bg-size:{300 * speed}%" {...rest} class={cn( `animate-gradient inline bg-linear-to-r from-(--color-from) via-(--color-to) to-(--color-from) bg-size-[var(--bg-size)_100%] bg-clip-text text-transparent`, className )}> {@render children?.()}</span> Add Tailwind CSS
Add the following to your routes/layout.css file:
routes/layout.css
@theme inline { --animate-gradient: gradient 8s linear infinite;
@keyframes gradient { to { background-position: var(--bg-size, 300%) 0; } }}Folder Structure
Folder Structure
src/└── lib/ └── components/ └── magic/ └── animated-gradient-text/ ├── animated-gradient-text.svelte └── index.tsInstall and integrate the Svelte component documented below.https://sv-animations.vercel.app/magic/docs/components/animated-gradient-text/llms.txt
Follow the guide's installation and usage instructions.Match the project's existing structure, imports, and styles.Keep changes scoped to the component and verify it works.Reply with a short bullet list of completed changes.Usage
<script lang="ts"> import { AnimatedGradientText } from "#lib/components/magic/animated-gradient-text/index.js";</script>
<AnimatedGradientText>Animated gradient text</AnimatedGradientText>Examples
Custom Speed
Fast Gradient
custom-speed.svelte
<script lang="ts"> import { AnimatedGradientText } from "$lib/components/magic/animated-gradient-text/index.js";</script>
<AnimatedGradientText speed={2} colorFrom="#4ade80" colorTo="#06b6d4" class="text-4xl font-semibold tracking-tight"> Fast Gradient</AnimatedGradientText>Props
Animated Gradient Text
A text component with animated gradient background effect.
| Name | Type | Default | Description |
|---|---|---|---|
speed | number | 1 | Animation speed multiplier for the gradient movement |
colorFrom | string | #ffaa40 | Starting color of the gradient |
colorTo | string | #9c40ff | Ending color of the gradient |
class | ClassValue | "" | Additional CSS classes to apply |