Skeleton Loader CSS With Angular

Many of us hope to improve user experience by displaying loaders and spinners while users wait for a page to be loaded due to some server to client communication, promises to be resolved or basically any function waiting to be executed or data waiting to be retrieved from the server before finally rendering the page to the user.

I personally think skeleton screens give the illusion of “it’s almost about to show” while loaders and spinners make it feel like “it’s trying to show hopefully” that is why you find Facebook, Slack, LinkedIn and Co using skeleton screens.

The idea is, Whenever someone requests new content from the server, you can immediately start showing the skeleton, while data is being loaded in the background. Once the content is ready, simply swap the skeleton for the actual card. This can be done with plain vanilla JavaScript or using a library like Angular, React, Vue etc.

Now you could use an image to display the skeleton, but that would introduce an additional request and data overhead. We’re already loading stuff here, so it’s not a great idea to wait for another image to load first. Plus it’s not responsive, and if we ever decided to adjust some of the content card’s styling, we would have to duplicate the changes to the skeleton image so they’d match again.

Related Post- Multi Theme CSS With Angular

What I observe is –

  • Skeleton screens are somewhat novel and attract more attention than the ubiquitous loading spinner.
  • Skeleton screens work better in familiar interfaces and can be off-putting in new settings when users don’t know what to expect.
  • Skeleton screens work best when wait times are very short.

Lets Code –

  • Create a new angular project, Add Bootstrap framework for faster & responsive design into the index.html file.
  • Do not forget to add BrowserAnimationsModule into app.module.ts ‘s “imports[]”.
  • Add the layout you want also it’s CSS.
  • CSS pseudo class – :empty pseudo can be used to preserve the loading effect on any of the layout elements without children. Children can be either element nodes or text (including whitespaces).
.head-section:empty, 

.profile-img-section:empty, 

.text1:empty, 

.text2:empty, 

.text3:empty, 

.text4:empty{

animation: loading 1.1s infinite linear;

background: #dedfe1;

background-image: -webkit-linear-gradient(to right, #dedfe1 0%, #f2f3f5 20%, #dedfe1 40%, #dedfe1 100%);

background-image: linear-gradient(to right, #dedfe1 0%, #f2f3f5 20%, #dedfe1 40%, #dedfe1 100%);

background-repeat: no-repeat;

}
  • Structural Derivative – *ngIf will be used to switch from the skeleton layout to the original layout once our asynchronous request has been fulfilled.
  • To get a loading effect on every element of our skeleton layout, we will make use of the linear-gradient CSS property which provides a smooth transition between colors. Angular provided a method called ‘transition()’.The transition() function accepts two arguments:

Check Related Case Study: Streamlining The Accreditation Process For Physicians

The first argument accepts an expression that defines the animation states or the direction between two transition states, and the second argument is an array that accepts some set of parameters like animate(), style() e.t.c.The animate() is similar to the animate CSS property while style() will contain the CSS styles for the animation states.

  • Using CSS animation property and @keyframes rule will enable us to gradually change from a set of CSS styles to another. The @keyframes rule specifies the animation code. The animation is created by gradually changing from one set of CSS styles to another, you can change the set of CSS styles many times.
@keyframes loading {

0% {

background-position: -100px;

}

100% {

background-position: 200px;

}

}
coma

Final word

I am hoping this article will help you to understand the aspects of skeleton screen loading animation. To discuss more about the concept of css skeleton loading, share your queries in the comment section.

Hire Our Angular App Developer

Nikhil

Tech Expert

I love building things and learning new stuff. Enjoying journey for the last few years as a software developer and creating better things. Industry experienced MEAN Stack Developer, Full Stack Developer, and BI Developer.

The founder's survey report on "What Matters For Startup" is released - Get your copy and learn the trends of successful companies :)

Download Free eBook Now!

Get in touch for a detailed discussion.

Hear From Our 100+ Customers
coma

Mindbowser helped us build an awesome iOS app to bring balance to people's lives.

author
Addie Wootten
CEO, Smiling Mind
coma

We had very close go live timeline and MindBowser team got us live a month before.

author
Shaz Khan
CEO, BuyNow WorldWide
coma

They were a very responsive team! Extremely easy to communicate and work with!

author
Kristen M.
Founder & CEO, TotTech
coma

We’ve had very little-to-no hiccups at all—it’s been a really pleasurable experience.

author
Chacko Thomas
Co-Founder, TEAM8s
coma

Mindbowser is one of the reasons that our app is successful. These guys have been a great team.

author
Dave Dubier
Founder & CEO, MangoMirror