Spinner
A spinning icon that tells the user something is loading, with a label for screen readers.
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>When to use
Section titled “When to use”- In a button while it saves (the button’s
loadingdoes 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.
What it says
Section titled “What it says”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.
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.
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>Reduced motion
Section titled “Reduced motion”For users who ask for reduced motion the spinner turns slower instead of standing still: a frozen arc reads as a broken icon.
Attributes
Section titled “Attributes”| Attribute | Values | Default | Description |
|---|---|---|---|
size | number | — | 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.
Styling hooks
Section titled “Styling hooks”The classes and attributes your own CSS can select to restyle the component, as explained in your own CSS rules.
Parts
| Class | Element |
|---|---|
.spinner | <svg> |
States
| Selector | Values |
|---|---|
.spinner[data-icon-size="…"] | 24 32 |