×

CSS Loader

CSS Loader

The loader is the animation that can alert a visitor regarding the loading of the page. We need to wait for some time. It will be helpful if any page takes a few seconds for loading of the webpage content. A visitor could assume that the website is unresponsive if he does not use the loader over any webpage.

With the use of the loader in CSS, we can create a visitor waited or distracted for a few seconds until a page gets completely loaded.

We may understand the CSS loader concept with the use of the following demonstrations.

Consider the below examples:

Example:1

<!DOCTYPE html>  
<html>  
<head>  
<title> CSS loader </title>  
<style>  
h1
{  
color:blue;  
}  
div
{  
display: block;  
position: absolute;  
width: 10px;  
height: 10px;  
left: calc(50% - 1em);  
border-radius: 1em;  
transform-origin: 1em 2em;  
animation: rotate;  
animation-iteration-count: infinite;  
animation-duration: 1.6s;  
}  
@keyframes rotate
{  
0% { transform: rotate(0deg); } 
100% { transform: rotate(360deg); } 
}  
.d1
{  
animation-delay: 0.1s;  
background-color: red;  
}  
.d2
{  
animation-delay: 0.2s;  
background-color: blue;  
}  
.d3
{  
animation-delay: 0.3s;  
background-color: yellow;  
}  
.d4
{  
animation-delay: 0.4s;  
background-color: lightblue;  
}  
.d5
{  
animation-delay: 0.5s;  
background-color: lime;  
}  
</style>  
</head>  
<body>  
<center>   
<h1> CSS Loader </h1>  
<div class='d1'></div>  
<div class='d2'></div>  
<div class='d3'></div>  
<div class='d4'></div>  
<div class='d5'></div>  
</center>  
</body>  
</html> 

Output:

CSS Loader

Example:2

In the following example, we will use spinner in this another demonstration of the CSS loader.

<!DOCTYPE html> 
<html> 
<head> 
<style> 
h1
{ 
text-align:center; 
} 
.loader
{ 
border: 20px solid #f3f3f3; 
position:absolute; 
left:43%; 
border-radius: 50%; 
border-top: 20px solid navy; 
width: 150px; 
height: 150px; 
animation: spin 2s linear infinite; 
} 
@keyframes spin
{ 
0% { transform: rotate(0deg); } 
100% { transform: rotate(360deg); } 
} 
</style> 
</head> 
<body> 
<h1>CSS Loader</h1> 
<div class="loader"></div> 
</body> 
</html> 

In this example, we have specified the border property of CSS, which describes the loader’s border size and border color. Here, we have also applied the border-radius attribute of CSS, which transforms a border into a circle.

We have applied the border-top attribute of CSS for the navy thing that will spin around inside the border. The loader's size is described with the use of the height and width properties. In the last, we have included the animation which create the navy thing spin endless times along with the 2s animation speed.

Output:

CSS Loader

The following another demonstration of loader.

Example:3

In the above-mentioned example, we have added only the border-top attribute of CSS, but in this demonstration, we will also add the border-right, border-left, and border-bottom attributes of CSS.

<!DOCTYPE html> 
<html> 
<head> 
<style> 
h1
{ 
text-align:center; 
} 
.loader
{ 
  border: 20px solid #f3f3f3; 
  position:absolute; 
  border-radius: 50%; 
  border-top: 20px solid navy; 
  border-bottom: 20px solid navy; 
  width: 150px; 
  height: 150px; 
  animation: spin 2s linear infinite; 
} 
.loader1
{ 
  border: 20px solid #f3f3f3; 
  position:absolute; 
  left:43%; 
  border-radius: 50%; 
  border-top: 20px solid navy; 
  border-bottom: 20px solid yellow; 
  border-right: 20px solid red; 
  width: 150px; 
  height: 150px; 
  animation: spin 2s linear infinite; 
} 
.loader2
{ 
  border: 20px solid #f3f3f3; 
  position:absolute; 
  left:80%; 
  border-radius: 50%; 
  border-top: 20px solid navy; 
  border-bottom: 20px solid yellow; 
  border-right: 20px solid red; 
  border-left:20px solid magenta; 
  width: 150px; 
  height: 150px; 
  animation: spin 2s linear infinite; 
} 
@keyframes spin
{ 
  0% { transform: rotate(0deg); } 
  100% { transform: rotate(360deg); } 
} 
</style> 
</head> 
<body> 
<h1>CSS Loader</h1> 
<div class="loader"></div> 
<div class="loader1"></div> 
<div class="loader2"></div> 
</body> 
</html> 

Output:

CSS Loader

Related Topics

CSS: nth-selector

CSS nth selector can be used to match an element according to its position regardless of its parent’s type. Here, n can be any number, formula, or a keyword. These selectors...

2 minutes read.

Internal CSS

What is CSS? CSS stands for Cascading Style Sheet.CSS is used to apply styling the HTML elements.With CSS user can add or change color, font-size and font-family. It also helps user...

4 minutes read.

CSS :root selector

CSS :root selector This CSS pseudo-class matches any document’s root element. It chooses the parent of the highest-level inside the document DOM or tree. An element of <html> is always a...

2 minutes read.

CSS Comments

CSS Comments: Generally, comments in CSS are used to describe our code. Further, it will provide support to many users who are concerned with the code. Somewhat, these are ignored...

2 minutes read.

CSS Outline

CSS Outline: This CSS property is quite similar to the border property of CSS. It eases us to design an additional border around the element to obtain visual attention. The...

4 minutes read.

Create a 3D text effect using HTML and CSS

A3D text effect is a beautiful and attractive part of a webpage. As a web page developer, it is crucial to know how to create a 3D text effect with...

3 minutes read.

CSS Text-Transform Property

Text-Transform in CSS The text-transform property permits us to alter the text case. It controls the capitalization of the text. This property is employed to design the text appearance in every...

3 minutes read.

CSS User Interface

Introduction User Interface can be defined as series of visual elements like screens, buttons, forms that help the user interact with the software application or hardware device. CSS User Interface allows the...

6 minutes read.

CSS Opacity

The CSS Opacity property is used to set the clarity of the image. It is defined as degree and specify the transparency of an element. Note: Opacity value will be less...

1 minute read.

How to make smooth bounce animation using CSS

The smooth bouncing animation project is done with the help of HTML and CSS. This project gives so much fun and excitement to the users. What is HTML? The HTML or HyperText...

2 minutes read.

CSS Arrow

CSS Arrow The arrow of CSS is applied to insert an array with the tooltip. It can make a tooltip as any speech bubble. Also, this arrow can be illustrated in...

4 minutes read.

CSS Masking

CSS Masking The CSS mask property is applied to hide a component with the use of the masking or clipping an image at any specific point. The masking depicts the use...

3 minutes read.

CSS Justify Content

Justify Content: These properties are applied for the alignment of items of a flexible box container if any item does not cover every available space over the main-axis, i.e., horizontally....

4 minutes read.

CSS Image Gallery

Image galleries are used to display and store collections of images. Example Let’s discuss an example. CSS was used to create the following image gallery: Code is as follows: <html> <head> <style> div.gallery {   margin: 6px;   border: 1px...

5 minutes read.

CSS translate() Function

Translate() CSS function This function in CSS is a CSS in-built function. It relocates the element in the horizontal direction or in the vertical direction. It can move the items from...

2 minutes read.

CSS Float

CSS Float: The float property of CSS is the positioning property. This property is applied to elements to push them either to left or right. It permits for wrapping facility...

4 minutes read.

CSS Transition

CSS Transition The transitions in CSS are influenced, included to modify the component from one design to another, without the use of the JavaScript or Flash. We should describe two of the...

2 minutes read.

How to change background color in CSS

How to change background color in CSS? The background-color property in CSS would be used to specify the color of an element's background. As the element's background, it uses solid colors. The...

3 minutes read.

CSS Background Color

It is one of the CSS properties to apply styling to html elements.This property is used to apply the background color to any HTML element.The background of an element includes...

2 minutes read.

CSS Counters

CSS Counters: The CSS counter property is similar to the variables. CSS counters are controlled via CSS, and its values are incremented via rules of CSS to record how much...

4 minutes read.