Create Loading Screen Using CSS

In this article we will see how to create a loading screen using CSS.

In this article we will see how to create a loading screen.

Step 1

The first step is to create an Index.html file and put the following code in it.

Index

In the preceding HTML file, we have added three divs. In the last div we have added five divs. In these five divs we are loading text as content that will be displayed as an output.

But currently if we view this Index.html in a browser, it will look like this.

browser
Step 2

The next step is to add some styles and for that create a CSS file “container” and specify the CSS file address in the HTML file.

html file

In the container.css file write the following:

container

Refresh the page.

Refresh the page

Our elements shifts 200px vertically and horizontally.

Set the padding-left to 70px.

Set the padding

Refresh the page.

page

Our container is now shifted 70px from the left.

Step 3

The next step is to add some CSS rules for the inner-container.

css

It will shift the elements more to the right and downward.

elements

Step 4

The next step is to add some styles for our load div.

  1. /*.load > div means we want to select only the div that sits directly after the load container. This will not take any child element present in the inner div. 
  2. */  
  3. .load > div{  
  4.     /*give a font-size of 20px*/  
  5.     font-size: 20px;  
  6.   
  7.     /*add a line-height of 90px. It will shift the element downwards.*/  
  8.     line-height: 90px;  
  9.   
  10.     /*It will shift the element to the center*/  
  11.     text-align: center;  
  12.   
  13.     /*set the background color to white*/  
  14.     background-color: white;  
  15.   
  16.     /*set the float property to left which will float elements from left to right*/  
  17.     float: left;  
  18.   
  19.     /*set the margin-left property to 150px, it will shift the elements 150px from the left*/  
  20.     margin-left: 150px;  
  21.   
  22.     /*set the width to 20px for each elements*/  
  23.     width: 20px;  
  24.   
  25.     /*set the opacity to 1 which is nothing but the visibility level*/  
  26.     opacity: 1.0;  
  27.   
  28.     /*Set the transform scale to 0.8 that will reduce the scale of the elements*/  
  29.     -webkit-transform: scale(0.8);  
  30.       
  31.     /*this "load" is a keyframe that we want to bind to a selector*/  
  32.     -webkit-animation-name: load;  
  33.   
  34.     /*animation duration*/  
  35.     -webkit-animation-duration: 1.20s;  
  36.   
  37.     /*set the iteration to infinite, if you want the animation non-stop*/  
  38.         -webkit-animation-iteration-count: infinite;  
  39. }  
Refresh the page. The elements scale will reduce to 0.8. But no animation will happen.

elements scale

Step 5

The next step is to add a keyframe with a name load and we will bind this keyframe to the .load selector.

keyframe

Since, we have already bound this keyframe to the selector.
  1. /*this load is a keyframe that we want to bind to a selector*/  
  2. -webkit-animation-name: load;  
Refresh the page and you will see all the five loading contents. Now the animation is from a scale of 1.2 to 0.7 with an opacity of 1 to 0.1.

loading contents
But all the contents animate at the same time. Now let's say we want each of the contents to animate one by one in a linear way and for that we need to set an animation delay for all the elements.

Step 6

animation

Refresh the page and you will see the elements animate one after another.

So, we have learned how to create a simple loading screen using CSS but there are many more things you can do with this. So keep exploring.

I hope you like it. Thank you.