eo-n/ui
UIComponentsSkeleton

Skeleton

Serves as a placeholder to indicate loading content.

Installation

CLI

npx shadcn@latest add "https://eo-n.vercel.app/r/skeleton"

Manual

Copy and paste the following code into your project.

import * as React from "react";
import { cva, type VariantProps } from "class-variance-authority";
 
import { cn } from "@/lib/utils";
 
const skeletonVariants = cva("bg-primary/10 rounded-md", {
  variants: {
    variant: {
      pulse: "animate-pulse",
      shimmer:
        "before:animate-skeleton-shimmer before:via-primary/10 dark:before:via-primary/5 relative overflow-hidden before:absolute before:inset-0 before:-translate-x-full before:bg-gradient-to-r before:from-transparent before:to-transparent",
      gradient:
        "bg-gradient-to-r from-primary/5 via-primary/10 to-primary/5 animate-skeleton-gradient bg-[length:400%_100%]",
    },
  },
  defaultVariants: {
    variant: "pulse",
  },
});
 
export type SkeletonVariants = VariantProps<typeof skeletonVariants>;
 
interface SkeletonProps extends React.ComponentProps<"div">, SkeletonVariants {}
 
export function Skeleton({ className, variant, ...props }: SkeletonProps) {
  return (
    <div
      data-slot="skeleton"
      className={cn(skeletonVariants({ className, variant }))}
      {...props}
    />
  );
}

Define the shimmer keyframes and CSS variables inside your globals.css file using the @theme inline block.

globals.css
@import "tailwindcss";
 
@theme inline {
/* other css vars */
  --animate-skeleton-shimmer: skeleton-shimmer 2s infinite ease-out;
  --animate-skeleton-gradient: skeleton-gradient 2s infinite ease-out;
 
  @keyframes skeleton-shimmer {
    0% {
      transform: translateX(-100%);
    }
    100% {
      transform: translateX(200%);
    }
  }
  @keyframes skeleton-gradient {
    0%,
    100% {
      background-position: 0% 50%;
    }
    50% {
      background-position: 100% 50%;
    }
  }
}
Update the import paths to match your project setup.

Usage

Import all parts and piece them together.

import { Skeleton } from "@/components/ui/skeleton";
<Skeleton />

Examples

Pulse

Shimmer

Gradient

API Reference

Root

The main container component for handling skeleton props.

PropTypeDefault
variant
"pulse" | "shimmer" | "gradient"
"pulse"

On this page