Getting Started
Components
Special Effects
Animations
Text Animations
Backgrounds
An animated button with a rainbow effect.
bits-uitailwind-variants
rainbow-button.svelte
<script lang="ts"> import { RainbowButton } from "$lib/components/magic/rainbow-button/index.js";</script>
<RainbowButton>Join Affiliate Program</RainbowButton>Installation
pnpm dlx shadcn-svelte@latest add https://sv-animations.vercel.app/r/rainbow-button.json
Install dependencies
Install the required packages for this component:
pnpm add bits-ui tailwind-variants
Copy the Source Code
Copy and paste the following code into your project:
rainbow-button.svelte
<script lang="ts" module> export const buttonVariants = tv({ base: cn( "group animate-rainbow relative cursor-pointer transition-all", "inline-flex shrink-0 items-center justify-center gap-2", "aria-invalid:border-destructive rounded-sm outline-none focus-visible:ring-[3px]", "text-sm font-medium whitespace-nowrap", "disabled:pointer-events-none disabled:opacity-50", "[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4" ), variants: { variant: { default: "text-primary-foreground before:animate-rainbow border-0 bg-[linear-gradient(#121213,#121213),linear-gradient(#121213_50%,rgba(18,18,19,0.6)_80%,rgba(18,18,19,0)),linear-gradient(90deg,var(--color-1),var(--color-5),var(--color-3),var(--color-4),var(--color-2))] bg-[length:200%] [background-clip:padding-box,border-box,border-box] [background-origin:border-box] [border:calc(0.125rem)_solid_transparent] before:absolute before:bottom-[-20%] before:left-1/2 before:z-0 before:h-1/5 before:w-3/5 before:-translate-x-1/2 before:bg-[linear-gradient(90deg,var(--color-1),var(--color-5),var(--color-3),var(--color-4),var(--color-2))] before:[filter:blur(0.75rem)] dark:bg-[linear-gradient(#fff,#fff),linear-gradient(#fff_50%,rgba(255,255,255,0.6)_80%,rgba(0,0,0,0)),linear-gradient(90deg,var(--color-1),var(--color-5),var(--color-3),var(--color-4),var(--color-2))]", outline: "border-input text-accent-foreground before:animate-rainbow border border-b-transparent bg-[linear-gradient(#ffffff,#ffffff),linear-gradient(#ffffff_50%,rgba(18,18,19,0.6)_80%,rgba(18,18,19,0)),linear-gradient(90deg,var(--color-1),var(--color-5),var(--color-3),var(--color-4),var(--color-2))] bg-[length:200%] [background-clip:padding-box,border-box,border-box] [background-origin:border-box] before:absolute before:bottom-[-20%] before:left-1/2 before:z-0 before:h-1/5 before:w-3/5 before:-translate-x-1/2 before:bg-[linear-gradient(90deg,var(--color-1),var(--color-5),var(--color-3),var(--color-4),var(--color-2))] before:[filter:blur(0.75rem)] dark:bg-[linear-gradient(#0a0a0a,#0a0a0a),linear-gradient(#0a0a0a_50%,rgba(255,255,255,0.6)_80%,rgba(0,0,0,0)),linear-gradient(90deg,var(--color-1),var(--color-5),var(--color-3),var(--color-4),var(--color-2))]", }, size: { default: "h-9 px-4 py-2", sm: "h-8 rounded-xl px-3 text-xs", lg: "h-11 rounded-xl px-8", icon: "size-9", }, }, defaultVariants: { variant: "default", size: "default", }, }); export type ButtonVariant = VariantProps<typeof buttonVariants>["variant"]; export type ButtonSize = VariantProps<typeof buttonVariants>["size"];
export type ButtonProps = WithElementRef<HTMLButtonAttributes> & WithElementRef<HTMLAnchorAttributes> & { variant?: ButtonVariant; size?: ButtonSize; };</script>
<script lang="ts"> import { cn } from "#lib/utils.js"; import type { WithElementRef } from "bits-ui"; import type { HTMLAnchorAttributes, HTMLButtonAttributes } from "svelte/elements"; import { tv, type VariantProps } from "tailwind-variants";
let { children, class: className = "", variant = "default", size = "default", ...props }: ButtonProps = $props();</script>
<button class={cn(buttonVariants({ variant, size }), className)} {...props}> {@render children?.()}</button> index.ts
export { default as RainbowButton } from "./rainbow-button.svelte"; src/routes/layout.css
:root { --color-1: 0 100% 63%; --color-2: 270 100% 63%; --color-3: 210 100% 63%; --color-4: 195 100% 63%; --color-5: 90 100% 63%;}Add Tailwind CSS
Add the following to your routes/layout.css file:
src/routes/layout.css
@theme inline { --animate-rainbow: rainbow var(--speed, 2s) infinite linear;
@keyframes rainbow { 0% { background-position: 0%; } 100% { background-position: 200%; } }}Folder Structure
Folder Structure
src/└── lib/ └── components/ └── magic/ └── rainbow-button/ ├── rainbow-button.svelte └── index.tsInstall and integrate the Svelte component documented below.https://sv-animations.vercel.app/magic/docs/components/rainbow-button/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 { RainbowButton } from "#lib/components/magic/rainbow-button/index.js";</script>
<RainbowButton>Get started</RainbowButton>Examples
Outline Variant
rainbow-button-outline.svelte
<script> import { RainbowButton } from "$lib/components/magic/rainbow-button/index.js";</script>
<RainbowButton variant="outline">Get Unlimited Access</RainbowButton>