The problem
You need placeholder content while data is loading to improve perceived performance.
The solution
.skeleton {
background: linear-gradient(
90deg,
#1a1a2e 25%,
#2a2a4e 50%,
#1a1a2e 75%
);
background-size: 200% 100%;
animation: skeleton-shimmer 1.5s ease-in-out infinite;
border-radius: 4px;
}
@keyframes skeleton-shimmer {
0% { background-position: 200% 0; }
100% { background-position: -200% 0; }
}
/* Skeleton elements */
.skeleton-text {
height: 16px;
margin-bottom: 8px;
}
.skeleton-text.short {
width: 60%;
}
.skeleton-title {
height: 24px;
width: 80%;
margin-bottom: 16px;
}
.skeleton-avatar {
width: 48px;
height: 48px;
border-radius: 50%;
}
.skeleton-image {
width: 100%;
height: 200px;
border-radius: 8px;
}See it live
Put it to work
<!-- Skeleton card while loading -->
<div class="card skeleton-card">
<div class="skeleton skeleton-image"></div>
<div class="skeleton skeleton-title"></div>
<div class="skeleton skeleton-text"></div>
<div class="skeleton skeleton-text short"></div>
</div>Worth knowing
Skeleton screens feel faster than spinners. Match skeleton shapes to your actual content layout.