blog

home / developersection / blogs / how to create a loader using css?

How to create a loader using CSS?

How to create a loader using CSS?

Ashutosh Kumar Verma 617 07-Jun-2024

CSS Loader

You can create a loader using CSS by taking advantage of keyframe animations.

Example- 

Here is a basic example to demonstrate the loader using CSS,

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Loader Example</title>
<style>
  /* styling for loader */
  .loader {
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-left: 4px solid #333;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: auto;
  }
/* styling for roated the loader */
  @keyframes spin {
    0% {
      transform: rotate(0deg);
    }
    100% {
      transform: rotate(360deg);
    }
  }
    /* Center the heading */
    .headting-text{
    display: flex;
    justify-content: center;
  }
</style>
</head>
<body>
  <div class="headting-text">
    <h1>Here are creating a loader using CSS</h1>
  </div>
  <div class="loader"></div>
</body>
</html>

In the above example

  • We create a <div> element with a class called "loader" to represent the loader.
  • We use CSS to style the loader, set its boundaries, border-radius, width and height to create a circle.
  • To further rotate the loader, we use the "spin" keyframe animation. The animation rotates the loader endlessly from 0 degrees to 360 degrees for 1 second.
  • The margin: auto; The property centers the loader directly in its container.

 

Output- 

How to create a loader using CSS?

You can further customize the loader by customizing CSS preferences such as size, color, animation duration, and facilitation functions to suit your design needs. Additionally, you can add different shapes or animation effects to create different style loaders.

 

Also, Read: How to implement the List group using CSS3 and HTML?

 


Updated 07-Jun-2024

I'm a passionate content writer with a deep background in technology and web development. Skilled at writing engaging, well-researched, and SEO-friendly articles, I enjoy simplifying complex topics into clear and impactful writing that informs, inspires, and engages readers.

Leave Comment

Comments

Liked By