CSS Loading Overlay
A frosted overlay with a spinner that covers any card or section while it has aria-busy set.
<section class="overlay-panel" aria-busy="true">
<h3>Monthly report</h3>
<p>Revenue grew 12% compared with last month, led by annual plans.</p>
<div class="loading-overlay" role="status" aria-label="Loading"></div>
</section>
.overlay-panel {
position: relative;
width: min(100%, 280px);
padding: 20px;
border-radius: 16px;
background: #fff;
color: #334155;
font: 15px/1.5 system-ui, sans-serif;
box-shadow: 0 4px 16px #0f172a14;
}
.overlay-panel h3 {
margin: 0 0 6px;
color: #0f172a;
font-size: 17px;
}
.overlay-panel p {
margin: 0;
}
.loading-overlay {
position: absolute;
inset: 0;
display: none;
place-items: center;
border-radius: inherit;
background: #ffffffa6;
-webkit-backdrop-filter: blur(3px);
backdrop-filter: blur(3px);
}
/* Show the overlay only while the section is busy */
[aria-busy="true"] > .loading-overlay {
display: grid;
}
.loading-overlay::after {
content: "";
width: 32px;
height: 32px;
border: 3px solid #cbd5e1;
border-top-color: #4f46e5;
border-radius: 50%;
animation: loading-overlay-spin 0.8s linear infinite;
}
@keyframes loading-overlay-spin {
to { transform: rotate(1turn); }
}
@media (prefers-reduced-motion: reduce) {
.loading-overlay::after { animation-duration: 2s; }
}
About this CSS Loading Overlay
This CSS Loading Overlay is 54 lines of pure CSS (1.0 KB) with no JavaScript and no dependencies. It uses keyframe animations, transforms, box shadows and backdrop filters. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.
CSS features used
- keyframe animations
- transforms
- box shadows
- backdrop filtersIncludes the -webkit- prefix for older Safari.
- CSS Grid
- reduced-motion support
Customize it
The colors in this snippet. Search and replace them to match your brand:
#fff#334155#0f172a14#0f172a#ffffffa6#cbd5e1#4f46e5
How to use this loading overlay
- Copy the HTML and paste it where you want the element to appear.
- Copy the CSS into your stylesheet, or inside a
<style>tag. - Keep the
.overlay-panelclass name, or rename it in both places. Then tweak colors, sizes and timing to match your design. - Using React or Next.js? Change
classtoclassNamein the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).
Building with an AI tool?
“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.