Spinner

Spinner component is a web component that displays a spinner on top of the content. It can be used for loading states or any other type of information that needs to be displayed on top of the content.

Design system docs Examples Default spinner
<dap-ds-spinner></dap-ds-spinner>
Variants

Spinner has different variants to match the design system colors.

<dap-ds-stack direction="row">
  <dap-ds-spinner variant="neutral"></dap-ds-spinner>
  <dap-ds-spinner variant="brand"></dap-ds-spinner>
  <dap-ds-spinner variant="negative"></dap-ds-spinner>
  <dap-ds-spinner variant="positive"></dap-ds-spinner>
  <div style={{ backgroundColor: 'var(--dds-background-brand-base-inverted)'}}>
    <dap-ds-spinner variant="inverted"></dap-ds-spinner>
  </div>
</dap-ds-stack>
Sizes

Spinner has different sizes to match the design system spacing. You can use the size attribute to set the size of the spinner. The staticSize attribute can be used to set a custom size.

<dap-ds-stack direction="row">
  <dap-ds-spinner size="xs"></dap-ds-spinner>
  <dap-ds-spinner size="sm"></dap-ds-spinner>
  <dap-ds-spinner size="md"></dap-ds-spinner>
  <dap-ds-spinner size="lg"></dap-ds-spinner>
  <dap-ds-spinner size="xl"></dap-ds-spinner>
  <dap-ds-spinner size="xxl"></dap-ds-spinner>
  <dap-ds-spinner staticSize="70"></dap-ds-spinner>
</dap-ds-stack>
Text

You can add a text to the spinner.

<dap-ds-spinner text="Loading"></dap-ds-spinner>
Orientation

The spinner supports both vertical (default) and horizontal orientations. Use the orientation attribute to change the layout.

<dap-ds-stack direction="column" spacing="lg">
  <div>
    <p><strong>Vertical (default):</strong></p>
    <dap-ds-spinner variant="brand" text="Loading..."></dap-ds-spinner>
  </div>
  <div>
    <p><strong>Horizontal:</strong></p>
    <dap-ds-spinner variant="brand" orientation="horizontal" text="Loading..."></dap-ds-spinner>
  </div>
</dap-ds-stack>
Accessibility

The spinner component includes several accessibility features to ensure it works well with screen readers.

Custom ARIA Label

Use the aria-label attribute to provide custom screen reader text. If not provided, the component uses localized default text ("Loading..." in English, "Betöltés" in Hungarian).

<dap-ds-spinner
  variant="brand"
  aria-label="Loading user data, please wait"
  text="Loading...">
</dap-ds-spinner>
ARIA Live Region

The aria-live attribute controls how screen readers announce loading states. The default value is "polite" which waits for a pause before announcing. Use "assertive" for critical loading states.

<dap-ds-stack direction="column" spacing="lg">
  <div>
    <p><strong>Polite (default):</strong></p>
    <dap-ds-spinner
      variant="brand"
      aria-live="polite"
      text="Loading data...">
    </dap-ds-spinner>
  </div>
  <div>
    <p><strong>Assertive (for errors):</strong></p>
    <dap-ds-spinner
      variant="negative"
      aria-live="assertive"
      text="Error loading...">
    </dap-ds-spinner>
  </div>
</dap-ds-stack>
Delay

Use the delay attribute to prevent spinner flash on quick loading operations. The spinner will only appear if the loading takes longer than the specified delay (in milliseconds). This improves user experience by avoiding distracting flashes for operations that complete quickly.

<dap-ds-stack direction="column" spacing="lg">
  <div>
    <p><strong>No delay (immediate):</strong></p>
    <dap-ds-spinner variant="brand" text="Loading..."></dap-ds-spinner>
  </div>
  <div>
    <p><strong>With 300ms delay:</strong></p>
    <dap-ds-spinner
      variant="brand"
      delay="300"
      text="Loading...">
    </dap-ds-spinner>
  </div>
</dap-ds-stack>

A common pattern is to use a 300ms delay for most loading operations. This prevents the spinner from showing for very quick operations while still providing feedback for longer ones.

Reduced Motion Support

The spinner automatically respects the user's prefers-reduced-motion system preference. When reduced motion is enabled, the spinning animation is replaced with a fade/pulse effect to avoid motion sickness or distraction.

This accessibility feature is automatic and requires no additional configuration.

Combined Features

Here are examples combining multiple features for common use cases:

<dap-ds-stack direction="column" spacing="xl">
  <div>
    <p><strong>Horizontal with delay and custom label:</strong></p>
    <dap-ds-spinner
      variant="brand"
      orientation="horizontal"
      size="lg"
      delay="300"
      aria-label="Processing your request"
      text="Processing...">
    </dap-ds-spinner>
  </div>
  <div>
    <p><strong>Error state with assertive announcement:</strong></p>
    <dap-ds-spinner
      variant="negative"
      orientation="horizontal"
      aria-live="assertive"
      aria-label="Failed to load data"
      text="Error loading">
    </dap-ds-spinner>
  </div>
  <div style={{ backgroundColor: 'var(--dds-background-brand-base-inverted)', padding: '20px'}}>
    <p style={{ color: 'white' }}><strong>Inverted on dark background:</strong></p>
    <dap-ds-spinner
      variant="inverted"
      orientation="horizontal"
      text="Loading...">
    </dap-ds-spinner>
  </div>
</dap-ds-stack>
Importing
import { DapDSSpinner } from 'dap-design-system'
Importing React
import { DapDSSpinnerReact } from 'dap-design-system/react'
Tree-Shakeable Imports

For optimal bundle sizes, use the tree-shakeable import syntax:

import { DapDSSpinner } from 'dap-design-system/components'
Attributes
PropertyTypeDefaultDescription
variant"neutral", "brand" , "negative" , "positive" , "inverted"'neutral'The variant of the spinner.
size"xxl", "xl" , "lg" , "md" , "sm" , "xs"'lg'The size of the spinner.
staticSizenumber, undefinedThe size of the spinner in pixels. This overrides the size attribute
textstringThe loading text.
noColorbooleanfalseRemoves the text color
orientation"vertical", "horizontal"'vertical'The orientation of the spinner (icon and text layout).
ariaLive"polite", "assertive" , "off"'polite'The aria-live politeness level for screen readers.
delaynumber0Delay in milliseconds before showing the spinner.
Prevents flash for quick operations.
Slots
NameDescription
(default)The loading text content.
Events

No custom events available.

CSS Parts
Part NameDescription
baseThe main spinner container.
iconThe loading icon element.
icon-baseThe base of the loading icon.
textThe loading text element.
How to Use CSS Parts

You can style CSS parts using the ::part() pseudo-element selector:

/* Target a specific part */
.my-custom-dap-ds-spinner::part(base) {
  /* Your custom styles */
}

/* Target multiple parts */
.my-custom-dap-ds-spinner::part(base),
.my-custom-dap-ds-spinner::part(icon) {
  /* Shared styles */
}

Example usage:

<dap-ds-spinner class="my-custom-dap-ds-spinner">
  Spinner
</dap-ds-spinner>
.my-custom-dap-ds-spinner::part(base) {
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

CSS parts allow you to style internal elements of the component while maintaining encapsulation. Learn more in our styling guide.

CSS Custom Properties
Property NameDescription
--dds-spinner-icon-color-neutralColor for neutral spinner icons.
--dds-spinner-icon-color-brandColor for brand spinner icons.
--dds-spinner-icon-color-negativeColor for negative spinner icons.
--dds-spinner-icon-color-positiveColor for positive spinner icons.
--dds-spinner-icon-color-invertedColor for inverted spinner icons.
--dds-spinner-text-spacingSpacing between spinner and text.
--dds-spinner-animation-durationDuration of the spinner animation.
How to Use CSS Custom Properties

CSS custom properties (CSS variables) can be set directly on the component or in your stylesheet:

Method 1: Inline styles (Quick customization)

<dap-ds-spinner
  style="--dds-spinner-icon-color-neutral: value; --dds-spinner-icon-color-brand: value;">
  Spinner
</dap-ds-spinner>

Method 2: CSS classes (Reusable styles)

.my-custom-dap-ds-spinner {
  --dds-spinner-icon-color-neutral: value;
  --dds-spinner-icon-color-brand: value;
  --dds-spinner-icon-color-negative: value;
}
<dap-ds-spinner class="my-custom-dap-ds-spinner">
  Spinner
</dap-ds-spinner>

Method 3: Global theme customization

/* Apply to all instances */
dap-ds-spinner {
  --dds-spinner-icon-color-neutral: value;
  --dds-spinner-icon-color-brand: value;
}

CSS custom properties inherit through the Shadow DOM, making them perfect for theming. Changes apply immediately without rebuilding.