Skip to content

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.

Progress
Thymeleaf source
<sl:progress value="33" aria-label="Upload progress"/>
Rendered HTML
<progress class="progress" max="100" value="33" aria-label="Upload progress"></progress>
  • 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 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.

Out of another maximum
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>
Values from an expression
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 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:

With a labelaria-labelledby names the bar after the visible 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>

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"/>
IndeterminateWithout a value, the bar says that work goes on without saying how far it is.
Thymeleaf source
<sl:progress aria-label="Preparing the export"/>
Rendered HTML
<progress class="progress" max="100" aria-label="Preparing the export"></progress>

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.

Pass-through attributesAnything that is not a prop lands on the progress element; class is appended.
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>

sl:progress declares no props; every attribute passes through.

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

ClassElement
.progress<progress>