Animated Hourglass Loader Using SVG and CSS Only
This animated hourglass loader is a purely HTML and CSS solution that uses SVG to render a detailed sand-timer animation. It’s lightweight, responsive, and requires no JavaScript. Everything from the falling sand to the rotating motion is driven by CSS keyframes.
Design Overview
The loader is built around an SVG <g> element that rotates clockwise, giving the illusion of a flipping hourglass. Inside it is a stylized hourglass shape with curved glass bulbs, filled and drained by animated sand particles.
The sand transitions from the top bulb to the bottom through a center stream, represented by animated lines. Simultaneously, a “sand mound” grows in the bottom bulb and shrinks in the top, creating a realistic hourglass illusion.
Structure Details
Rotating Circles: Three concentric circular strokes (thick, medium, thin) rotate around the hourglass, fading in and out during the cycle.
Sand Motion: Individual lines simulate falling grains and fill levels.
Mounds: Two clipped
<path>s represent accumulating and depleting sand mounds in the top and bottom bulbs.Glare Effects: Top and bottom glares highlight the glass surface as the hourglass flips.
Animations
The motion is entirely handled via CSS @keyframes. Key transitions include:
loader-flip: Rotates the hourglass by 180° to simulate flipping.sand-drop: Animates the center sand stream downward.sand-fillandsand-line-*: Control the level and texture of the sand inside the lower bulb.motion-thick,motion-medium,motion-thin: Rotate and fade outer loader rings at varying speeds and weights.sand-mound-top&sand-mound-bottom: Animate sand pile growth and shrink using scale and translation.
All elements are synchronized with a shared custom duration variable (--dur), making the loader easy to tweak by changing one value.
Responsive & Themed
The loader scales with em units, making it responsive to font size. It also adapts to dark mode using a media query, changing colors with CSS custom properties based on the user’s color scheme preference.
This SVG-based hourglass loader is a fully self-contained, reusable animation for loading states. It’s both visually engaging and technically precise, with all motion driven by CSS animations.
This code uses HTML and CSS only — no JavaScript included.
Copyright – 2025 nima-mollazadeh (XOcode)
Permission is freely granted to anyone who obtains a copy of this software and its accompanying documentation files (referred to as “the Software”), allowing them to use, copy, modify, merge, publish, distribute, sublicense, and even sell copies of the Software. Additionally, users are allowed to permit others to use the Software under these same terms.
It is required that the above copyright notices and this permission notice be included in all versions or significant portions of the Software.
Please note, the Software is provided “as is”, without any form of warranty—express or implied. This includes, but is not limited to, warranties of merchantability, fitness for a specific purpose, or non-infringement. Under no circumstances shall the original authors or rights holders be held responsible for any claims, damages, or other liabilities that may arise from the use of the Software, whether through legal action, negligence, or otherwise.
All code on Freeofcosts.com is reviewed before publishing. Each post includes a live code editor with real-time preview, so you can experiment and learn by doing. Most code is open-source and free to use or modify under respective licenses.



