CSS Top Loading Bar
A thin glowing bar pinned to the top of the page that eases toward the end while a page loads.
<div class="top-loading-bar" role="progressbar" aria-label="Loading page"></div>
.top-loading-bar {
position: fixed;
top: 0;
left: 0;
z-index: 1000;
width: 0;
height: 3px;
border-radius: 0 3px 3px 0;
background: #2563eb;
box-shadow: 0 0 8px #2563eb, 0 0 2px #2563eb;
/* Fast at first, then slows to a crawl near the end. Remove the element when the load finishes. */
animation: top-loading-bar-grow 8s cubic-bezier(0.1, 0.7, 0.2, 1) forwards;
}
@keyframes top-loading-bar-grow {
0% { width: 0; }
20% { width: 45%; }
100% { width: 92%; }
}
@media (prefers-reduced-motion: reduce) {
.top-loading-bar { animation: none; width: 60%; }
}
About this CSS Top Loading Bar
This CSS Top Loading Bar is 23 lines of pure CSS (0.6 KB) with no JavaScript and no dependencies. It uses keyframe animations, box shadows and reduced-motion support. 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
Customize it
The colors in this snippet. Search and replace them to match your brand:
#2563eb
How to use this top loading bar
- 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
.top-loading-barclass 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.