Spin
A Spin shows that something is loading: four turning dots, on their own, over content that is waiting, or over the whole page. It is not interactive and never takes focus.
When to use
- Use a Spin while a block or a page waits for data. Wrap the content in it when a card or a list is loading; use it alone for a small spot.
- For a load that is usually quick, set
delayso the indicator does not flash. If you know how far along it is, usepercent. - Use
fullscreenonly for a page loader, and say what is going on withdescription, because a screen reader hears nothing else.
Examples
spinning
A standalone Spin: only the indicator spinning is true
<script lang="ts">
import { Spin, Switch } from 'svelte-ant-design';
let spinning = $state(true);
</script>
<div class="stack">
<div class="field">
<span class="caption">spinning</span>
<Switch bind:checked={spinning} aria-label="Spinning" />
</div>
<div class="field">
<span class="caption">A standalone Spin: only the indicator</span>
<!-- A Spin with no children is just the indicator. Not spinning, it renders nothing; the slot below keeps the height. -->
<div class="slot">
<Spin {spinning} aria-label="Loading the data" />
</div>
<span>spinning is {spinning}</span>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 20px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.slot {
display: flex;
align-items: center;
min-height: 32px;
}
</style>
size="small" (14 px)
size="medium" (20 px, the default)
size="large" (32 px)
size="default" (an alias of medium)
<script lang="ts">
import { Spin } from 'svelte-ant-design';
</script>
<div class="stack">
<div class="field">
<span class="caption">size="small" (14 px)</span>
<Spin size="small" aria-label="Loading, small" />
</div>
<div class="field">
<span class="caption">size="medium" (20 px, the default)</span>
<Spin size="medium" aria-label="Loading, medium" />
</div>
<div class="field">
<span class="caption">size="large" (32 px)</span>
<Spin size="large" aria-label="Loading, large" />
</div>
<div class="field">
<span class="caption">size="default" (an alias of medium)</span>
<Spin size="default" aria-label="Loading, default" />
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
spinning
Spin with children: the content is dimmed and ignores the mouse The button was pressed 0 times
<script lang="ts">
import { Button, Spin, Switch } from 'svelte-ant-design';
let loading = $state(true);
let presses = $state(0);
</script>
<div class="stack">
<div class="field">
<span class="caption">spinning</span>
<Switch bind:checked={loading} aria-label="Spinning" />
</div>
<div class="field">
<span class="caption">Spin with children: the content is dimmed and ignores the mouse</span>
<!--
The content stays reachable with the keyboard: Tab to the button and press Enter while it is dimmed. Something
that must not run twice (a form being sent) has to guard itself.
-->
<Spin spinning={loading} description="Loading the report">
<div class="panel">
<p>The report has three rows.</p>
<Button onclick={() => (presses += 1)}>Press me</Button>
</div>
</Spin>
<span>The button was pressed {presses} times</span>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 20px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.panel {
box-sizing: border-box;
width: 280px;
height: 190px;
padding: 16px;
border: 1px solid var(--ads-color-border);
border-radius: 8px;
}
p {
margin: 0 0 12px;
}
</style>
description as a string, standalone
Loading
description as a snippet, standalone
Saving (this takes a moment)
description over embedded content
<script lang="ts">
import { Spin } from 'svelte-ant-design';
</script>
<!-- The text of the description is what a screen reader announces, so a Spin with one needs no aria-label. -->
{#snippet detail()}
<strong>Saving</strong> <small>(this takes a moment)</small>
{/snippet}
<div class="stack">
<div class="field">
<span class="caption">description as a string, standalone</span>
<Spin description="Loading" />
</div>
<div class="field">
<span class="caption">description as a snippet, standalone</span>
<Spin description={detail} />
</div>
<div class="field">
<span class="caption">description over embedded content</span>
<Spin description="Loading the table">
<div class="panel">Rows that are being loaded.</div>
</Spin>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 20px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.panel {
box-sizing: border-box;
width: 280px;
height: 120px;
padding: 16px;
border: 1px solid var(--ads-color-border);
border-radius: 8px;
}
</style>
delay={500}: the indicator waits half a second
A load shorter than the delay never shows the indicator Nothing has been loaded yet
<script lang="ts">
import { Button, Spin } from 'svelte-ant-design';
let loading = $state(false);
let last = $state('Nothing has been loaded yet');
function load(ms: number) {
loading = true;
last = `Loading, it will take ${ms} ms`;
setTimeout(() => {
loading = false;
last = `Loaded in ${ms} ms`;
}, ms);
}
</script>
<div class="stack">
<div class="field">
<span class="caption">delay={500}: the indicator waits half a second</span>
<div class="row">
<Button disabled={loading} onclick={() => load(200)}>Load fast (200 ms)</Button>
<Button disabled={loading} onclick={() => load(2000)}>Load slow (2 s)</Button>
</div>
</div>
<div class="field">
<span class="caption">A load shorter than the delay never shows the indicator</span>
<Spin spinning={loading} delay={500} description="Loading">
<div class="panel">The content of the panel.</div>
</Spin>
<span role="status">{last}</span>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 20px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.panel {
box-sizing: border-box;
width: 280px;
height: 120px;
padding: 16px;
border: 1px solid var(--ads-color-border);
border-radius: 8px;
}
</style>
indicator: an icon the example turns
Loading
indicator: a large icon
indicator: text
<script lang="ts">
import { Spin } from 'svelte-ant-design';
</script>
<!--
An indicator is drawn in a box of the dot size, and its font size is the dot size, so an icon in `em` scales with
`size`. The Spin does not turn it: this example animates its own icon and keeps still when asked to reduce motion.
-->
{#snippet arc()}
<svg class="arc" viewBox="0 0 24 24" width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="3">
<path d="M12 3a9 9 0 1 0 9 9" stroke-linecap="round" />
</svg>
{/snippet}
{#snippet dots()}
<span class="ellipsis">…</span>
{/snippet}
<div class="stack">
<div class="field">
<span class="caption">indicator: an icon the example turns</span>
<Spin indicator={arc} description="Loading" />
</div>
<div class="field">
<span class="caption">indicator: a large icon</span>
<Spin indicator={arc} size="large" aria-label="Loading, large icon" />
</div>
<div class="field">
<span class="caption">indicator: text</span>
<Spin indicator={dots} aria-label="Loading, text indicator" />
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 20px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.arc {
animation: turn 1s linear infinite;
}
.ellipsis {
font-weight: 700;
}
@keyframes turn {
to {
transform: rotate(360deg);
}
}
@media (prefers-reduced-motion: reduce) {
.arc {
animation-duration: 3s;
}
}
</style>
percent: a number from 0 to 100
Uploading
percent="auto": an indeterminate ring, no value
Preparing
percent with size="large"
<script lang="ts">
import { Spin } from 'svelte-ant-design';
let percent = $state(35);
</script>
<div class="stack">
<div class="field">
<span class="caption">percent: a number from 0 to 100</span>
<label class="row">
<input type="range" min="0" max="100" bind:value={percent} />
<span>{percent}%</span>
</label>
<!-- The ring is a progressbar; the description is its name. -->
<Spin {percent} description="Uploading" />
</div>
<div class="field">
<span class="caption">percent="auto": an indeterminate ring, no value</span>
<Spin percent="auto" description="Preparing" />
</div>
<div class="field">
<span class="caption">percent with size="large"</span>
<Spin percent={70} size="large" aria-label="Upload progress" />
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 20px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.row {
display: flex;
align-items: center;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
fullscreen: a dimmed backdrop over the viewport, for three seconds spinning is false
<script lang="ts">
import { Button, Spin } from 'svelte-ant-design';
let loading = $state(false);
function show() {
loading = true;
setTimeout(() => (loading = false), 3000);
}
</script>
<div class="stack">
<div class="field">
<span class="caption">fullscreen: a dimmed backdrop over the viewport, for three seconds</span>
<!--
The backdrop is drawn where the component is (position: fixed), so put it near the root of the application, not
inside an element with a transform. It has no focus trap: Tab still reaches the page behind it.
-->
<Button disabled={loading} onclick={show}>Show fullscreen</Button>
<span>spinning is {loading}</span>
</div>
</div>
<Spin fullscreen spinning={loading} description="Loading the page" />
<style>
.stack {
display: grid;
justify-items: start;
gap: 20px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
classNames: a class for each part (the CSS is in this example)
Loading
styles: inline styles, custom properties included
Loading
class and style go to the root; container is the covered content
<script lang="ts">
import { Spin } from 'svelte-ant-design';
</script>
<div class="stack">
<div class="field">
<span class="caption">classNames: a class for each part (the CSS is in this example)</span>
<Spin
description="Loading"
classNames={{ indicator: 'demo-indicator', description: 'demo-description' }}
/>
</div>
<div class="field">
<span class="caption">styles: inline styles, custom properties included</span>
<Spin
description="Loading"
styles={{
root: { '--ads-spin-color': '#52c41a' },
description: { 'font-weight': 700, 'letter-spacing': '1px' }
}}
/>
</div>
<div class="field">
<span class="caption">class and style go to the root; container is the covered content</span>
<Spin
description="Loading"
class="demo-root"
style="border-radius: 8px"
classNames={{ container: 'demo-container' }}
styles={{ section: { 'gap': '4px' } }}
>
<div class="panel">Covered content</div>
</Spin>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 20px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.panel {
box-sizing: border-box;
width: 280px;
height: 120px;
padding: 16px;
border: 1px solid var(--ads-color-border);
border-radius: 8px;
}
:global(.demo-indicator) {
color: #fa541c;
}
:global(.demo-description) {
color: #fa541c;
font-style: italic;
}
:global(.demo-root) {
background: var(--ads-color-bg-container);
}
:global(.demo-container) {
border-radius: 8px;
}
</style>
API
| Property | Description | Type | Default |
|---|---|---|---|
| spinning | Whether the Spin is active. spinning={undefined} counts as the default, true. Standalone, not spinning (or still in the delay) renders nothing; embedded, the content is shown as it is. | boolean | true |
| delay | Milliseconds to wait, every time spinning becomes true (also at mount), before the indicator appears. Turning spinning off cancels the wait and hides at once; a repeated true starts no second timer. A negative or non-finite number throws a RangeError in development and means no delay in production. | number | — |
| size | Size of the dot box: 14, 20 or 32 px. default is a compatibility alias of medium. Another value throws a RangeError in development and falls back to medium in production. | 'small' | 'medium' | 'large' | 'default' | 'medium' |
| description | Text or content under the indicator. A string is text, never HTML; an empty string counts as not given. It is the status message that a screen reader announces and the name of the progress ring. | string | Snippet | — |
| indicator | Replaces the default dots. Drawn in a box of the dot size, with the same font size and the Spin color. The component does not turn it. Hidden from assistive technology. | Snippet | — |
| percent | Draws a progress ring in place of the dots. A number is clamped to 0 to 100; 'auto' is an indeterminate ring that turns, with no aria-valuenow and no timer. A value that is not a valid number, or of another type, throws a RangeError in development and is ignored in production. A custom indicator wins. | number | 'auto' | — |
| fullscreen | A dimmed backdrop over the viewport with the indicator in the middle. Drawn in place with position: fixed, so it is relative to the viewport only when no ancestor has a transform, filter or contain. It blocks the pointer, has no focus trap and does not lock the scroll. It fades in and leaves at once. | boolean | false |
| children | Embedded mode: the content the Spin covers. While spinning it has half opacity, ignores the pointer and the text selection, and gets aria-busy. It stays focusable and readable. Together with fullscreen it is drawn as it is, not dimmed. | Snippet | — |
| classNames | Extra classes for the parts root, section (indicator and description together), indicator, description and container (the covered content, embedded mode only), appended to the component's own. A standalone Spin has one element for root and section. | Partial<Record<'root' | 'section' | 'indicator' | 'description' | 'container', string>> | — |
| styles | Inline styles for the same parts. Property names are kebab-case or custom properties, numbers are written as they are (no automatic px). They win over the component's styles. | Partial<Record<'root' | 'section' | 'indicator' | 'description' | 'container', Record<string, string | number>>> | — |
| class | An additional CSS class for the root. | string | — |
| style | Inline style of the root; styles.root is written after it. | string | — |
| native attributes | Native attributes of the root <div> (id, title, data-*, aria-*, handlers) are forwarded to it. aria-label and aria-labelledby go to the status element (the section, in embedded mode), where they name a Spin that has no description. role belongs to the component. | HTMLAttributes<HTMLDivElement> | — |
Differences from Ant Design:
description replaces the deprecated tip, classNames.root replaces wrapperClassName, and size="default" is only an alias of medium. percent="auto" is an indeterminate ring that turns, not a simulated progress. indicator is a snippet, and classNames and styles take objects, not functions. There is no Spin.setDefaultIndicator: a default indicator and size are reserved for ConfigProvider in v1.1.Semantic parts
| Part | Description |
|---|---|
| root | The outer element. Standalone and fullscreen: the status element itself. |
| section | The indicator and the description together. The same element as the root when standalone; a separate one, centered over the content, when embedded or fullscreen. |
| indicator | The box of the dots, the ring or the custom indicator. |
| description | The text under the indicator. |
| container | The covered content. Embedded mode only (and with fullscreen plus children). |
Design tokens
| Token | Description | Default |
|---|---|---|
| --ads-spin-dot-size | Box of the dots of a medium Spin. | 20px |
| --ads-spin-dot-size-sm | Box of the dots of a small Spin. | 14px |
| --ads-spin-dot-size-lg | Box of the dots of a large Spin. | 32px |
| --ads-spin-gap | Space between the indicator and the description. | 12px |
| --ads-spin-color | Color of the dots, the ring and a custom indicator. | #1677ff |
| --ads-spin-description-color | Color of the description. tokens-accessible.css darkens it to #1668dc to keep 4.5:1 as text. | #1677ff |
| --ads-spin-container-opacity | Opacity of the covered content while spinning. | 0.5 |
| --ads-spin-duration | One turn of the dots or of the indeterminate ring. With prefers-reduced-motion it is 2.5 times longer. | 1.2s |
| --ads-spin-pulse-duration | One pulse of a dot. With prefers-reduced-motion it is 2.5 times longer. | 1s |
| --ads-spin-mask-bg | Backdrop of a fullscreen Spin. tokens-accessible.css sets 60% black, so white text on it keeps 4.5:1 over a white page. | rgba(0, 0, 0, 0.45) |
| --ads-spin-fullscreen-color | Color of the indicator and the description on the backdrop. | #ffffff |
| --ads-spin-fullscreen-z-index | Layer of the backdrop (the base layer of Ant Design popups). | 1000 |
| --ads-spin-ring-track | Track of the progress ring. | rgba(0, 0, 0, 0.06) |
Accessibility
- The dots, the drawing of the ring and a custom indicator are hidden from assistive technology. What a screen reader hears is the status element:
role="status", a polite live region, with the text ofdescription. - A Spin with no description is silent. Name it with
aria-labeloraria-labelledby; in development a spinning Spin with neither logs one warning. - In embedded mode the covered content gets
aria-busy="true"while spinning. It is not madeinertor hidden: the mouse and the text selection are blocked, the keyboard and a screen reader are not, so an action that must not run twice has to guard itself. - The progress ring is
role="progressbar"witharia-valuenow, named by the description or byaria-label. An indeterminate ring ('auto') has no value. - The fullscreen backdrop blocks the pointer but has no focus trap and does not lock the scroll, so Tab still reaches the page behind it.
- By default the colours are Ant Design's own. With
tokens-accessible.css, and in the dark theme, the dots and the ring keep 3:1 and the description 4.5:1 against the page, and white text on the fullscreen backdrop keeps 4.5:1.prefers-reduced-motionslows the turn instead of stopping it, and in forced-colors modes such as Windows High Contrast the dots and the ring are drawn with system colours. - Checked with a real screen reader (Orca with Firefox): it reads the description as a status, a Spin named by
aria-label, the content an embedded Spin covers, the progress ring with its name and its value in percent (and without a value when it is indeterminate), and a fullscreen Spin that hides nothing behind it. Not checked: whether a screen reader announces the status when it appears (the Orca setup does not speak a live region that is inserted into the page), NVDA, JAWS and VoiceOver.