How to Create Skeleton Screen Loading Effect using CSS?
Last Updated :
24 Jul, 2024

The skeleton screens are used to indicate that the content is loading. They are also called splash screens. This is a part of the modern design trend. The skeleton screens are better than the loading spinners in some cases. It is used by many big companies like Facebook, Google, etc.
HTML Code:
In this section, we will create a basic structure of loading page screen skeleton. To create a loading page skeleton, we need to use <div> element where we will display the content. We will add a loading
class to each element inside the card which we will remove when the content is loaded.
html
<!DOCTYPE html>
<html>
<head>
<title>
How to Create Skeleton Screen
Loading Effect using CSS?
</title>
</head>
<body>
<div class="card">
<div class="card__image loading"></div>
<div class="card__title loading"></div>
<div class="card__description loading"></div>
</div>
</body>
</html>
CSS Code: In this section, we will use some CSS property to create a loading page screen skeleton.
CSS
/* Card styles */
.card {
background-color: #fff;
height: auto;
width: auto;
overflow: hidden;
margin: 12px;
border-radius: 5px;
box-shadow: 9px 17px 45px -29px rgba(0, 0, 0, 0.44);
}
/* Card image loading */
.card__image img {
width: 100%;
height: 100%;
}
.card__image.loading {
height: 300px;
width: 400px;
}
/* Card title */
.card__title {
padding: 8px;
font-size: 22px;
font-weight: 700;
}
.card__title.loading {
height: 1rem;
width: 50%;
margin: 1rem;
border-radius: 3px;
}
/* Card description */
.card__description {
padding: 8px;
font-size: 16px;
}
.card__description.loading {
height: 3rem;
margin: 1rem;
border-radius: 3px;
}
/* The loading Class */
.loading {
position: relative;
background-color: #e2e2e2;
}
/* The moving element */
.loading::after {
display: block;
content: "";
position: absolute;
width: 100%;
height: 100%;
transform: translateX(-100%);
background: -webkit-gradient(linear, left top,
right top, from(transparent),
color-stop(rgba(255, 255, 255, 0.2)),
to(transparent));
background: linear-gradient(90deg, transparent,
rgba(255, 255, 255, 0.2), transparent);
/* Adding animation */
animation: loading 0.8s infinite;
}
/* Loading Animation */
@keyframes loading {
100% {
transform: translateX(100%);
}
}
Note: The loading
class has a pseudo-element that moves from left to right in order to mimic animation.
JavaScript Code: Now, when the content loaded, we can remove the loading
class from each element and add the content to the appropriate place.
javascript
const title = document.querySelector(".card__title");
const description = document.querySelector(".card__description");
const image = document.querySelector(".card__image");
// Remove the 'loading' class
title.classList.remove("loading");
description.classList.remove("loading");
image.classList.remove("loading");
// Add the content
title.textContent = 'Title';
description.textContent = 'This is the description.';
image.innerHTML = `<img src="${image - source}`;
Complete Code: In this section, we will combine the above two sections (HTML and CSS code) to create Skeleton Screen Loading Effect. If JavaScript code is added then the skeleton is replaced by the data.
Example:
html
<!DOCTYPE html>
<html>
<head>
<title>
How to Create Skeleton Screen
Loading Effect using CSS?
</title>
<style>
/* Card styles */
.card {
background-color: #fff;
height: auto;
width: auto;
overflow: hidden;
margin: 12px;
border-radius: 5px;
box-shadow: 9px 17px 45px -29px rgba(0, 0, 0, 0.44);
}
/* Card image loading */
.card__image img {
width: 100%;
height: 100%;
}
.card__image.loading {
height: 300px;
width: 400px;
}
/* Card title */
.card__title {
padding: 8px;
font-size: 22px;
font-weight: 700;
}
.card__title.loading {
height: 1rem;
width: 50%;
margin: 1rem;
border-radius: 3px;
}
/* Card description */
.card__description {
padding: 8px;
font-size: 16px;
}
.card__description.loading {
height: 3rem;
margin: 1rem;
border-radius: 3px;
}
/* The loading Class */
.loading {
position: relative;
background-color: #e2e2e2;
}
/* The moving element */
.loading::after {
display: block;
content: "";
position: absolute;
width: 100%;
height: 100%;
transform: translateX(-100%);
background: -webkit-gradient(linear, left top,
right top, from(transparent),
color-stop(rgba(255, 255, 255, 0.2)),
to(transparent));
background: linear-gradient(90deg, transparent,
rgba(255, 255, 255, 0.2), transparent);
/* Adding animation */
animation: loading 0.8s infinite;
}
/* Loading Animation */
@keyframes loading {
100% {
transform: translateX(100%);
}
}
</style>
</head>
<body>
<div class="card">
<div class="card__image loading"></div>
<div class="card__title loading"></div>
<div class="card__description loading"></div>
</div>
</body>
</html>
Output:
Similar Reads
How to create advanced Loading Screen using CSS ? In this article, we are going to build an advanced version of a wave-like structure for loading screens using HTML and CSS. The loading screen is useful when a certain page took a few seconds to load the content of the webpage. If a certain webpage doesnât contain the loading screen then at the time
2 min read
How to create a marquee effect using CSS ? In this article, we will be creating the marquee effect by using HTML and CSS. This effect can be created by using the <marquee> tag in HTML, but we will not use this tag as it is not widely used nowadays. We will create and design a marquee effect by using the CSS classes and styling properti
2 min read
How to Create Fade-in Effect on Page Load using CSS? To create a fade-in effect on page load using CSS, apply the opacity property in conjunction with the transition property to smoothly change the element's opacity from 0 to 1.opacity Property: Sets the transparency level of an element, with 0 being fully transparent and 1 fully opaque.transition Pro
3 min read
How to Create Circle Loading Animation Effect using CSS ? In this article, we will see how to create a circle-loading animation using HTML and CSS, along with understanding its basic implementation through the example. Generally, Loading Animation is utilized to wait for the content to be fully loaded on the webpage. If some pages don't contain the loader,
6 min read
How to create windows loading effect using HTML and CSS ? In this article, we are going to create a window loading effect before the lock screen appears using HTML and CSS. Glimpse of the Windows Loading Effect: Approach: Create an HTML file that contains HTML div in which we are giving the loader effect.Then we create 5 span elements which are used for c
4 min read
How to create image overlay hover slide effects using CSS ? In this article, we will learn how to make image overlay hover slide effects using CSS. When the users hover over the image, a smooth sliding overlay effect occurs. This technique gives a visual appeal with interactivity, making your website more interactive.Table of ContentFull Width Slide-In Text
4 min read
How to create Shooting Star Animation Effect using CSS ? The Shooting Star effect is one of the coolest background effects that is used for dark-themed websites. Shooting Stars Animation is an extraordinary illustration of a loading screen that grabs your eye for a considerable length of time for the remainder of the content to load on the website. This e
4 min read
How to Create a Sliding Background Effect Using CSS ? A sliding background effect in CSS creates a smooth, continuous movement of a webpageâs background image, typically in a horizontal or vertical direction. It gives a dynamic, animated feel by using properties like background-position and animation, enhancing visual engagement without additional Java
2 min read
How to create Neumorphism Effect using HTML and CSS ? Neumorphism (neomorphism) is a modern way of styling web-elements of any web-page and providing a 3D effect. This animation effect can be easily generated by using HTML and CSS. Box-shadow property of CSS can be used to implemented Neumorphism. It is used to add a dark shadow to one side and a light
2 min read
How to Create Floating Box Effect using HTML and CSS ? The floating box effect is a classical example of a custom box-shadow technique. In this technique, we create realistic-looking shadows without using the box-shadow property that is provided by the CSS. Approach: The approach is to use after selector to use create shadow using the blur function. HTM
2 min read