Getting Started
Components
Special Effects
Animations
Text Animations
Backgrounds
A button with a shimmering light which travels around the perimeter.
shimmer-button.svelte
<script lang="ts"> import { ShimmerButton } from "$lib/components/magic/shimmer-button/index.js";</script>
<ShimmerButton class="shadow-2xl"> <span class="text-center text-sm leading-none font-medium tracking-tight whitespace-pre-wrap text-white lg:text-lg dark:from-white dark:to-slate-900/10" > Shimmer Button </span></ShimmerButton>Installation
pnpm dlx shadcn-svelte@latest add https://sv-animations.vercel.app/r/shimmer-button.json
Copy the Source Code
Copy and paste the following code into your project:
shimmer-button.svelte
<script lang="ts"> import { cn } from "#lib/utils.js"; import type { Snippet } from "svelte"; import type { ClassValue, HTMLButtonAttributes } from "svelte/elements";
interface ShimmerButtonProps extends HTMLButtonAttributes { children: Snippet; class?: ClassValue; shimmerColor?: string; shimmerSize?: string; borderRadius?: string; shimmerDuration?: string; background?: string; }
let { children, class: className, shimmerColor = "#ffffff", shimmerSize = "0.05em", shimmerDuration = "3s", borderRadius = "100px", background = "rgba(0, 0, 0, 1)", ...props }: ShimmerButtonProps = $props();</script>
<button style=" --spread: 90deg; --shimmer-color: {shimmerColor}; --radius: {borderRadius}; --speed: {shimmerDuration}; --cut: {shimmerSize}; --bg: {background}; " class={cn( "group relative z-0 flex cursor-pointer items-center justify-center overflow-hidden [border-radius:var(--radius)] border border-white/10 px-6 py-3 whitespace-nowrap text-white [background:var(--bg)]", "transform-gpu transition-transform duration-300 ease-in-out active:translate-y-px", className )} {...props}> <!-- spark container --> <div class={cn("-z-30 blur-[2px]", "@container-[size] absolute inset-0 overflow-visible")}> <!-- spark --> <div class="animate-shimmer-slide absolute inset-0 aspect-[1] h-[100cqh] rounded-none [mask:none]" > <!-- spark before --> <div class="animate-spin-around absolute -inset-full w-auto [translate:0_0] rotate-0 [background:conic-gradient(from_calc(270deg-(var(--spread)*0.5)),transparent_0,var(--shimmer-color)_var(--spread),transparent_var(--spread))]" ></div> </div> </div> {@render children()}
<!-- Highlight --> <div class={cn( "absolute inset-0 size-full",
"rounded-2xl px-4 py-1.5 text-sm font-medium shadow-[inset_0_-8px_10px_#ffffff1f]",
// transition "transform-gpu transition-all duration-300 ease-in-out",
// on hover "group-hover:shadow-[inset_0_-6px_10px_#ffffff3f]",
// on click "group-active:shadow-[inset_0_-10px_10px_#ffffff3f]" )} ></div>
<!-- backdrop --> <div class={cn( "absolute inset-(--cut) -z-20 [border-radius:var(--radius)] [background:var(--bg)]" )} ></div></button> index.ts
export { default as ShimmerButton } from "./shimmer-button.svelte";Add Tailwind CSS
Add the following to your routes/layout.css file:
src/routes/layout.css
@theme inline { --animate-shimmer-slide: shimmer-slide var(--speed) ease-in-out infinite alternate; --animate-spin-around: spin-around calc(var(--speed) * 2) infinite linear;
@keyframes shimmer-slide { to { transform: translate(calc(100cqw - 100%), 0); } } @keyframes spin-around { 0% { transform: translateZ(0) rotate(0); } 15%, 35% { transform: translateZ(0) rotate(90deg); } 65%, 85% { transform: translateZ(0) rotate(270deg); } 100% { transform: translateZ(0) rotate(360deg); } }}Folder Structure
Folder Structure
src/└── lib/ └── components/ └── magic/ └── shimmer-button/ ├── shimmer-button.svelte └── index.tsInstall and integrate the Svelte component documented below.https://sv-animations.vercel.app/magic/docs/components/shimmer-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 { ShimmerButton } from "#lib/components/magic/shimmer-button/index.js";</script>
<ShimmerButton>Get started</ShimmerButton>Props
Shimmer Button
A component for Shimmer Button.
| Name | Type | Default | Description |
|---|---|---|---|
class | ClassValue | "" | Additional CSS classes to apply |
shimmerColor | string | "#ffffff" | Color of the shimmer effect |
shimmerSize | string | "0.05em" | Size of the shimmer effect |
shimmerDuration | string | "3s" | Duration of the shimmer animation |
borderRadius | string | "100px" | Border radius of the button |
background | string | "rgba(0, 0, 0, 1)" | Background color of the button |