Progress Bar Examples
The examples below assume that you have imported the component and set up the theme.
Basic
Show a known amount of progress. value sets the fill, a data-sv-progress-bar-percentage element shows the number, and data-sv-progress-bar-value-text has screen readers read the same text.
Reduced Motion
The indeterminate fill sits still in the middle of the track because your system is set to reduce motion.
--indeterminate
<div class="bar-basic"> <sv-progress-bar aria-label="Upload progress" value="65"> <span>Uploading</span> <span class="value" data-sv-progress-bar-value-text> <span data-sv-progress-bar-percentage="0"></span> <span>%</span> </span> </sv-progress-bar></div>
<style> .bar-basic { display: grid; justify-items: center;
sv-progress-bar { inline-size: min(100%, 20rem); font-size: 0.875rem; }
.labels-below { flex-direction: column-reverse; }
sv-progress-bar[vertical] { inline-size: auto; block-size: 10rem; }
.value { display: flex; }
.fill-value { font-size: 0.75rem; color: var(--sv-accent-content); }
sv-progress-bar:state(--indeterminate) .value { display: none; } }</style>Download
Drive the bar from script as progress arrives. Setting the value property each time animates the fill to the new value.
<div class="bar-download"> <sv-progress-bar class="download-bar" aria-label="Download progress" value="0"> <span>Downloading</span> <span class="value" data-sv-progress-bar-value-text> <span data-sv-progress-bar-percentage="0"></span> <span>%</span> </span> </sv-progress-bar></div>
<script type="application/x-typescript" module> const bar = document.querySelector<ProgressBar>(".download-bar")!;
let speed = 100;
function tick() { const current = bar.value ?? 0; const next = current >= bar.max ? 0 : current + 1;
bar.value = next;
if (Math.random() < 0.1) { speed = 20 + Math.random() * 380; }
setTimeout(tick, next >= bar.max ? 1500 : speed); }
tick();</script>
<style> .bar-download { display: flex; justify-content: center;
sv-progress-bar { inline-size: min(100%, 20rem); font-size: 0.875rem; }
.value { display: flex; } }</style>