Loading Skeleton or Shimmer are everywhere nowadays. All the big companies like Facebook and Linkedin are using them to have a nice user experience. Using TailwindCSS, you can easily create a loading skeleton/shimmer for your web pages. There are 2 steps in designing a basic loading skeleton.
Creating Loading Skeleton/Shimmer in TailwindCSS
First, you have to create a static skeleton that doesn’t move at all. You can do it with gray colors available in TailwindCSS. Here is a simple static user card skeleton with gray colors. You can check the basic structure demo on tailwind play.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<div class="border border-blue-300 shadow rounded-md p-4 mt-10 max-w-sm w-full mx-auto"> <div class=" flex space-x-4 "> <div class="rounded-full bg-slate-500 h-10 w-10"></div> <div class="flex-1 space-y-6 py-1"> <div class="h-2 bg-slate-600 rounded"></div> <div class="space-y-3"> <div class="grid grid-cols-3 gap-4"> <div class="h-2 bg-slate-600 rounded col-span-2"></div> <div class="h-2 bg-slate-600 rounded col-span-1"></div> </div> <div class="h-2 bg-slate-600 rounded"></div> </div> </div> </div> </div> |
This static skeleton will look like the screenshot below.
Adding Animation to Skeleton
Now, you need to add just one class that will do everything for you. Add the class animate-pulse
that adds animations for creating a loading effect. The following code will create a complete loading effect for the skeleton. You can check the working demo online to see the effect.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<div class="border border-blue-300 shadow rounded-md p-4 mt-10 max-w-sm w-full mx-auto"> <div class=" flex space-x-4 animate-pulse "> <div class="rounded-full bg-slate-500 h-10 w-10"></div> <div class="flex-1 space-y-6 py-1"> <div class="h-2 bg-slate-600 rounded"></div> <div class="space-y-3"> <div class="grid grid-cols-3 gap-4"> <div class="h-2 bg-slate-600 rounded col-span-2"></div> <div class="h-2 bg-slate-600 rounded col-span-1"></div> </div> <div class="h-2 bg-slate-600 rounded"></div> </div> </div> </div> </div> |
Conclusion
You can add a simple loading skeleton in TailwindCSS by creating a static skeleton and adding animate-pulse
class. This is very useful to increase the user experience on the website.