Build an accessible CSS status ring for a file preview
Admin ·
A file preview can take a moment to appear. A loading ring makes the wait visible when the operation has no measured completion percentage. Set its dimensions up front so the surrounding layout has room for it.
Set a 48-pixel ring with a four-pixel stroke
Choose Track ring, set Size to 48 px, Cycle length to 0.8 seconds, Thickness to 4 px and Hex color to #246B73. Set CSS class to file-preview-loader. The 48-pixel box includes the stroke.
Choose Dark preview and check the brighter leading segment against the faint track. Select Pause preview to inspect one position. Replay preview restores movement from the beginning of the cycle.
Verify the downloaded HTML in a browser
Choose Download HTML and open css-loader.html. Look for .file-preview-loader and @keyframes file-preview-loader-cycle in the source. Inspect the shape’s computed width and height of 48 pixels, border width of 4 pixels and animation duration of 0.8 seconds.
Turn on your browser’s reduced-motion emulation or operating system setting. The ring should remain visible with its leading segment at the top. The Loading text stays available to assistive technology through the status element.
W3C CSS Animations, animation duration and keyframesW3C Media Queries, prefers-reduced-motionW3C WAI-ARIA, status role
Use the ring while a real operation is pending
Copy the HTML and CSS into your page and keep the class name and keyframe name paired. Show the status while the file is loading, then replace it with the successful preview or the error message when the result arrives.
For a second size, make another export with a distinct CSS class. Reserve enough space for each indicator in the component’s layout to reduce movement when its status changes.
W3C CSS Animations, animation duration and keyframesW3C WAI-ARIA, status role
Common questions
Does the moving meter report a percentage?
The moving bar is an indeterminate indicator for a pending operation. When you have measured progress, present that value separately in a progress element or a measured progress bar.
What happens if the class name matches an existing rule?
Rules with the same selector can interact through the cascade. Give the export a unique class and keep the HTML and CSS from that same export together.