---
title: "Loader"
description: "Loading indicator with 13 variants, from spinner and dot matrix to ASCII. One size prop, currentColor, reduced motion."
updatedAt: "2026-12-01"
license: "MIT"
url: "https://schindlertom.com/ui/loader"
---

# Loader

> Loading indicator with 13 variants, from spinner and dot matrix to ASCII. One size prop, currentColor, reduced motion.

A single React component for loading states: spinner, dots, bars, dot matrix, comet, morph, orbit, pulse, scramble, percent and three ASCII spinners like the ones in terminal and AI interfaces. Everything scales from one size prop and inherits the text color. With reduced motion, every variant becomes a calm pulse.

## Install

```bash
npx shadcn@latest add https://schindlertom.com/r/loader.json
```

Or manually:

```bash
npm install motion
```

Then copy the source below into `components/ui/loader.tsx`.

## Usage

```tsx
import { Loader } from "@/components/ui/loader";

export function Example() {
return (
  <div className="flex items-center gap-6 text-neutral-400">
    <Loader />
    <Loader variant="dot-matrix" size={28} />
    <Loader variant="ascii-braille" label="Thinking" />
  </div>
);
}
```

## API Reference

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `variant` | `"spinner" \| "dots" \| "bars" \| "dot-matrix" \| "comet" \| "morph" \| "orbit" \| "pulse" \| "scramble" \| "percent" \| "ascii" \| "ascii-braille" \| "ascii-blocks"` | `"spinner"` | Which animation to render. |
| `size` | `number` | `32` | Base size in px, everything scales from it. |
| `speed` | `number` | `1` | Seconds per animation cycle. |
| `label` | `string` | `"Loading"` | Screen reader label, also used by scramble. |
| `className` | `string` |  | Extra classes, for example for the color. |

## Features

- 13 variants in one component
- Scales from one size prop, draws in currentColor
- Accessible: role=status and a screen reader label
- Respects reduced motion

## FAQ

**How do I change the color?**

Set a text color on the loader or a parent, for example with a Tailwind class like text-emerald-400. Every variant draws in currentColor.

**Which dependencies do I need?**

Only React, Tailwind CSS and motion. The ASCII variants are plain text frames without fonts or images.

**Can I use it commercially?**

Yes, the component is released under the MIT license.

## License

```
MIT License

Copyright (c) 2026 Tom Schindler (https://schindlertom.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```

## Source

```tsx
/**
 * Loader by Tom Schindler
 * https://schindlertom.com/ui/loader
 *
 * MIT License, Copyright (c) 2026 Tom Schindler
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software,
 * to deal in it without restriction, provided this notice is kept in all copies.
 * Full license text: https://opensource.org/licenses/MIT
 */
"use client";

import { useEffect, useState } from "react";
import { motion, useReducedMotion } from "motion/react";

export type LoaderVariant =
  | "spinner"
  | "dots"
  | "bars"
  | "dot-matrix"
  | "comet"
  | "morph"
  | "orbit"
  | "pulse"
  | "scramble"
  | "percent"
  | "ascii"
  | "ascii-braille"
  | "ascii-blocks";

export type LoaderProps = {
  variant?: LoaderVariant;
  size?: number;
  speed?: number;
  label?: string;
  className?: string;
};

const ASCII_FRAMES: Record<"ascii" | "ascii-braille" | "ascii-blocks", string[]> = {
  ascii: ["|", "/", "-", "\\"],
  "ascii-braille": ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"],
  "ascii-blocks": ["▁", "▂", "▃", "▄", "▅", "▆", "▇", "█", "▇", "▆", "▅", "▄", "▃", "▂"],
};

const SCRAMBLE_CHARS = "!<>-_\\/[]{}=+*^?#";

function useTicker(active: boolean, interval: number) {
  const [tick, setTick] = useState(0);

  useEffect(() => {
    if (!active) return;
    const id = window.setInterval(() => setTick((value) => value + 1), interval);
    return () => window.clearInterval(id);
  }, [active, interval]);

  return tick;
}

function join(...classes: (string | undefined | false)[]) {
  return classes.filter(Boolean).join(" ");
}

const loop = (duration: number, delay = 0) => ({
  duration,
  delay,
  repeat: Infinity,
  ease: "easeInOut" as const,
});

export function Loader({ variant = "spinner", size = 32, speed = 1, label = "Loading", className }: LoaderProps) {
  const reduce = useReducedMotion() ?? false;
  const isText = variant === "scramble" || variant === "percent" || variant.startsWith("ascii");
  const frames = variant.startsWith("ascii") ? ASCII_FRAMES[variant as keyof typeof ASCII_FRAMES] : null;
  const tick = useTicker(isText && !reduce, variant === "percent" ? (speed * 1000) / 100 : (speed * 1000) / (frames?.length ?? 10));

  const root = join("inline-flex shrink-0 items-center justify-center text-current", className);
  const box = { width: size, height: size };

  if (reduce) {
    return (
      <motion.span
        role="status"
        aria-label={label}
        className={root}
        style={box}
        animate={{ opacity: [0.35, 1, 0.35] }}
        transition={loop(speed * 1.6)}
      >
        <span className="block rounded-full bg-current" style={{ width: size * 0.4, height: size * 0.4 }} />
      </motion.span>
    );
  }

  const dot = size / 5;

  const content = (() => {
    switch (variant) {
      case "spinner":
        return (
          <motion.svg
            viewBox="0 0 24 24"
            width={size}
            height={size}
            fill="none"
            animate={{ rotate: 360 }}
            transition={{ duration: speed, repeat: Infinity, ease: "linear" }}
          >
            <circle cx="12" cy="12" r="9.5" stroke="currentColor" strokeOpacity="0.2" strokeWidth="2.5" />
            <path d="M21.5 12a9.5 9.5 0 0 0-9.5-9.5" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" />
          </motion.svg>
        );
      case "dots":
        return (
          <span className="flex items-center" style={{ gap: dot * 0.6 }}>
            {[0, 1, 2].map((index) => (
              <motion.span
                key={index}
                className="block rounded-full bg-current"
                style={{ width: dot, height: dot }}
                animate={{ y: [0, -dot, 0], opacity: [0.4, 1, 0.4] }}
                transition={loop(speed * 0.9, index * speed * 0.15)}
              />
            ))}
          </span>
        );
      case "bars":
        return (
          <span className="flex items-center" style={{ gap: size / 12, height: size }}>
            {[0, 1, 2, 3].map((index) => (
              <motion.span
                key={index}
                className="block rounded-full bg-current"
                style={{ width: size / 8, height: size * 0.75, originY: 0.5 }}
                animate={{ scaleY: [0.35, 1, 0.35] }}
                transition={loop(speed, index * speed * 0.12)}
              />
            ))}
          </span>
        );
      case "dot-matrix":
        return (
          <span className="grid grid-cols-3" style={{ gap: size / 10 }}>
            {Array.from({ length: 9 }, (_, index) => {
              const wave = (index % 3) + Math.floor(index / 3);
              return (
                <motion.span
                  key={index}
                  className="block rounded-full bg-current"
                  style={{ width: size / 4.5, height: size / 4.5 }}
                  animate={{ opacity: [0.15, 1, 0.15], scale: [0.7, 1, 0.7] }}
                  transition={loop(speed, wave * speed * 0.12)}
                />
              );
            })}
          </span>
        );
      case "comet":
        return (
          <motion.span
            className="block rounded-full"
            style={{
              ...box,
              background: "conic-gradient(from 0deg, transparent 0deg, currentColor 300deg, transparent 360deg)",
              WebkitMask: `radial-gradient(farthest-side, transparent calc(100% - ${size / 8}px), #000 calc(100% - ${size / 8 - 1}px))`,
              mask: `radial-gradient(farthest-side, transparent calc(100% - ${size / 8}px), #000 calc(100% - ${size / 8 - 1}px))`,
            }}
            animate={{ rotate: 360 }}
            transition={{ duration: speed, repeat: Infinity, ease: "linear" }}
          />
        );
      case "morph":
        return (
          <motion.span
            className="block bg-current"
            style={{ width: size * 0.6, height: size * 0.6 }}
            animate={{ borderRadius: ["12%", "50%", "12%"], rotate: [0, 180, 360], scale: [1, 0.75, 1] }}
            transition={loop(speed * 1.6)}
          />
        );
      case "orbit":
        return (
          <motion.span
            className="relative block"
            style={box}
            animate={{ rotate: 360 }}
            transition={{ duration: speed * 1.2, repeat: Infinity, ease: "linear" }}
          >
            {[0, 1].map((index) => (
              <span
                key={index}
                className="absolute left-1/2 block rounded-full bg-current"
                style={{
                  width: dot,
                  height: dot,
                  marginLeft: -dot / 2,
                  top: index === 0 ? 0 : size - dot,
                  opacity: index === 0 ? 1 : 0.45,
                }}
              />
            ))}
          </motion.span>
        );
      case "pulse":
        return (
          <span className="relative block" style={box}>
            {[0, 1].map((index) => (
              <motion.span
                key={index}
                className="absolute inset-0 block rounded-full border-current"
                style={{ borderWidth: Math.max(1.5, size / 16) }}
                animate={{ scale: [0.2, 1], opacity: [1, 0] }}
                transition={{ duration: speed * 1.4, delay: index * speed * 0.7, repeat: Infinity, ease: "easeOut" }}
              />
            ))}
          </span>
        );
      case "scramble": {
        const word = label.toUpperCase();
        const text = word
          .split("")
          .map((char, index) => ((tick + index) % 4 === 0 ? SCRAMBLE_CHARS[(tick * 7 + index * 3) % SCRAMBLE_CHARS.length] : char))
          .join("");
        return (
          <span className="font-mono tabular-nums" style={{ fontSize: size * 0.4, letterSpacing: "0.08em" }}>
            {text}
          </span>
        );
      }
      case "percent":
        return (
          <span className="font-mono tabular-nums" style={{ fontSize: size * 0.45 }}>
            {String(tick % 101).padStart(3, " ")}%
          </span>
        );
      default: {
        const list = frames ?? ASCII_FRAMES.ascii;
        return (
          <span className="font-mono leading-none" style={{ fontSize: size * 0.75 }}>
            {list[tick % list.length]}
          </span>
        );
      }
    }
  })();

  return (
    <span role="status" aria-label={label} className={join(root, isText && "w-auto")} style={isText ? { height: size } : box}>
      {content}
    </span>
  );
}
```
