---
title: Spinner for Astro
description: "Astro activity indicators for pending controls and page regions."
seo:
    title: Spinner for Astro | Shadcn & Tailwind CSS
related:
    - /components/button
    - /components/progress
    - /components/skeleton
sidebar:
    label: "Spinner"
---

```astro
---
import { Button } from "@/components/ui/button"
import { Spinner } from "@/components/ui/spinner"
---

<div class="flex flex-col items-center gap-6">
  <Spinner />
  <Button size="sm" variant="outline" disabled>
    <Spinner class="mr-2 size-4" />
    Loading...
  </Button>
</div>
```

## Installation

### Command

```sh
bunx --bun shadcn@latest add @gnostic/spinner
```

### Manual

Complete the [Installation guide](/docs/installation) first. Then copy the component files below.

No extra packages are required.

#### src/components/ui/spinner/index.ts

```ts
export { default as Spinner } from "./spinner.astro"
```

#### src/components/ui/spinner/spinner.astro

```astro
---
import type { HTMLAttributes } from "astro/types"
import LoaderCircle from "@lucide/astro/icons/loader-circle"

import { cn } from "cn"

type Props = HTMLAttributes<"svg"> & {
  color?: string
  size?: number | string
  "stroke-width"?: number | string
  absoluteStrokeWidth?: boolean
  title?: string
}

const { class: className, ...props } = Astro.props
---

<LoaderCircle
  data-slot="spinner"
  role="status"
  aria-label="Loading"
  class={cn("size-4 animate-spin", className)}
  {...props}
/>
```

Component classes use the preset configured during project setup. Select the same preset in the docs before copying Manual source. To change installed component classes, edit or reinstall their source. See [Theming](/docs/theming) for details.


## Usage

```ts
import { Spinner } from "@/components/ui/spinner"
```

```astro
<Spinner />
```

## Notes

- `Spinner` works well as a standalone loading indicator or inline inside a
  `Button`.
- When it is purely decorative next to visible loading text, the button text can
  carry the main status message.

## Example

```astro
<div class="flex items-center gap-2 text-sm">
  <Spinner />
  <span>Loading results...</span>
</div>
```

## API Reference

Read the [installed source](/r/spinner.json) for the complete prop types.

## When to use Spinner

Use Spinner beside a short loading message or inside a button with a pending action. Choose a size that fits the nearby text. Keep the action label understandable while work is in progress.

## Keyboard and behavior

The animation does not start a request or announce a result. Give the surrounding region a suitable status message, and avoid announcing a decorative spinner twice.

## Theme and layout

The icon follows text color, so check contrast inside primary and outline buttons. Provide a static text indication for reduced motion and for tasks that fail or take a long time.
