Progress
A horizontal bar that fills up as a task gets done, or shows how much of something is used. It is a native <progress>
element, so screen readers announce it as a progress bar with its value.
Thymeleaf source
<sl:progress value="33" aria-label="Upload progress"/>Rendered HTML
<progress class="progress" max="100" value="33" aria-label="Upload progress"></progress>When to use
Section titled “When to use”- An upload or an import whose progress the server reports.
- The steps of a form spread over several pages: step 3 of 8.
- How much of something is used or left, such as storage or stock.
Use something else for:
- Something that is loading, without a share to show: a spinner or a skeleton.
- The progress of files the user uploads: the file upload shows it on each file.
Value and maximum
Section titled “Value and maximum”value is how far the task has come, out of max: 100 unless you set it. Both are the native element’s attributes, so
th:value and th:max set them from an expression. A value above the maximum shows a full bar.
Thymeleaf source
<sl:progress value="3" max="8" aria-label="Steps done"/>Rendered HTML
<progress class="progress" max="8" value="3" aria-label="Steps done"></progress>Thymeleaf source
<sl:progress th:value="${task.done}" th:max="${task.total}" th:aria-label="${task.name}"/>Rendered HTML
<progress class="progress" max="1000" value="750" aria-label="Import contacts"></progress>A name
Section titled “A name”A progress bar needs an accessible name, or rendering fails: an aria-label, or an aria-labelledby with the id of a
visible label. In a field, the field label is that label:
Thymeleaf source
<sl:field> <sl:field-label id="upload-label">Upload progress</sl:field-label> <sl:progress value="66" aria-labelledby="upload-label"/> <sl:field-description>8 of 12 MB</sl:field-description></sl:field>Rendered HTML
<div class="field"> <label class="label field-label" id="upload-label">Upload progress</label> <progress class="progress" max="100" value="66" aria-labelledby="upload-label"></progress> <p class="field-description">8 of 12 MB</p></div>Indeterminate
Section titled “Indeterminate”Without a value the bar is indeterminate: it shows an empty track, as shadcn’s, and a screen reader announces a progress
bar without a value. A th:value whose expression is null still writes an empty value attribute, which the browser
reads as 0; for a value that may be null, use th:attr, which leaves the attribute out:
<sl:progress th:attr="value=${export.percent}" aria-label="Export"/>Thymeleaf source
<sl:progress aria-label="Preparing the export"/>Rendered HTML
<progress class="progress" max="100" aria-label="Preparing the export"></progress>Updating with htmx
Section titled “Updating with htmx”The server renders the value, so to show progress while a task runs, swap the bar in again: poll a fragment with
hx-trigger="every 1s" around it, or send it out of band with each response. A progress element is not a live region;
put the text that matters (such as “Import done”) in a status message or a toast.
Everything else passes through
Section titled “Everything else passes through”Thymeleaf source
<sl:progress value="80" aria-label="Storage used" class="app-wide" id="storage" data-testid="storage"/>Rendered HTML
<progress class="progress app-wide" max="100" value="80" aria-label="Storage used" id="storage" data-testid="storage"></progress>Attributes
Section titled “Attributes”sl:progress declares no props; every attribute passes through.
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. The bar is the element itself; the indicator is
the browser’s ::-webkit-progress-value (Chrome, Safari) and ::-moz-progress-bar (Firefox), each in a rule of its
own.
Parts
| Class | Element |
|---|---|
.progress | <progress> |