Skip to content

UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.

2.0 KB
Raw Blame
---
title: Animated Gradient Text
date: 2024-04-09
description: An animated gradient background which transitions between colors for text.
author: dillionverma
published: true
video: https://cdn.magicui.design/animated-gradient-text.mp4
---

<ComponentPreview name="animated-gradient-text-demo" />

## Installation

<Tabs defaultValue="cli">

<TabsList>
  <TabsTrigger value="cli">CLI</TabsTrigger>
  <TabsTrigger value="manual">Manual</TabsTrigger>
</TabsList>
<TabsContent value="cli">

```bash
npx shadcn@latest add @magicui/animated-gradient-text
```

</TabsContent>

<TabsContent value="manual">

<Steps>

<Step>Copy and paste the following code into your project.</Step>

<ComponentSource name="animated-gradient-text" />

<Step>Update the import paths to match your project setup.</Step>

<Step>Add the required CSS animations</Step>

Add the following animations to your global CSS file.

```css title="app/globals.css" showLineNumbers {2, 4-8}
@theme inline {
  --animate-gradient: gradient 8s linear infinite;

  @keyframes gradient {
    to {
      background-position: var(--bg-size, 300%) 0;
    }
  }
}
```

</Steps>

</TabsContent>

</Tabs>

## Examples

### Custom Speed

<ComponentPreview name="animated-gradient-text-demo-2" />

### Usage

```tsx showLineNumbers
import { AnimatedGradientText } from "@/components/ui/animated-gradient-text"
```

```tsx showLineNumbers
<AnimatedGradientText>Animated Gradient Text</AnimatedGradientText>
```

## Props

| Prop        | Type     | Default     | Description                            |
| ----------- | -------- | ----------- | -------------------------------------- |
| `children`  | `node`   | `-`         | The children passed into the component |
| `className` | `string` | `-`         | The class name to be applied           |
| `speed`     | `number` | `1`         | The speed of the gradient animation    |
| `colorFrom` | `string` | `"#ffaa40"` | The starting color of the gradient     |
| `colorTo`   | `string` | `"#9c40ff"` | The ending color of the gradient       |