Content loaders, skeleton screens, ghost elements, and content placeholders. These are the names given to the effect we’ll be exploring today. Many companies, such as LinkedIn, Facebook, YouTube and Slack, use this effect in their apps and websites, as you may have noticed. As much as we developers want our websites to load as quickly as possible, there are times when a lot of data needs to be rendered on the page, so Skeleton screens are a great option.
CSS technology used
Although some of the above mentioned sites use Vanilla CSS and other CSS libs/frameworks to achieve the effect, I have used the latest version of Tailwind CSS (v3.1.5) as of date to create it.
Developers earlier used to add a loading spinner animation to indicate that the page resources are still being fetched in the background which doesn’t fit the UI/UX standards of the current timeline.
First of all, lets use Tailwind’s range of utility classes to create a skeleton that roughly resembles the content you’re about to load. I have created a simple block to denote a member of our skeleton animation which may(not) scale throughout the viewport.
Size Limit
For demonstration purposes I have limited the wrapper width to 200px. If you were to increase the dimension, you would have to update the CSS props accordingly.
I have to admit that I don’t cross paths often with Linear Gradients on my day-to-day work. However with enough effort I was able to use Tailwind’s gradient color stops to create a gradient that fades from transparent to white and back to transparent.
Lets define a CSS keyframe animation that translates elements 100% to the right in the extend keyframes object of tailwind.config.js. I have used Tailwind’s arbitrary values to apply the keyframe animation to the overlay element. I have added a custom keyframe shift by the name of shimmer as well as curated my own color named stone from the Tailwind’s default color palette by importing tailwindcss/colors.
Now we shall combine our skeleton block with the overlay animation by adding the overlay to a pseudo-element of the skeleton wrapper using Tailwind’s before: modifier.
To make our overlay animation sharper I tried hiding the overlay while it’s positioned outside the skeleton. This limits the overlay overflow within the skeleton’s block and gives our effect a sharper look.
Optional
Add a white border to the top of the overlay to simulate light reflecting on the top of the skeleton.
Therefore, using powerful Tailwind CSS’s utility classes, we can build a complex customized layout to place our animated skeleton such as grid, flexbox, etc. Below is a simple grid layout with our fancy skeleton boxes. Here is the link to the Live Tailwind Playground to play around with our final build.
I hope you found this article useful and that it serves as a good starting point (not only for developers but also for Designers) for creating various skeleton loading screens. If you found this article insightful, do share it with your friends and network.
Before you leave 📌
Do check out some amazing skeleton loading packages I have found for React, Angular and Vue. Thanks for reading, and keep creating amazing UI with Tailwind💨!