Markup
<div class="tray-progress">
<span class="tray-progress__name">Autumn batch reserved</span>
<span class="tray-progress__value">68%</span>
<span class="tray-progress__bar" role="progressbar" aria-label="Autumn batch reserved"
aria-valuemin="0" aria-valuemax="100" aria-valuenow="68" style="--tray-v: 68"></span>
</div>Set the fill with --tray-v (0 to 100) and keep aria-valuenow in step. The name and the value sit above the bar; a bar without a number beside it is decoration.
Variants: tray-progress--accent fills in yellow, for the single bar on an ink card. tray-progress--busy slides a segment when the length is not known yet (leave out aria-valuenow). tray-steps is a row of short pills for "step 2 of 4": mark the finished ones with data-done.
Use role="meter" instead of progressbar for a level that is not a task: stock left, a rating, a share.
Accessibility
- The bar is a
role="progressbar"for a task or arole="meter"for a level, named by anaria-labelthat repeats the visible name. aria-valuemin,aria-valuemaxandaria-valuenowcarry the amount. When the words beside the bar are not a percentage, addaria-valuetextwith those words ("68%: 132 of 412 jars left"), as the example does.- A busy bar has no
aria-valuenow, so it is read as a progress bar of unknown length. Its sliding segment stops underprefers-reduced-motion: reduce. - A
tray-stepsrow on its own takesrole="progressbar"and anaria-valuetextsuch as "Step 2 of 4: Delivery". Beside a written count, as in Questionnaire, it isaria-hidden="true". - The fill is ink on grey, not a hue, and with forced colours the track and the fill are drawn in the system's colours.
Do and don't
- Do print the value in words when it is not a percentage: "132 of 412 jars left".
- Do use ink for the fill. Yellow only on an ink card.
- Don't use a data colour for a progress bar.
- Don't let the bar go backwards.