Recreating Google Gemini Loading Animation in CSS & Tailwind
I want to give a sincere appreciation to the person who designed the Gemini loading animation. It is such a clean animation that I had to attempt to implement myself. It won’t be a exact match but close enough for my purpose. Here is the animation taken from Google Gemini implemented in CSS and Tailwind for my people :
(Refresh for the initial animation)
First in regular CSS
The animation is composed of two keyframes: expanding and moving.
expanding keyframe is responsible for the initial sliding animation. We set the scaleX to 0 (meaning it is not visible on the X-axis) and opacity to 0 (to create a fade in effect ). I chose to scale it because if you do it by width, every loading bar would essentially have the same width. By scaling it, it would return back to its original width set.
moving keyframe is responsible for the loading gradient effect. It basically moves the background gradient from left to right on a infinite loop. The background-size is set at 200% because if you only do 100%, you can see a skipping/jumping effect in the gradient. The animation begins with the background-position at 0% and moves to -200% because we want the loading animation to look like its moving to the right (by moving to the left). It’s a little counterintuitive to think about it but basically we are setting the current position of the background to the start of the loading bar. At 0%, it’s the very left of the gradient. At 50%, the middle of the gradient is now at the start of the loading bar (which is on the left). By doing the negative, it would now appear on the right!
The .loading-bar then applies the two keyframes above, with expanding running only once and moving running infinitely with a 1s delay at the start
Now TailwindCSS!
In your tailwind config, add this:
The example above I created looks likes this if you want to copy in tailwindcss