Skip to content

Spinner

A spinning icon that tells the user something is loading, with a label for screen readers.

Spinner
Thymeleaf source
<sl:spinner/>
Rendered HTML
<svg xmlns="http://www.w3.org/2000/svg" class="icon spinner" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" role="status" aria-label="Loading">
<path d="M21 12a9 9 0 1 1-6.219-8.56"></path>
</svg>
  • In a button while it saves (the button’s loading does this for you).
  • In a part of the page that waits for an htmx response.

Use something else for:

  • The shape of the content that is loading: a skeleton.

A spinner is a status (role="status") named “Loading”. Give it an aria-label of its own to say what is loading; the default is the message sl.spinner.label, which you can reword or translate in your messages.properties.

Saying what loadsAn aria-label replaces the default name, "Loading".
Thymeleaf source
<sl:spinner aria-label="Loading invoices"/>
Rendered HTML
<svg xmlns="http://www.w3.org/2000/svg" class="icon spinner" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" role="status" aria-label="Loading invoices">
<path d="M21 12a9 9 0 1 1-6.219-8.56"></path>
</svg>

For a button that is busy, use <sl:button loading> instead: it shows the spinner, disables the button and announces the busy state. To show a skeleton of the content to come, use <sl:skeleton>.

A spinner is 16 pixels, or the size of an icon in the component around it, such as <sl:empty-media variant="icon">. size sets the width and height in pixels.

Sizes
Thymeleaf source
<sl:spinner/>
<sl:spinner size="24"/>
<sl:spinner size="32"/>
Rendered HTML
<svg xmlns="http://www.w3.org/2000/svg" class="icon spinner" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" role="status" aria-label="Loading">
<path d="M21 12a9 9 0 1 1-6.219-8.56"></path>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" class="icon spinner" viewBox="0 0 24 24" width="24" height="24" data-icon-size="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" role="status" aria-label="Loading">
<path d="M21 12a9 9 0 1 1-6.219-8.56"></path>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" class="icon spinner" viewBox="0 0 24 24" width="32" height="32" data-icon-size="32" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" role="status" aria-label="Loading">
<path d="M21 12a9 9 0 1 1-6.219-8.56"></path>
</svg>

For users who ask for reduced motion the spinner turns slower instead of standing still: a frozen arc reads as a broken icon.

AttributeValuesDefaultDescription
sizenumber—Width and height in pixels. Without it the spinner is 16 pixels, or sized by the surrounding component (as an icon in sl:empty-media).

Every prop can also be set from an expression: th:size="${...}". Any other attribute passes through to the rendered element, and class is appended.

The classes and attributes your own CSS can select to restyle the component, as explained in your own CSS rules.

Parts

ClassElement
.spinner<svg>

States

SelectorValues
.spinner[data-icon-size="…"]24 32