# The Loading Loop — full text > The Loading Loop is an independent code publication for designers and front-end developers building honest loading feedback. It pairs copyable HTML and CSS with the accessibility, state management, layout, and performance details that make a loader useful outside a demo box. # Accessible Loading Indicators: Motion, Status, and ARIA > Accessible loading indicators pair a visual cue with a meaningful text status. Use `role="status"` for polite indeterminate updates, `aria-busy="true"` on the region being changed, and native `` when completion is measurable. Hide decorative animation from assistive technology, honor `prefers-reduced-motion`, preserve sensible keyboard focus, avoid invented percentages, and replace loading with accurate success, empty, failure, or cancellation states. Source: https://css-spinners.com/accessible-loading-indicators/ Publisher: The Loading Loop Published: 2026-07-19 Updated: 2026-08-25 ## Accessible loading feedback combines state, text, and restraint An accessible loading indicator tells users what is happening without relying on motion, color, or sight alone. Use a status message for indeterminate work, `aria-busy="true"` on the region being updated, and a native `` element or correctly implemented progress bar when completion is measurable. Treat the animation as decorative, honor reduced-motion preferences, preserve focus, and replace loading with success or error at the right time. There is no magic `aria-loading` attribute. Accessibility comes from matching semantics to the task and updating them truthfully. A spinner can rotate with the confidence of a tiny lighthouse while communicating absolutely nothing. ## Choose the semantic pattern from the information you have | Task state | Visual option | Semantic option | |---|---|---| | Indeterminate, short | Spinner or dots plus text | `role="status"` and meaningful message | | Region updating | Local overlay or skeleton | `aria-busy="true"` on affected region | | Determinate progress | Progress bar | Native `` with value and label | | User must act now | Usually no loader | Focused error, dialog, or alert as appropriate | | Failed or timed out | Stop animation | Error text and recovery action | | No results | No loader | Empty-state message | Do not use a determinate progress bar with invented percentages. If the system cannot estimate progress, say what it is doing and use an indeterminate pattern. A bar that travels briskly to 93% and rents an apartment there is not more informative than a spinner. ## Pattern 1: An indeterminate status Keep the live-region container in the DOM before loading starts. Update its text when the state changes. ```html
``` When a request begins, application code should set `aria-busy="true"` on `#search-results` and insert a useful message into `#search-status`: ```html
Loading search results…
``` When the request ends, replace the text with a concise result such as “12 search results loaded,” set `aria-busy="false"`, and remove the visual spinner. If the request fails, announce “Search results could not be loaded” and expose a retry action in the ordinary interface. W3C's [`role="status"` technique](https://www.w3.org/WAI/WCAG21/Techniques/aria/ARIA22) explains that status is a polite live region and advises having the container present before the update. `aria-atomic="true"` requests announcement of the whole message when its contents change. Use status for advisory updates that should not interrupt the user. Do not upgrade every loading message to `role="alert"`; assertive announcements can cut off other speech and become exhausting. ## Pattern 2: A native determinate progress bar When the application knows the amount completed, use native HTML: ```html
40% 40% complete
``` Update both `value` and visible text from the real task state. Here `40 ÷ 100 = 0.4`, so 40% is exact. If completed bytes are 2,000,000 out of 5,000,000, the percentage is also 40 because `2,000,000 ÷ 5,000,000 × 100 = 40`. Native `` provides built-in semantics. Keep a visible label and text because browser rendering varies and users benefit from a plain-language value. Do not use `` for task progress; W3C's ARIA Authoring Practices distinguishes a meter, which reports a value within a known range, from progress toward completion. For indeterminate native progress, omit the `value` attribute: ```html Preparing report… ``` If the system later knows completion, add and update `value` based on actual work. ## Pattern 3: A skeleton for an updating region A skeleton previews layout but has no semantic value of its own. Hide its shapes and expose the region state: ```html

Loading recent articles…

``` On completion, replace the shapes with real articles, clear `aria-busy`, and update or clear the status according to what helps users. The [layout-stable CSS skeleton](/css-skeleton-loader/) includes complete styling and reduced-motion behavior. Do not give the three fake cards headings, buttons, or alt text. They are not three content items yet. Their only job is visual space reservation. ## What `aria-busy` does—and does not do `aria-busy="true"` indicates that an element and its subtree are being modified and may not be complete. Apply it to the region whose content is updating, not automatically to ``. Clear it when that region is ready. It does not: - Draw a visual indicator - Tell users what task is running - Disable controls - Calculate progress - Resolve focus management - Guarantee an announcement by itself in every environment Pair it with visible status and sensible application behavior. If existing content remains usable during refresh, do not cover or disable the whole region unnecessarily. A user reading page two should not be ejected from civilization because page three is fetching. ## Make motion optional without removing information Use `prefers-reduced-motion` to stop or replace non-essential loops: ```css .spinner { width: 1.5rem; height: 1.5rem; border: 0.2rem solid #cbd5e1; border-top-color: #1d4ed8; border-radius: 50%; animation: spin 0.8s linear infinite; } @keyframes spin { to { transform: rotate(1turn); } } @media (prefers-reduced-motion: reduce) { .spinner { animation: none; } } ``` The text remains. The static partial ring still provides a visual cue. This is the complete [border-spinner pattern](/css-loading-spinner/); the [three-dot loader](/css-three-dot-loader/) uses the same semantic separation. Reduced motion is not a demand to remove all state changes. A progress value can still update. Text can still change from “Uploading” to “Upload complete.” Avoid continuous rotation, bouncing, sweeping, zooming, and pulsing where a static component plus state text works. ## Keep focus stable Loading is usually not a reason to move keyboard focus. If a user activates “Load more,” keep focus on that control while new items appear after the existing list. If they submit a form and validation fails, focus or announcement may need to move to the error summary according to the form design—not to the spinner. For a route or view change, focus management may be necessary after new content is ready so users understand the new context. Move focus to a meaningful heading or container with deliberate code, not to an animated visual. Never add `tabindex="0"` to a decorative loader merely to make it “accessible.” That inserts a useless stop into keyboard navigation. Status live regions normally should not receive focus. ## Disable only what must be disabled Preventing duplicate submission can justify disabling the submit button while its request is pending. Keep its label understandable: ```html ``` But disabling every control or placing an opaque full-screen layer over the interface can block unrelated work. Scope the busy state to the operation. Be careful with disabled controls: users cannot focus native disabled buttons to inspect them. Nearby visible status should explain why the action is unavailable, and the control must return to an enabled state on both success and recoverable failure. For actions that may be cancelled, provide a real cancel control and explain what cancellation means. Do not display a decorative “X” that merely hides the loader while the upload continues cheerfully in the basement. ## Avoid announcement spam Live regions should report meaningful changes, not animation frames. Never update “Loading.” to “Loading..” to “Loading...” repeatedly for assistive technology. The visual dots can animate while the accessible message remains stable. For determinate progress, announcing every one-percent change may be excessive. Choose meaningful intervals or milestones based on task duration and user need. Keep the visual `` value accurate even if spoken updates are less frequent. Do not place several nested live regions around the same message. Test with the screen readers and browsers you support because announcement behavior can differ. ## Account for timing and perceived delay An indicator shown for a very brief operation can create flicker and make the interface feel slower. A delayed reveal may help, but there is no universal threshold that fits every application, network, or user. Measure real tasks and test the transition. For longer waits, progressively offer more information: - What is happening - Whether the rest of the interface remains usable - Actual progress, if measurable - A cancel or background option, if supported - What to do after a timeout or failure Do not promise “This will take a minute” unless the system has a reliable estimate. Honest uncertainty is better than a fake countdown. ## Test the full state machine Test more than the animation. Use this sequence: 1. Start from idle with a keyboard and screen reader. 2. Trigger loading and confirm one useful announcement. 3. Continue navigating and verify focus stays sensible. 4. Enable reduced motion and confirm state remains visible. 5. Simulate a slow response. 6. Simulate success, empty results, failure, retry, and cancellation. 7. Confirm `aria-busy`, disabled controls, progress values, and indicators all reset. 8. Trigger two concurrent operations and verify messages remain distinguishable. Also zoom text, test high contrast or forced-colors modes where supported, and inspect color contrast. A border that depends on a subtle hue shift may disappear under user color settings; visible text remains the reliable anchor. ## Common accessibility failures **Spinner with no text:** Users know something moves, but not what or where. Add a scoped message. **Visual hidden with `display: none`:** Assistive technology loses the message too. Use visible text or a tested visually-hidden utility. **Permanent `aria-busy="true"`:** The accessibility state lies after completion. Clear it in success and failure paths. **Fake percent:** A determinate bar reports numbers not tied to work. Use indeterminate status instead. **Focus on loader:** Keyboard users gain a meaningless stop. Leave decoration unfocusable. **Animation survives reduced motion:** Add a static alternative and test the operating-system preference. **Error keeps spinning:** Stop the loader, explain the problem, and offer recovery. Accessible loading feedback is less about making a spinner speak and more about designing a coherent state transition. Name the task, scope the busy region, preserve control, honor motion preferences, and provide an ending the user can understand. ## Frequently asked questions **What ARIA role should a loading spinner use?** Usually the moving spinner should be decorative with `aria-hidden="true"`, while a containing or nearby message uses `role="status"`. Status creates a polite live region for text such as “Loading search results…”. Keep the status container present before dynamically inserting the message, and do not put focus on the spinner. **When should I use aria-busy?** Set `aria-busy="true"` on the specific region whose content is being updated, then clear it when the update succeeds or fails. It does not draw a loader, disable controls, calculate progress, or explain the task. Pair it with visible feedback and a useful status message when users need one. **Should I use a progress bar or spinner?** Use a progress bar when the application can report real completion against a known maximum. Use a spinner or text status when duration or completion is indeterminate. Never invent percentages to make a task look measurable. Use an empty state when no results exist and an error with recovery when loading fails. **How do I make a loading indicator respect reduced motion?** Stop or replace continuous rotation, bouncing, sweeping, and strong pulsing inside `@media (prefers-reduced-motion: reduce)`. Keep the status text and any static visual cue, and continue updating actual progress values. Reduced motion should remove non-essential movement without removing information about the task or its outcome. **Should focus move to a loading indicator?** Usually no. Keep focus on the control the user activated while local content loads. After a true navigation or major view replacement, move focus deliberately to a meaningful new heading or container if needed. Do not make decorative loaders focusable; live status regions normally announce updates without receiving keyboard focus. **How do I prevent screen readers from repeating loading messages?** Keep one scoped live region, update it only when application state meaningfully changes, and avoid rewriting identical text or animated ellipses. Do not nest several live regions around the same message. For determinate tasks, visual progress can update continuously while spoken messages occur at useful milestones rather than every percentage point. --- # CSS Dual Ring Spinner With Two Counter-Rotating Arcs > A CSS dual ring spinner uses one decorative element with two circular pseudo-elements. Give each a partly transparent border, keep their centers aligned, and reverse the inner arc's rotation. This recipe adds visible loading text, static reduced-motion styling and a four-second motion limit. The application, not the rotation count, determines when loading ends. Source: https://css-spinners.com/css-dual-ring-spinner/ Publisher: The Loading Loop Published: 2026-09-15 Updated: 2026-09-15 ## How do you make a CSS dual ring spinner? A CSS dual ring spinner uses one decorative element with two circular pseudo-elements. Give each a partly transparent border, keep their centers aligned, and reverse the inner arc's rotation. This recipe adds visible loading text, static reduced-motion styling and a four-second motion limit. The application, not the rotation count, determines when loading ends. Choose this shape when two concentric arcs fit your interface. They do not represent two tasks or a completion percentage. The [spinner examples library](/css-spinner-examples-library/) compares other shapes; the [single-ring recipe](/css-loading-spinner/) is a simpler visual alternative. ## What code should you copy? Paste this HTML and CSS into a document. The buttons are manual demonstration controls: they show waiting, success and failure without sending a network request. The drawing uses one span; the paragraph carries its meaning. ```html

``` ```css .ring-row { display: flex; align-items: center; gap: 0.75rem; } .dual-ring { --size: 3rem; --stroke: 0.1875rem; --outer: #1d4ed8; --inner: #7e22ce; position: relative; display: block; flex: none; width: var(--size); height: var(--size); padding: 0; border: 0; } .dual-ring[hidden] { display: none; } .dual-ring::before, .dual-ring::after { content: ""; position: absolute; box-sizing: border-box; inset: 0; border: var(--stroke) solid transparent; border-top-color: var(--outer); border-right-color: var(--outer); border-radius: 50%; transform-origin: 50% 50%; transform: rotate(0turn); } .dual-ring::after { inset: 25%; border-top-color: var(--inner); border-right-color: var(--inner); } @keyframes dual-turn { from { transform: rotate(0turn); } to { transform: rotate(1turn); } } @media (prefers-reduced-motion: no-preference) { .dual-ring:not([hidden])::before, .dual-ring:not([hidden])::after { animation: dual-turn 1s linear 4; } .dual-ring:not([hidden])::after { animation-direction: reverse; } } ``` The empty `content` declaration creates the generated boxes. Removing it can make a pseudo-element disappear, as [MDN's before reference](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Selectors/::before) explains. Keep meaningful words in the HTML paragraph, not generated CSS content. ## Why do the arcs rotate in opposite directions? Both arcs use the same keyframes. The outer arc follows them forwards; the inner arc uses `animation-direction: reverse`, which [MDN defines as playing backwards each cycle](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/animation-direction). With linear timing, they move steadily in opposite directions. Keep the reverse declaration after the shared animation shorthand. If a later shorthand replaces it, inspect the inner arc's computed `animation-direction` before changing the keyframes. Animate the pseudo-elements themselves: rotating their parent would carry both arcs around together. ## How do the rings stay centered when resized? The parent is square. The outer box fills it; the inner box is inset by one-quarter of the parent's size on every side. [MDN's box-sizing reference](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/box-sizing) explains that `border-box` includes borders within the box dimensions. Equal opposing insets keep the inner box centered. At a root font size of 16 pixels, the default `3rem` is 48 pixels. This recipe's geometry is: | Measurement | Calculation | Result | |---|---|---| | Outer diameter | 3 × 16 | 48 pixels | | Inner inset on each side | 48 × 0.25 | 12 pixels | | Inner diameter | 48 − 12 − 12 | 24 pixels | | Border thickness | 0.1875 × 16 | 3 pixels | | Shared center from parent's top-left | 48 ÷ 2 | 24 pixels on each axis | Each pseudo-element rotates around its own center. [MDN's transform-origin reference](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/transform-origin) identifies `50%` as the center coordinate. Because those centers coincide, neither arc should orbit the other. Change `--size` and `--stroke` together when making a much smaller icon. At `1.5rem`, try `0.125rem` strokes: with the same 16-pixel root, those are a 24-pixel outer diameter, 12-pixel inner diameter and 2-pixel borders. Keep the stroke thinner than one-quarter of the outer size so the inner opening and the gap remain visible. This limit comes from the recipe's geometry, not a universal spinner rule. Change `--outer` and `--inner` for your theme, checking both against the background. Equal colors still preserve counter-rotation. Leave padding and borders off the parent; put surrounding decoration on a wrapper. ## Why does motion stop after four seconds? Four one-second cycles take four seconds. Afterward the base, static arcs return; the loading text remains. This is a motion limit, not a timeout or evidence that the task finished. Motion is enabled only by `prefers-reduced-motion: no-preference`. Under a reduced-motion preference, the base static styling remains from the start. [MDN documents these preference values](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@media/prefers-reduced-motion). If you replace the count with an endless loop, review [WCAG's Pause, Stop, Hide criterion](https://www.w3.org/WAI/WCAG22/Understanding/pause-stop-hide.html): nonessential moving information that starts automatically, lasts more than five seconds and appears alongside other content needs a pause, stop or hide mechanism. This bounded recipe avoids ongoing rotation; it does not establish whole-page accessibility compliance. ## How should the application end the loading state? Put this script after the markup. Finish and Fail only affect a waiting demo. Start while waiting does nothing, so repeated clicks cannot restart the motion indefinitely. ```js const visual = document.querySelector("#ring-visual"); const message = document.querySelector("#ring-status"); let waiting = false; document.querySelector("#ring-start").onclick = () => { if (waiting) return; waiting = true; visual.hidden = false; message.textContent = "Loading demo content..."; }; function finishDemo(text) { if (!waiting) return; waiting = false; visual.hidden = true; message.textContent = text; } document.querySelector("#ring-done").onclick = () => { finishDemo("Demo content loaded."); }; document.querySelector("#ring-fail").onclick = () => { finishDemo("Demo failed. Select Start demo to retry."); }; ``` For production, connect these transitions to the actual operation and remove the outcome buttons. Handle success, failure, cancellation and timeout deliberately. Never use `animationend` to announce success. A component removed from the page also needs its pending work and state handled by the application. The persistent paragraph has `role="status"`, providing polite live-region semantics. The explicit atomic attribute requests the whole message. [W3C technique ARIA22](https://www.w3.org/WAI/WCAG22/Techniques/aria/ARIA22) checks that the status container exists before its update. Our code changes its text at state transitions, not on animation frames. The [accessible loading indicators guide](/accessible-loading-indicators/) covers integration with updating content regions. ## What should you verify in your page? Inspect both pseudo-elements separately. Confirm equal width and height, matching center coordinates and opposite computed rotation directions. If an arc wobbles, first check for a rectangular parent, unequal insets or an overridden transform origin. If neither appears, inspect `content` and border colors before adjusting animation speed. The exact demonstration was tested in headless Microsoft Edge: counter-rotation, concentric geometry at several sizes, terminal states, retry, reduced-motion emulation and static state after the motion limit. DOM checks do not prove screen-reader announcements. Test your supported browser and assistive-technology combinations, keyboard flow, zoom and themes before shipping. Only `transform` changes during rotation. [MDN's performance guide](https://developer.mozilla.org/en-US/docs/Web/Performance/Guides/Animation_performance_and_frame_rate) explains that transforms handled in composition can avoid layout and repaint work. That is not a frame-rate promise. Profile the actual page if multiple indicators or other animations compete for resources. ## Sources - [MDN: before pseudo-element](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Selectors/::before). - [MDN: animation-direction](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/animation-direction). - [MDN: box-sizing](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/box-sizing). - [MDN: transform-origin](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/transform-origin). - [MDN: reduced motion](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@media/prefers-reduced-motion). - [W3C: Pause, Stop, Hide](https://www.w3.org/WAI/WCAG22/Understanding/pause-stop-hide.html). - [W3C: ARIA22 status messages](https://www.w3.org/WAI/WCAG22/Techniques/aria/ARIA22). - [MDN: animation performance](https://developer.mozilla.org/en-US/docs/Web/Performance/Guides/Animation_performance_and_frame_rate). ## Frequently asked questions **Why does the inner ring look off-center?** Inspect the parent and both generated boxes. This recipe needs a square parent and equal insets on opposing sides. At the default 48-pixel outer size, the inner box is 24 pixels wide with 12-pixel insets. Check for overriding padding, borders or transform-origin declarations before changing the animation. **Can both arcs use the same keyframes?** Yes. The example applies one rotation animation to both pseudo-elements, then gives the inner one reverse direction. Keep that declaration after the shared animation shorthand. Animating the parent instead would carry both arcs together, which would not produce the independent counter-rotation shown by this recipe. **Does stopping the animation mean loading has finished?** No. Four seconds is this example's motion limit, not its task deadline. The arcs become static while the loading message remains. Only the demonstration's outcome controls end its wait. In an application, success, failure, cancellation and timeout must come from actual task handling, never from a completed rotation. **Will a screen reader announce both rings?** The decorative span is hidden from assistive technology; the separate paragraph carries the message through a status role. Keep that container present before changing its text. Test the actual announcements with your supported screen-reader and browser combinations: checking DOM attributes alone does not establish what a person will hear. **What happens when reduced motion is enabled?** The example leaves both arcs static and retains visible loading text. Its animation declarations are inside a no-preference media query, so they do not apply when the reduced-motion setting matches. Check this preference while waiting as well as before starting, and confirm that ending the task still hides the decoration. --- # CSS Line Loader: A Bar With Honest Loading States > A CSS line loader uses a clipped track and a narrower pseudo-element animated with translateX. Treat the moving bar as decoration, not a completion percentage. Keep visible text in one persistent status region, provide a static reduced-motion state, and remove the visual when the actual operation succeeds or fails. Test the complete interaction with your supported browsers and assistive technologies. Source: https://css-spinners.com/css-line-loader-bar/ Publisher: The Loading Loop Published: 2026-09-08 Updated: 2026-09-08 ## How do you make a CSS line loader? Build a CSS line loader from one decorative element with a clipped, narrower pseudo-element moving across it with `transform: translateX()`. Pair it with visible status text, keep reduced motion static, and hide the line when the actual task succeeds or fails. The sweep indicates an indeterminate wait: its position and width are not completion percentages. This recipe adds the details a thin loading line needs outside a visual demo: exact travel geometry, a motion limit, one persistent status, and a working local lifecycle demonstration. For a circular alternative, use the [CSS loading spinner recipe](/css-loading-spinner/). ## Copy the markup and CSS Paste the HTML into a document body and the CSS into its stylesheet. The three buttons deliberately control a local demonstration; they do not contact a server or simulate measured download progress. “Finish” and “Fail” affect only a pending demo. ```html

Local demo: start a wait, then choose its outcome.

Existing demo content.
``` ```css .line-loader { position: relative; width: 100%; max-width: 24rem; height: 0.25rem; overflow: hidden; border-radius: 999px; background: #dbeafe; } .line-loader[hidden] { display: none; } .line-loader::before { content: ""; position: absolute; top: 0; bottom: 0; left: 0; width: 40%; background: #1d4ed8; border-radius: inherit; transform-box: border-box; transform: translateX(75%); } @keyframes line-sweep { from { transform: translateX(-100%); } to { transform: translateX(250%); } } @media (prefers-reduced-motion: no-preference) { .line-loader:not([hidden])::before { animation: line-sweep 1.2s linear 3; } } ``` The visual loader itself is one element. Its `::before` pseudo-element supplies the moving segment. The status paragraph is separate information, not an extra piece needed to draw the line. The line takes its container's width up to `24rem`. Change that cap for your layout; keep `width: 100%` to accommodate narrower containers. Reserve a row for it in the surrounding layout if showing and hiding it would otherwise move content. ## Why do the translations use those percentages? [MDN's translateX reference](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/transform-function/translateX) specifies that percentage translation uses the reference box established by `transform-box`. Here that is the moving segment's border box, not the track. The segment is 40% of the track. For an illustrative 300-pixel track: | State | Calculation | Segment's left edge | |---|---|---| | Beginning | 120 × -1 | -120 pixels | | End of sweep | 120 × 2.5 | 300 pixels | | Static center | 120 × 0.75 | 90 pixels | At the beginning its right edge is zero; at the end its left edge reaches the track's far edge. Clipping hides the off-track portion. The static segment extends from 90 to 210 pixels, centered in the 300-pixel track. Those values are geometry, not progress data. If you change the segment width, recalculate travel and centering rather than copying these translations unchanged. ## Why does the animation stop while loading continues? The base style is static. Motion is enabled only when `prefers-reduced-motion: no-preference` matches; a reduced-motion preference leaves the centered segment and visible message intact. [MDN documents the media feature's values](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@media/prefers-reduced-motion). Even without that preference, three 1.2-second sweeps take `3 × 1.2 = 3.6` seconds, after which the base static style returns. This is a deliberate motion limit, not a task deadline. “Loading demo content...” remains until the Promise settles. Do not casually replace the iteration count with `infinite`. [WCAG 2.2, Success Criterion 2.2.2](https://www.w3.org/TR/WCAG22/#pause-stop-hide) requires a pause, stop or hide mechanism for moving information that starts automatically, lasts more than five seconds and appears alongside other content, unless the movement is essential. A reduced-motion query alone does not address every user's need to stop ongoing animation. ## Connect the line to a real state transition Put this script after the markup. Start creates a pending Promise. Finish fulfills it; Fail rejects it. There is no timer that declares success. ```js const start = document.querySelector("#line-start"); const finish = document.querySelector("#line-finish"); const fail = document.querySelector("#line-fail"); const visual = document.querySelector("#line-visual"); const statusText = document.querySelector("#line-status"); const results = document.querySelector("#line-results"); let pending = null; start.addEventListener("click", async () => { if (pending) return; start.disabled = true; visual.hidden = false; results.setAttribute("aria-busy", "true"); statusText.textContent = "Loading demo content..."; try { const text = await new Promise((resolve, reject) => { pending = { resolve, reject }; }); results.textContent = text; statusText.textContent = "Demo content loaded."; } catch { statusText.textContent = "Demo failed. Select Start demo to retry."; } finally { pending = null; visual.hidden = true; results.setAttribute("aria-busy", "false"); start.disabled = false; } }); finish.addEventListener("click", () => { pending?.resolve("New local demo content."); }); fail.addEventListener("click", () => { pending?.reject(new Error("Demonstration failure")); }); ``` The disabled Start button and pending guard allow one operation at a time. Finish or Fail while idle does nothing. Both terminal paths hide the line, clear busy state and permit another attempt. Failure leaves the previous content in place with an explicit error message. For production, replace the manually settled Promise with your actual operation and remove the demonstration outcome buttons. Handle its failure, timeout and cancellation explicitly. If the design allows overlapping requests, add cancellation or response-ownership logic before reusing this pattern; this single-flight demo does not implement concurrent requests. [MDN's Promise reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) explains fulfillment, rejection and why a Promise itself has no first-class cancellation protocol. ## What gets announced? The decorative line is `aria-hidden`. The existing status paragraph receives text changes; it is never recreated or hidden with the line. [WAI-ARIA 1.2](https://www.w3.org/TR/wai-aria-1.2/#status) gives `status` implicit polite live-region semantics. The explicit atomic attribute asks for the complete message. The busy attribute belongs on the updating results, not on an ancestor enclosing the status. Otherwise the loading announcement could be deferred with the content update. Do not also make the results a live region for the same message. [W3C technique ARIA22](https://www.w3.org/WAI/WCAG22/Techniques/aria/ARIA22) checks that the status container exists before the update. This script changes its text only at meaningful state transitions, not at every animation frame. That avoids generating repeated frame-by-frame status changes; it does not guarantee identical announcements across assistive technologies. See the fuller [accessible loading indicators guide](/accessible-loading-indicators/) for integration considerations. ## What should you test before shipping? This exact demonstration was executed in headless Microsoft Edge 152.0.4191.66. DOM and computed-style checks covered start, fulfillment, rejection, retry, one status mutation while advancing animation time, sweep endpoints and reduced-motion emulation at a narrow viewport. Those checks are not a screen-reader audit, physical-device benchmark or accessibility certification. Test your supported browsers, keyboard flow, screen readers, zoom, color themes and actual application states. Keep visible loading text legible; a static segment alone is ambiguous. Check that success and failure both remove the visual, and that a slow task remains accurately labeled after motion ends. Only `transform` changes during the sweep. [MDN's animation-performance guide](https://developer.mozilla.org/en-US/docs/Web/Performance/Guides/Animation_performance_and_frame_rate) explains why composited transforms can avoid layout and repaint work. That is not a smoothness guarantee: profile the real page on representative hardware, especially with multiple loaders. If completion is measurable, choose a labeled native `progress` element with values derived from the task. Without a value it is indeterminate, as [MDN explains](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/progress). Never derive a completion value from this decorative sweep. The [spinner recipes hub](/spinner-recipes/) collects other shape-specific patterns. ## Sources - [MDN: translateX](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/transform-function/translateX). - [MDN: prefers-reduced-motion](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@media/prefers-reduced-motion). - [WCAG 2.2: Pause, Stop, Hide](https://www.w3.org/TR/WCAG22/#pause-stop-hide). - [WAI-ARIA 1.2: status](https://www.w3.org/TR/wai-aria-1.2/#status) and [aria-busy](https://www.w3.org/TR/wai-aria-1.2/#aria-busy). - [W3C: technique ARIA22](https://www.w3.org/WAI/WCAG22/Techniques/aria/ARIA22). - [MDN: Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). - [MDN: animation performance](https://developer.mozilla.org/en-US/docs/Web/Performance/Guides/Animation_performance_and_frame_rate). - [MDN: progress element](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/progress). ## Frequently asked questions **Does a CSS line loader need JavaScript?** CSS can draw and animate the line, but it does not know whether an application operation is pending, successful or failed. JavaScript or framework state must connect those outcomes to the visual and status text. The recipe's local demonstration uses manually settled Promises to make those transitions inspectable. **Why does the moving segment use translateX(250%)?** In this recipe, percentage translation is relative to the moving segment's border box. The segment is 40% of its track, so translating it by 250% of its own width moves its left edge one full track width. Change the segment width and you must recalculate that endpoint. **Does the static bar mean loading has finished?** No. The example limits decorative motion to three 1.2-second sweeps, then keeps a centered static segment and visible loading text while work remains pending. Reduced-motion users receive the static state immediately. Only fulfillment or rejection of the actual operation should end its loading state. **Should a screen reader announce each sweep?** No. The sweep is decorative and does not represent a new application state. Keep it hidden from the accessibility tree and update a persistent status message only when meaningful state changes occur. Test actual announcement behavior with supported screen readers and browsers rather than assuming identical output everywhere. **Can I use the line's position as a progress percentage?** No. Its position follows an animation timeline, not completed work. Use measured task values for determinate progress, with appropriate labeling and semantics such as a native progress element. When the amount completed is unknown, keep the indicator indeterminate and describe what the application is doing. --- # CSS Loading Spinner: A Clean, Copyable Pattern > Create a CSS loading spinner with a square element, a circular border, one contrasting border side, and an infinite linear rotation using `transform`. Put the visual spinner inside a `role="status"` wrapper with descriptive text, mark the spinner itself `aria-hidden="true"`, and stop its animation inside `@media (prefers-reduced-motion: reduce)`. Application state must remove the indicator and announce success or failure when loading ends. Source: https://css-spinners.com/css-loading-spinner/ Publisher: The Loading Loop Published: 2026-07-19 Updated: 2026-08-25 ## A dependable CSS spinner needs two layers A clean CSS loading spinner can be made from one empty element with a circular border, one contrasting border segment, and a `transform: rotate()` animation. Mark that visual element `aria-hidden="true"` and pair it with real status text. The animation communicates activity visually; the text communicates the state to people who cannot see or comfortably watch it. Here is the complete pattern: ```html
Loading results…
``` ```css .loading { --spinner-size: 2rem; --spinner-width: 0.25rem; --spinner-track: #cbd5e1; --spinner-active: #1d4ed8; display: inline-flex; align-items: center; gap: 0.75rem; color: #0f172a; font: 600 1rem/1.4 system-ui, sans-serif; } .spinner { box-sizing: border-box; width: var(--spinner-size); height: var(--spinner-size); flex: 0 0 auto; border: var(--spinner-width) solid var(--spinner-track); border-top-color: var(--spinner-active); border-radius: 50%; animation: spinner-rotate 0.8s linear infinite; } @keyframes spinner-rotate { to { transform: rotate(1turn); } } @media (prefers-reduced-motion: reduce) { .spinner { animation: none; } } ``` Paste the HTML and CSS into a blank page and the ring will rotate beside “Loading results…”. Under a reduced-motion preference, it remains a static partial ring while the text continues carrying the meaning. ## How the spinner works The element has equal width and height, a full border, and `border-radius: 50%`, which creates a ring. Three sides use the quiet track color. `border-top-color` creates one contrasting segment. Rotation moves that segment around the ring. The keyframe needs only an ending state. The browser interpolates from the element's initial transform to one complete turn. `linear` keeps angular speed constant; `infinite` repeats until the loading element is removed. The `box-sizing: border-box` declaration keeps the declared width and height inclusive of the border. Without it, a project-wide box-sizing reset may still save you, but a standalone snippet should not rely on a kindly ancestor it has never met. `flex: 0 0 auto` prevents the spinner from shrinking in a tight flex container. The inline flex wrapper aligns the ring and text and gives them a predictable gap. ## Customize size, thickness, color, and speed Change the custom properties on `.loading`: ```css .loading--large { --spinner-size: 3rem; --spinner-width: 0.375rem; --spinner-track: #d1fae5; --spinner-active: #047857; } ``` ```html
Preparing preview…
``` Keep width and height equal. A thicker border creates a heavier ring but also leaves less open center. For a tiny spinner, reduce the border width along with overall size so it does not become a rotating poker chip. To change speed, edit the animation duration: ```css .spinner { animation-duration: 1.1s; } ``` A longer duration rotates more slowly. Avoid rapid, attention-demanding motion, especially when several indicators could appear at once. Timing should acknowledge the wait, not challenge the user to a staring contest. Check the active segment and track against every background on which the component appears. The active segment must remain distinguishable from the track, and the visible status text needs normal text contrast. A beautiful ring that disappears in dark mode is simply a circle with work-life balance. ## Why `transform` is the right property to animate This pattern animates `transform`, not `top`, `left`, width, margin, or border width. Properties that change geometry can trigger layout and paint work on every frame. Transforms and opacity can often be handled during compositing, though actual performance still depends on the page, browser, device, and number of animated elements. MDN's [animation performance guide](https://developer.mozilla.org/en-US/docs/Web/Performance/Guides/Animation_performance_and_frame_rate) lists `transform` and `opacity` as properties that can avoid layout and paint when handled in their own layer. That does not make unlimited animation free. Ten full-page overlays containing two hundred spinning nodes will find a way to become expensive. Do not add `will-change: transform` by reflex. Browsers can optimize animations, and persistent layer hints consume resources. Measure a real performance problem before applying a hint, then remove it when the animation is inactive if your implementation truly needs one. ## Make the status accessible The ring is decorative because it provides no information beyond the accompanying text. `aria-hidden="true"` keeps it out of the accessibility tree. The parent uses `role="status"`, which creates a polite live region, and `aria-atomic="true"` asks assistive technology to announce the complete updated message. The [W3C technique for `role="status"`](https://www.w3.org/WAI/WCAG21/Techniques/aria/ARIA22) recommends that the status container exist before the message update. In a dynamic application, render an empty status container with the page, then insert “Loading results…” when work begins. If you create both the live region and its already-filled message in one operation, announcements can be inconsistent across environments. Do not put `role="status"` on the spinning element while hiding that same element with ARIA. An element removed from the accessibility tree cannot also serve as the accessible message. Keep semantics on the wrapper or text. If sighted users do not need visible text, visually hide it rather than deleting it: ```css .visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; } ``` ```html
Loading results…
``` Visible status text is often better because everyone benefits from knowing what is happening. Hide it only when nearby interface context already makes the state unmistakable visually. ## Respect reduced-motion preferences The `prefers-reduced-motion: reduce` media query detects a user preference for reducing non-essential motion. In this pattern, the spinner stops but remains visually distinct, and the status text remains present. Do not hide the whole loading component in the media query. Reduced motion is not reduced information. Also avoid replacing rotation with a strong pulsing or scaling loop; that may be no more comfortable. The wider guide to [accessible loading indicators](/accessible-loading-indicators/) covers alternatives and state announcements. If your design needs a subtle active visual in reduced-motion mode, consider a static ring plus a text ellipsis that changes only when application state changes—not a perpetual animated ellipsis. ## Use truthful application state CSS can draw the spinner, but JavaScript or framework state must decide when it appears. A robust loading flow should: 1. Insert or reveal the indicator when the task begins. 2. Mark the affected content region `aria-busy="true"` when appropriate. 3. Update status text if the task meaningfully changes. 4. Remove or hide the indicator when the task succeeds or fails. 5. Set `aria-busy="false"` and move focus only when the user needs it. 6. Show an actionable error rather than spinning forever. Avoid flashing a spinner for near-instant work. A brief delay before showing it can prevent distracting flicker, while a separate threshold can introduce more detailed progress or a cancel option for longer operations. Choose timings from observed application behavior rather than copying a universal millisecond recipe. The spinner must not block the entire page unless the entire page truly cannot be used. For a loading card, place the indicator within that card and keep unrelated controls available. ## When to use another loading pattern Use this compact ring for an indeterminate wait where progress cannot be measured and the affected area is clear. Choose something else when: - **Several text or media blocks are taking shape:** a [CSS skeleton loader](/css-skeleton-loader/) can reserve the final layout. - **A short inline action is pending:** the [three-dot loader](/css-three-dot-loader/) can fit beside a label. - **Completion can be measured:** use a semantic `` element or an appropriately implemented progress bar with actual values. - **Nothing is happening:** show an empty state, not a loader. - **The request failed:** show the error and a retry path, not immortal rotation. ## Common spinner bugs ### The circle looks oval Check that width and height match and that flex or grid sizing is not stretching one axis. Keep `flex: 0 0 auto` on the ring. ### The animation does not run Confirm the keyframe name matches exactly, the stylesheet is loaded, and no later rule sets `animation: none`. A reduced-motion setting may be activating the intentional static state. ### The spinner changes layout when it appears Reserve its space or position it inside a container designed for loading state. If the text changes from a short button label to a wider message, size the control for both states. ### Screen readers announce nothing Ensure the status container exists before its text changes, is not `aria-hidden`, and contains a useful message. Test with the assistive technologies your project supports; semantic intent still deserves real-world verification. ### It never disappears That is not a CSS defect. Tie visibility to success and error handling, and include timeout or retry behavior appropriate to the task. The most accessible animation in the world cannot compensate for a promise that never resolves. The finished component is deliberately modest: one visual span, one text span, one transform animation, and one reduced-motion rule. Good loading feedback should make waiting legible, then get off the stage. ## Frequently asked questions **How do you make a circle spinner in CSS?** Give an element equal width and height, a solid border, and `border-radius: 50%`. Change one border side to a contrasting color, then animate `transform: rotate(1turn)` with a linear infinite animation. Use `box-sizing: border-box` so the declared dimensions include the border thickness. **Should a CSS spinner have an ARIA label?** Treat the moving shape as decorative with `aria-hidden="true"` and provide actual status text in a `role="status"` container. Text such as “Loading results…” is clearer than naming a decorative span “spinner.” For reliable dynamic announcements, place the live-region container in the document before inserting or updating its message. **How do I stop a spinner for reduced motion?** Add `@media (prefers-reduced-motion: reduce)` and set the spinner's `animation` to `none`. Keep the static ring and status text visible so the loading state remains understandable. Do not replace rotation with aggressive pulsing or scaling, and do not hide the entire indicator merely because motion is reduced. **Is animating CSS transform better than top or left?** Animating `transform` avoids changing document geometry and can often be handled during compositing, while animating `top`, `left`, width, or margin can trigger layout and painting work. Actual performance depends on the browser, page, device, and number of elements, so measure real interactions instead of assuming any animation is free. **Why is my CSS spinner oval?** Its width and height may differ, or a flex or grid container may be stretching it. Set equal dimensions, `box-sizing: border-box`, and `flex: 0 0 auto`. Also inspect project-wide rules affecting spans, borders, or aspect ratio. The border-radius creates a circle only when the rendered box remains square. **When should a loading spinner disappear?** Remove or hide it as soon as the associated task succeeds or fails. On success, reveal the content and clear any busy state. On failure, show an actionable error or retry control rather than continuing to spin. Longer tasks may need measurable progress, a cancel option, or more specific status updates. --- # CSS Skeleton Loader Without Layout Shift > Build a CSS skeleton loader on the same grid as the final component, reserving media with `aspect-ratio` and text regions with realistic minimum dimensions. Hide stand-in shapes from assistive technology, mark the updating region `aria-busy="true"`, and provide a separate status message. For optional shimmer, move a pseudo-element with `transform`; stop the animation under `prefers-reduced-motion` and replace the skeleton on success or error. Source: https://css-spinners.com/css-skeleton-loader/ Publisher: The Loading Loop Published: 2026-07-19 Updated: 2026-08-25 ## A skeleton should reserve the content's real shape A CSS skeleton loader is a temporary visual stand-in whose boxes match the dimensions of incoming content. Build the stand-in and final component on the same grid, reserve media with `aspect-ratio`, give text regions predictable minimum heights, hide decorative skeleton shapes from assistive technology, and expose a separate loading status. Animate a pseudo-element with `transform` for optional shimmer, then disable it for reduced motion. The pattern below creates a card whose loading and loaded states occupy the same basic footprint. ## Complete HTML for loading and loaded states Show only one card state at a time. The first is the loading state: ```html

Loading article preview…

``` When data arrives, replace it with the final content and clear the busy state: ```html
Curving gravel path through a green garden

Garden Design

How to Plan a Garden Path

Choose a useful route, comfortable width, and surface that suits the site.

``` In a real application, preserve the live-region container outside the replaced subtree if you need it to announce both loading and completion reliably. The example keeps the state markup readable; your framework should update DOM and focus according to the interaction. ## Complete CSS ```css .card { --card-radius: 0.75rem; --skeleton-base: #e2e8f0; --skeleton-highlight: rgba(255, 255, 255, 0.65); display: grid; grid-template-rows: auto 1fr; width: min(100%, 22rem); overflow: hidden; border: 1px solid #cbd5e1; border-radius: var(--card-radius); background: #ffffff; color: #0f172a; font-family: system-ui, sans-serif; } .card__media { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: var(--skeleton-base); } .card__body { min-height: 10rem; padding: 1rem; } .card__eyebrow { margin: 0 0 0.5rem; color: #475569; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; } .card__title { min-height: 2.5em; margin: 0 0 0.75rem; font-size: 1.25rem; line-height: 1.25; } .card__summary { margin: 0; color: #334155; line-height: 1.5; } .skeleton { position: relative; overflow: hidden; border-radius: 0.375rem; background: var(--skeleton-base); } .skeleton::after { position: absolute; inset: 0; background: linear-gradient( 90deg, transparent, var(--skeleton-highlight), transparent ); content: ""; transform: translateX(-100%); animation: skeleton-shimmer 1.5s ease-in-out infinite; } .skeleton--eyebrow { width: 35%; height: 0.75rem; margin-bottom: 0.75rem; } .skeleton--title { width: 88%; height: 1.25rem; margin-bottom: 1rem; } .skeleton--line { width: 100%; height: 0.875rem; margin-bottom: 0.625rem; } .skeleton--line-short { width: 68%; } .visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; } @keyframes skeleton-shimmer { to { transform: translateX(100%); } } @media (prefers-reduced-motion: reduce) { .skeleton::after { animation: none; transform: none; } } ``` The loading card uses the same `.card`, `.card__media`, and `.card__body` geometry as the final card. The skeleton utility adds the stand-in fill and optional highlight. ## Why this reduces layout shift Layout shift occurs when visible content moves because the browser learns a missing size or the replacement content occupies different space. A skeleton helps only if it reserves dimensions close to the final component. The image has three safeguards: 1. Both states use `.card__media`. 2. CSS reserves a `16 / 9` aspect ratio. 3. The final `` includes intrinsic `width="800"` and `height="450"`, which express the same ratio because `800 ÷ 450 = 16 ÷ 9`. The body uses the same padding and a `min-height` of 10rem in both states. The title reserves at least 2.5em, which is two lines at `line-height: 1.25`: `2 × 1.25em = 2.5em`. Those choices do not guarantee zero shift. A three-line title, translated text, larger user font settings, or different final controls may require more space. Design skeletons from actual component variants, not from the shortest English card in the mockup. ## Do not copy the text too literally A skeleton should suggest structure without pretending to know the exact incoming sentence. Use a few varied bars, not one rectangle for every line of eventual copy. Dense shimmering paragraphs add visual noise and can make a wait feel longer. Match stable component regions: - Media ratio - Title area - Summary area - Avatar or icon footprint - Fixed controls that will actually appear Do not skeletonize interface elements that are already available. If a card's menu can function before its content loads, consider keeping the real control rather than replacing it with inert gray confetti. ## Make skeletons invisible to the accessibility tree The stand-in shapes contain no content, so the example hides them with `aria-hidden="true"`. The article carries `aria-busy="true"`, signaling that the region is being updated, and a separate `role="status"` message announces the wait. When content arrives: - Replace the stand-in with semantic content. - Set `aria-busy="false"` or remove the attribute. - Update a persistent status region with a completion message only if that announcement helps. - Keep keyboard focus where the interaction requires; do not move it merely because data arrived. Do not put fake headings, empty buttons, or meaningless image alt text inside a skeleton. Assistive technology should encounter the status, then the real content—not tour a museum of unnamed rectangles. The full [accessible loading indicators guide](/accessible-loading-indicators/) explains the differences between status, busy, and progress semantics. ## Keep the shimmer restrained The shimmer uses an absolutely positioned pseudo-element, so it does not affect layout. Its transform moves the highlight across the already-painted base. MDN's performance guidance notes that transforms and opacity can often be handled in composition rather than triggering layout; still, many large animated skeletons can consume CPU or GPU time. Consider these limits: - Animate only skeletons currently visible. - Stop and remove them when the request completes or fails. - Avoid stacking several animated gradients on each stand-in. - Test a full realistic list on lower-powered devices. - Prefer a static stand-in when motion adds no useful reassurance. The reduced-motion rule stops shimmer and leaves the base shapes visible. This preserves layout and state without perpetual movement. A static skeleton is still a skeleton; it has not lost its professional license. ## Responsive skeleton layouts If the final component changes at a breakpoint, change the skeleton through the same layout rules. For example: ```css @media (min-width: 48rem) { .card--horizontal { grid-template-columns: 10rem 1fr; grid-template-rows: 1fr; width: min(100%, 36rem); } .card--horizontal .card__media { height: 100%; aspect-ratio: auto; } } ``` Apply `card--horizontal` to both loading and final cards. The grid change then affects the stand-in and content equally. Test the loaded image's crop with `object-fit: cover`; geometry can match while the chosen photograph still loses its subject at a narrow crop. ## Skeleton, spinner, or progress bar? Choose feedback based on the task: | Situation | Better pattern | Reason | |---|---|---| | Content card or feed is taking shape | Skeleton | Reserves expected layout | | Small indeterminate action | [CSS spinner](/css-loading-spinner/) | Compact acknowledgment | | Inline conversational wait | [Three-dot loader](/css-three-dot-loader/) | Fits text rhythm | | Known amount completed | Native or ARIA progress bar | Communicates actual progress | | Empty result | Empty state | Nothing is loading | | Failed request | Error and recovery action | Spinning would be false feedback | A skeleton is most useful when the content structure is predictable and the wait is noticeable. For a button action that finishes almost immediately, swapping the whole page into gray scaffolding is theatrical overreach. ## Common skeleton mistakes ### The final content is taller Test long titles, localization, large text, optional badges, and error states. Use flexible minimum sizes rather than fixed heights where content can legitimately grow. ### Images still cause a jump Give the final image intrinsic `width` and `height` attributes and a matching CSS aspect ratio. Ensure loading and final states share the same grid placement. ### Screen readers encounter blank content Hide decorative shapes, expose a meaningful status, and mark the updating region busy. Verify that real content enters the accessibility tree when loading completes. ### Shimmer looks jerky Animate transform rather than background position, reduce the number of simultaneous skeletons, and profile the real page. A static reduced-motion state should also be available. ### The loader remains after an error Replace it with an error message and a retry or alternative action. A skeleton forecasts content; after failure, continuing the forecast becomes misinformation. The best skeleton is an honest floor plan of the component that is coming. It reserves space, reports the wait, respects motion preferences, and vanishes cleanly when the real tenant arrives. ## Verify the swap with real data Run the component with the shortest title, the longest plausible title, missing optional media, translated copy, and increased text size. Record loading and loaded dimensions in developer tools; compare the card's top, bottom, and media box before and after replacement. Also throttle the request, force an error, and confirm the stand-in becomes useful error content rather than an abandoned construction site. Test keyboard and screen-reader behavior across the swap. No stand-in should receive focus, the busy state must clear, and newly loaded links should enter the normal tab order exactly once. Visual stability and semantic stability are separate checks, and the component needs both. ## Frequently asked questions **What is a CSS skeleton loader?** A skeleton loader is a temporary set of simple shapes that previews the layout of content still loading. It is useful for predictable cards, lists, and media areas. A good skeleton reserves nearly the same dimensions as the final content, remains decorative to assistive technology, and is paired with truthful loading status. **How does a skeleton loader prevent layout shift?** It reserves the final component's space before data and media arrive. Use the same grid, padding, media ratio, and realistic text-area minimums in loading and loaded states. Add intrinsic width and height to final images. Test long titles, localization, large text, optional controls, and errors because one ideal card cannot represent every variant. **Should skeleton loaders use ARIA labels?** Do not label every gray bar. Hide decorative skeleton shapes with `aria-hidden="true"`, mark the content region `aria-busy="true"`, and expose one useful status such as “Loading article previews…” in a live region. When content arrives, clear the busy state and ensure the real semantic content replaces the stand-ins. **How do I make a skeleton shimmer in CSS?** Place an absolutely positioned pseudo-element over the base skeleton, give it a transparent-to-light gradient, and animate `transform: translateX()` from one side to the other. Keep the parent positioned and clipped with `overflow: hidden`. Use a static base for reduced motion and test performance with the real number of visible stand-ins. **Are skeleton screens better than spinners?** They serve different situations. Skeletons are useful when the incoming layout is predictable and reserving its shape reduces visual movement. Spinners suit compact indeterminate actions whose final structure is already present. Use a progress bar when completion is measurable, an empty state when no content exists, and an error when the request fails. **Why does my page still shift after using a skeleton?** The stand-in likely does not match a real variant. Common causes include missing image dimensions, a different grid, fixed stand-in heights, long or translated text, large user font settings, badges, and late controls. Compare computed loading and loaded dimensions across realistic data, then share layout classes and reserve flexible minimum space. --- # CSS Spinner Examples: Five Copyable Loaders > The most useful CSS spinner examples are a ring for general waits, a sliding line for page or panel loading, three dots beside compact text, a pulse for quiet background work, and a progress bar when the application knows a real percentage. Each example here uses minimal markup and animates transform or opacity. Add visible or screen-reader status text, then stop or replace decorative motion for people who prefer reduced motion. Source: https://css-spinners.com/css-spinner-examples-library/ Publisher: The Loading Loop Published: 2026-09-05 Updated: 2026-09-07 ## Five CSS spinner examples you can copy If you need a loader today, pick the shape that matches what the interface actually knows. Use a ring, dots, or a pulse for an indeterminate wait: the task is running, but there is no trustworthy percentage. Use a real progress bar when the application can calculate completion. A sliding line works well in a narrow page or form header. The five patterns below use valid HTML and CSS, animate only `transform` and `opacity`, and include one shared accessibility layer. Here is the short version: | Pattern | Best for | What it communicates | |---|---|---| | Ring | General-purpose waits | Work is continuing | | Sliding line | Page or panel refresh | A section is loading | | Three dots | Messages and compact controls | A short response is pending | | Pulse | Quiet background work | Activity without urgency | | Progress bar | Uploads, imports, multi-step jobs | A measured fraction is complete | When you are unsure, use the ring. It is familiar, compact, and does not pretend to know how long the task will take. ## Use one accessible loading wrapper The animation is decoration. The status message carries the meaning. Start with this wrapper and put one of the visual patterns inside it: ```html
Loading results...
``` ```css .loading-indicator { display: inline-flex; align-items: center; gap: 0.625rem; } .visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; } ``` The `aria-hidden="true"` attribute keeps the decorative shape out of the accessibility tree. The text remains available to screen readers. Under [WAI-ARIA 1.2](https://www.w3.org/TR/wai-aria/#status), `role="status"` has implicit polite live-region behavior, so a status can be announced without moving focus. Do not repeatedly replace the text on every animation frame. If a particular content region is being updated, set `aria-busy="true"` on that region while the update is in progress, then restore `aria-busy="false"` when the update is complete. The ARIA specification explains that assistive technology may hold changes while a region is busy and expose them together after it becomes available. The site’s [accessible loading indicators guide](/accessible-loading-indicators/) covers the full state-management pattern. ## Example 1: a dependable ring spinner This is the useful default: one element, one animation, and three variables you can change without rebuilding it. ```html ``` ```css .loader-ring { --loader-size: 2rem; --loader-width: 0.25rem; --loader-color: #2563eb; display: inline-block; width: var(--loader-size); aspect-ratio: 1; border: var(--loader-width) solid #dbeafe; border-top-color: var(--loader-color); border-radius: 50%; animation: ring-turn 0.8s linear infinite; } @keyframes ring-turn { to { transform: rotate(1turn); } } ``` The pale border draws the full track. The differently coloured top edge becomes the moving arc when the element rotates. Change `--loader-size` for the diameter, `--loader-width` for thickness, and `--loader-color` for the active arc. Keep the border width comfortably below half the radius; otherwise the centre closes and the spinner becomes a disc. The `aspect-ratio: 1` declaration keeps the box square when the size changes. For a deeper explanation of alignment, border construction, and stopping the element, use the [single-ring CSS loading spinner recipe](/css-loading-spinner/). ## Example 2: a sliding line loader A line loader fits the top of a page, a table, or the edge of a form panel. The track clips a shorter bar while that bar travels across it. ```html ``` ```css .loader-line { display: block; position: relative; width: min(24rem, 100%); height: 0.25rem; overflow: hidden; border-radius: 999px; background: #dbeafe; } .loader-line::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 40%; border-radius: inherit; background: #2563eb; animation: line-sweep 1.1s ease-in-out infinite; } @keyframes line-sweep { from { transform: translateX(-110%); } to { transform: translateX(360%); } } ``` Why `360%`? Percentage translation is based on the moving bar’s own width. The bar is 40% as wide as the track, so it needs to travel several of its own widths to clear the far edge. The track’s `overflow: hidden` removes the bar before and after each pass. This remains indeterminate. The sweep means “still working,” not “40% complete.” Do not use the moving bar’s position as a percentage. If the application has measured progress, use the final example instead. ## Example 3: three staggered dots Dots work neatly beside “Sending” or “Checking” because they occupy little horizontal space. Use three identical spans and stagger the same animation with delays. ```html ``` ```css .loader-dots { display: inline-flex; align-items: center; gap: 0.3rem; } .loader-dots > span { width: 0.5rem; aspect-ratio: 1; border-radius: 50%; background: #2563eb; animation: dot-lift 0.9s ease-in-out infinite alternate; } .loader-dots > span:nth-child(2) { animation-delay: 0.15s; } .loader-dots > span:nth-child(3) { animation-delay: 0.3s; } @keyframes dot-lift { from { transform: translateY(0); opacity: 0.45; } to { transform: translateY(-0.35rem); opacity: 1; } } ``` The dots share duration and easing. Only the delays differ, which creates the sequence. Keep the vertical movement small enough that the loader does not change the line box or collide with nearby text. The transform changes what is drawn without moving surrounding layout. For variations that use a static centre line, different timing, or a single reusable class, see the [three-dot loader recipe](/css-three-dot-loader/). ## Example 4: a quiet pulse A pulse is useful when rotation feels too prominent: background synchronisation, a compact toolbar state, or a wait that should stay visible without taking over the page. ```html ``` ```css .loader-pulse { display: inline-block; width: 1rem; aspect-ratio: 1; border-radius: 50%; background: #2563eb; animation: pulse-softly 1.4s ease-in-out infinite; } @keyframes pulse-softly { 0%, 100% { transform: scale(0.8); opacity: 0.45; } 50% { transform: scale(1); opacity: 1; } } ``` The long duration and `ease-in-out` timing avoid a sharp visual jump. Both endpoints match, so the loop joins cleanly. Scaling from 0.8 to 1 keeps the pulse restrained; large repeated zooms are harder to ignore and may be uncomfortable. A pulse is deliberately less assertive than a ring. Do not use that subtlety where a blocked form or payment action needs an unmistakable state, and never rely on the dot alone. Keep the status text in the shared wrapper. ## Example 5: a measured progress bar Use this only when your application knows the completed fraction. The bar below starts at 65%. Its visual fill and accessible value must be updated together. ```html
``` ```css .loader-progress { width: min(24rem, 100%); height: 0.625rem; overflow: hidden; border-radius: 999px; background: #dbeafe; } .loader-progress__fill { display: block; width: 100%; height: 100%; border-radius: inherit; background: #2563eb; transform: scaleX(var(--progress)); transform-origin: left; transition: transform 180ms ease-out; } ``` Scaling a full-width fill avoids repeatedly changing its layout width. A value of `0.65` gives a 65% scale from the left edge. In JavaScript, clamp the fraction between 0 and 1, set `--progress` to that fraction, and set `aria-valuenow` to the corresponding number between 0 and 100. If the total is unknown, do not invent a percentage; use the line, ring, dots, or pulse. The native HTML `progress` element is also a good first choice when its semantics and available styling fit the design. Native elements should be preferred when they already provide the required meaning; WAI-ARIA explicitly advises using host-language semantics where an equivalent feature exists. ## Why these examples animate transform and opacity Each repeating recipe changes `transform`, `opacity`, or both. The progress bar transitions `transform`. This is a sound default because animation cost depends on the property being changed. MDN’s [animation performance guide](https://developer.mozilla.org/en-US/docs/Web/Performance/Guides/Animation_performance_and_frame_rate) separates style, layout, paint, and composition work and warns that expensive properties can produce uneven motion. That does not guarantee perfect performance. The number and size of animated elements, effects, other page work, device, and browser still matter. Test on an ordinary low-powered device with the real page loaded. Do not add `will-change` automatically; [MDN describes it as a last resort](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/will-change) because overuse can consume resources and make performance worse. ## Add reduced-motion behavior once The `prefers-reduced-motion` media feature detects a user request to reduce non-essential motion. MDN documents broad browser availability and explains that the reduced rule can remove, reduce, or replace motion. For this library, stop the decorative loops and leave a visible static indicator: ```css @media (prefers-reduced-motion: reduce) { .loader-ring, .loader-line::before, .loader-dots > span, .loader-pulse { animation: none; } .loader-ring { border-top-color: #2563eb; } .loader-line::before { transform: translateX(75%); } .loader-dots > span, .loader-pulse { transform: none; opacity: 1; } .loader-progress__fill { transition: none; } } ``` The loading state does not disappear: the static shape and status text remain. Test the page with the operating system’s reduced-motion setting both on and off. Also test keyboard flow and a screen reader while the status begins, changes, finishes, and fails. A loader that spins correctly but never announces completion is not finished. ## How to choose without overthinking it Use a ring for the default, a line when the container is wide and shallow, dots near conversational text, and a pulse for low-emphasis background activity. Use progress only with a real value. Keep one visual language across the product: matching colour, stroke weight, speed, status wording, and reduced-motion treatment does more for polish than adding a sixth shape. Remove the loader when work completes, update the controlled content, clear its busy state, and expose a useful success or error message when the outcome is not already obvious. The animation is only the visible middle of that sequence. ## Check the whole loading lifecycle A copied loader is ready only after its start and finish behavior works. Before the request begins, the content region should be usable and not marked busy. When work starts, show the status, mark the affected region busy, and prevent only actions that would genuinely conflict with the request. A page-wide overlay for a small card refresh blocks too much. On success, render the new content, clear the busy state, and remove the loading status. On failure, replace “Loading” with a useful error and recovery action; an endless spinner is not an error message. If the request can time out, the interface, not the CSS animation, must decide when to stop waiting. Also test what happens when two requests overlap, a response returns immediately, the network is slow, the component is removed before the response arrives, or JavaScript fails. A very fast response can make a spinner flash distractingly, so a product may choose a short display delay. That timing belongs in application logic and should never delay the actual result. The CSS recipes simply render the state they are given. ## Frequently asked questions **What is the simplest CSS loading spinner?** A one-element border ring is the simplest dependable spinner. Give a square element a circular border, change one border edge to the active colour, and rotate it with a CSS keyframe. Put the decorative ring inside a status wrapper with readable text. The ring shows ongoing work; it does not claim to show how much work is complete. **Should a loader use a spinner or progress bar?** Use a spinner, dots, pulse or sliding line when the duration or total work is unknown. Use a progress bar only when the application can calculate a meaningful completed fraction. Keep its visual value and accessible value synchronized. An animated bar that sweeps across a track is still indeterminate and should not be presented as a percentage. **Which CSS properties are best for loader animation?** Transform and opacity are strong defaults because they can avoid repeated layout work, although performance still depends on element size, effects, page activity, device and browser. Test the real interface on a low-powered device. Do not add will-change automatically: browser guidance treats it as a last-resort hint for a demonstrated performance problem. **Does a CSS spinner need ARIA?** The decorative shape should usually be hidden from the accessibility tree, while the loading state is conveyed by text and appropriate semantics. A status role can announce a polite update; aria-busy can mark the region being updated. For measured progress, use the native progress element or keep the progressbar value synchronized with the visual fill. **How do I support prefers-reduced-motion in a loader?** Add a prefers-reduced-motion media query that stops, reduces or replaces repeating decorative movement. Leave a visible static shape and the loading text so the state does not vanish. Remove transitions from measured progress if necessary. Test with the operating system preference enabled and disabled, and confirm that start, completion and failure remain understandable without animation. --- # CSS Three-Dot Loader With Smooth Staggered Motion > Build a CSS three-dot loader with three equal circular spans sharing one keyframe animation. Animate `transform: translateY()` and `opacity`, then apply increasing `animation-delay` values to the second and third dots for a traveling wave. Mark the dots `aria-hidden="true"`, place descriptive text in a `role="status"` container, and stop the animation when `prefers-reduced-motion: reduce` matches. Source: https://css-spinners.com/css-three-dot-loader/ Publisher: The Loading Loop Published: 2026-07-19 Updated: 2026-08-25 ## Three dots need one animation and three delays A CSS three-dot loader uses three equal circles running the same keyframe with staggered `animation-delay` values. Animate `transform: translateY()` and `opacity` so the dots rise in sequence without changing layout. Keep the dots decorative, add a real text status, and replace the loop with a static state when the user prefers reduced motion. This complete example creates a compact wave: ```html
Sending message
``` ```css .dot-loader { --dot-size: 0.5rem; --dot-color: #4338ca; --dot-gap: 0.3rem; display: inline-flex; align-items: baseline; gap: 0.5rem; color: #111827; font: 600 1rem/1.4 system-ui, sans-serif; } .dot-loader__dots { display: inline-flex; align-items: center; gap: var(--dot-gap); min-height: calc(var(--dot-size) * 2.4); } .dot-loader__dot { width: var(--dot-size); height: var(--dot-size); flex: 0 0 auto; border-radius: 50%; background: var(--dot-color); opacity: 0.35; animation: dot-wave 0.9s ease-in-out infinite; } .dot-loader__dot:nth-child(2) { animation-delay: 0.15s; } .dot-loader__dot:nth-child(3) { animation-delay: 0.3s; } @keyframes dot-wave { 0%, 60%, 100% { transform: translateY(0); opacity: 0.35; } 30% { transform: translateY(calc(var(--dot-size) * -0.7)); opacity: 1; } } @media (prefers-reduced-motion: reduce) { .dot-loader .dot-loader__dots .dot-loader__dot { animation: none; opacity: 0.75; } } ``` The three nested dot spans share one rule. Only their delays differ. The wrapper reserves 2.4 times the dot height. With a centered 0.5rem dot, the 1.2rem box leaves 0.35rem above it, matching the 0.35rem upward travel. Transforms do not change the element's layout box, so that reserved room prevents clipping or overlap. ## Why the stagger works Each dot follows a 0.9-second cycle. The first begins immediately, the second 0.15 seconds later, and the third 0.3 seconds later. Since the animation repeats forever, those offsets create a traveling wave. At 0%, 60%, and 100%, a dot rests at its original position with lower opacity. At 30%, it moves upward by 70% of its own diameter and becomes fully opaque. Repeating the resting state across the latter part of the timeline creates breathing room before the next cycle. The arithmetic of the start delays is straightforward: - Dot 1: `0s` - Dot 2: `1 × 0.15s = 0.15s` - Dot 3: `2 × 0.15s = 0.3s` The delay does not make the whole component 0.3 seconds slower. It offsets each dot within a continuous loop. ## Customize without breaking the rhythm Size, gap, and color live in custom properties: ```css .dot-loader--quiet { --dot-size: 0.375rem; --dot-gap: 0.25rem; --dot-color: #475569; } ``` To slow the pattern, change all dots through the shared rule: ```css .dot-loader--slow .dot-loader__dot { animation-duration: 1.2s; } .dot-loader--slow .dot-loader__dot:nth-child(2) { animation-delay: 0.2s; } .dot-loader--slow .dot-loader__dot:nth-child(3) { animation-delay: 0.4s; } ``` Here the delay step is one-sixth of the duration: `1.2s ÷ 6 = 0.2s`. Keeping delays proportional preserves a similar cadence. You can choose another rhythm, but adjust it intentionally rather than tuning decimals by vibes. For an in-place fade instead of a bounce, remove the transform change and animate only opacity: ```css @keyframes dot-fade { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } } .dot-loader--fade .dot-loader__dot { animation-name: dot-fade; } ``` That variant creates no spatial motion; only opacity changes. The reduced-motion selector in the complete example has three class selectors, specificity `(0,3,0)`, while the fade variant has two, `(0,2,0)`. The reduced-motion rule therefore wins on specificity. Source order breaks ties only when competing declarations have equal cascade weight and specificity. ## Use spans, pseudo-elements, or a background? Three spans are deliberately boring and maintainable. They make per-dot delays obvious and allow the dots to inherit component variables. A wrapper, one child, and two pseudo-elements can still animate three independent dots. The pseudo-elements become the outer dots; the child becomes the middle dot: ```html ``` ```css .dot-loader__pseudo { --dot-size: 0.5rem; display: inline-flex; gap: 0.3rem; } .dot-loader__pseudo::before, .dot-loader__pseudo::after, .dot-loader__pseudo > span { width: var(--dot-size); height: var(--dot-size); border-radius: 50%; background: currentColor; animation: dot-wave 0.9s ease-in-out infinite; } .dot-loader__pseudo::before, .dot-loader__pseudo::after { content: ""; } .dot-loader__pseudo > span { animation-delay: 0.15s; } .dot-loader__pseudo::after { animation-delay: 0.3s; } ``` This saves two child elements, but the relationship between visual order and selector order is less obvious than three spans. A box-shadow trick can draw all three circles from one element, yet a single shadow list cannot give each circle an independent animation delay. Use it for a static reduced-motion mark, not for this staggered wave. Choose the smallest code that your team can understand. DOM minimalism is not a competitive sport. Three decorative spans do not burden a normal interface, while a clever one-element construction can burden the next person who must change its timing. ## Keep status meaning outside the animation The dot group has `aria-hidden="true"` because its shapes do not identify what is happening. The parent `role="status"` contains “Sending message,” which assistive technology can announce as a polite update. Use a message specific to the action: - “Loading comments…” - “Saving changes…” - “Uploading photo…” - “Checking availability…” Avoid a bare “Please wait” when the interface can say what it is doing. If the task fails, replace the loading message with the error and a recovery path. A timeout still needs an error state and a recovery action; the dots cannot negotiate with the server. For a dynamically inserted message, keep the live-region container present before updating its contents. The broader [accessible loading indicators guide](/accessible-loading-indicators/) explains live-region timing, `aria-busy`, and progress semantics. ## Hide the label visually only when context is strong An inline “Sending message” label is useful to everyone. If a button already reads “Send” and changes to a dot indicator within the same stable control, you may visually hide a fuller status message: ```html
Sending message…
``` Use your project's tested visually-hidden utility. Do not use `display: none` or the `hidden` attribute on the status text because that removes it from visual display and the accessibility tree. Keep the button's width stable between idle and loading states. Replacing a wide label with three narrow dots can make adjacent controls jump. Reserve width with component sizing or keep the original label visibly present. ## Reduced motion should preserve the state MDN documents [`prefers-reduced-motion`](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion) as a media feature for detecting a user request to remove, reduce, or replace non-essential motion. The snippet stops the wave and leaves three moderately opaque dots beside the label. Another valid reduced-motion design is to hide the decorative dots while retaining visible text: ```css @media (prefers-reduced-motion: reduce) { .dot-loader__dots { display: none; } } ``` Use one approach, not both. A static dot group preserves the component's visual footprint; hiding it reduces decoration further. Neither should remove the status message. ## Performance: keep the animation local The wave animates `transform` and `opacity`, which avoid geometry changes and can often be composed efficiently. The moving dots still consume resources, especially when repeated across many list items or left running in a background tab. Render an indicator only for work that is actually pending. Remove it when complete, cancel its task when the associated view disappears, and avoid placing separate infinite loaders on every stand-in if one container-level status is enough. If a grid of content needs its final shape reserved, use a [skeleton loader](/css-skeleton-loader/) with restrained animation rather than dozens of independent dot groups. If a compact circular signal better matches the interface, use the [border-based CSS spinner](/css-loading-spinner/). ## Common three-dot problems ### All dots move together Confirm the `:nth-child()` selectors target the dot spans and that later CSS has not overwritten `animation-delay`. The spans must be siblings inside the dots wrapper. ### The dots are clipped An ancestor may use `overflow: hidden`, or the wrapper may not reserve vertical room. Keep the `min-height` in the example and inspect nearby line-height and clipping rules. ### The baseline looks awkward Try `align-items: center` on `.dot-loader` if the label's font and dot size do not sit comfortably with `baseline`. Visual alignment is font-dependent. ### A global span rule changes the circles Component class selectors should win over broad element rules, but inspect inherited display, border, and transform declarations. Encapsulated class names reduce collisions. ### The message is announced repeatedly Do not rewrite identical live-region text on every animation cycle. CSS motion should never drive status announcements. Update text only when application state meaningfully changes. A three-dot loader earns its place by being quiet, specific, and temporary. The stagger gives it personality; the text gives it meaning; the application gives it an ending. ## A quick browser test before shipping Test the component at normal and 200% page zoom, beside both short and long translated labels, and inside the narrowest container where it can appear. Toggle the operating system's reduced-motion preference while the page is open and confirm the loop stops. In developer tools, inspect all three dots: their computed delays should be `0s`, `0.15s`, and `0.3s` in the base version. Finally, slow the associated network request and force it to succeed, fail, and be cancelled. The status should announce once when the state changes, the dots should disappear in every terminal state, and the surrounding layout should not jump. A loader tested only in eternal loading has passed the least interesting third of its exam. ## Frequently asked questions **How do I stagger three dots in CSS?** Apply the same animation to all three sibling dots, then set increasing delays with `:nth-child()`. For a 0.15-second step, the first uses zero delay, the second `0.15s`, and the third `0.3s`. Because the animation repeats, these offsets create a continuous sequence rather than delaying the whole loader. **Which properties should a dot loader animate?** Use `transform` for movement and `opacity` for emphasis. They do not alter document geometry and can often be handled efficiently during compositing. Avoid animating margin, top, width, or other layout-affecting properties for the bounce. Performance still depends on the number of animations, page complexity, browser, and device. **Do animated loading dots need text?** Yes, when they communicate application state. The shapes do not explain what is loading, saving, or sending. Hide the dots from assistive technology and provide a specific status message in a live region. Keep the text visible when useful; if visually hidden, use a tested utility rather than `display: none`. **How should a dot loader handle reduced motion?** Inside `@media (prefers-reduced-motion: reduce)`, set the dots' animation to `none` and leave them static, or hide only the decorative dot group. Preserve the visible or assistive status text in either case. Avoid swapping the bounce for another continuous scale, pan, or strong pulse that may remain uncomfortable. **Why do all my loading dots animate at once?** The delay selectors may not match the actual sibling dots, or a later shorthand `animation` rule may reset `animation-delay`. Confirm the three dot elements share one parent, inspect the computed styles for the second and third children, and place delay rules after the shared animation shorthand if specificity is equal. **Can I make a three-dot loader with one HTML element?** Not with three independently timed dots and no generated content. A wrapper can create the outer dots with `::before` and `::after` while one child supplies the middle dot. Box shadows can draw three circles from one element, but independently staggering those painted shadows is awkward. Prefer the version your team can test and maintain. ---