DEV Community

Cover image for Create a Spinner Loader in React using CSS
Kirtesh Bansal
Kirtesh Bansal

Posted on • Edited on

19

Create a Spinner Loader in React using CSS

Hi Folks,

In this article, we'll talk about how to create a spinner loader in React using pure CSS.

We will be creating a loader as shown below -

CPT2110092208-232x179

Let's start creating a file called spinner.js in the react project and add some JSX to it for the loader.

File: Spinner.js
const Spinner = () => <div className="loader"></div>;

export default Spinner;
Enter fullscreen mode Exit fullscreen mode

Let's understand the above code -

Here, we have created a functional component called Spinner. Which is returning a div element with a class loader. That's all the JSX required for it.

Now, Let's add css for it.

.loader {
  border: 10px solid #f3f3f3;
  border-top: 10px solid #3498db;
  border-radius: 50%;
  width: 80px;
  height: 80px;
  animation: spin 1s linear infinite;
}
Enter fullscreen mode Exit fullscreen mode

Let's understand the above CSS -

We've added border:10px solid #f3f3f3 property to create the gray circle and border-top: 10px solid #3498db to create the blue colored arc on top of the gray colored circle. After that border-radius: 50% property to make it circular and have given same amount of height & width.

Now, to add the spinning effect we've added animation: spin 1s linear infinite.

It will look like this -

s

Let's add the final CSS to create the spinning effect-

 @keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
} 
Enter fullscreen mode Exit fullscreen mode

Let's understand the final CSS -

Here, we have added keyframes for the spin animation. Where we are rotating the element using transform: rotate() property from 0 degree to 360 degree.

Finally, Our Sinnner loader is ready.

That was it from this article. Do share your comments and feedback about the article.

Find the code below.

Keep learning!

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (1)

Collapse
 
steinitz profile image
Steve Steinitz

Really nice, stand alone and easy to tweak. Bravo and thank you.

Image of PulumiUP 2025

From Cloud to Platforms: What Top Engineers Are Doing Differently

Hear insights from industry leaders about the current state and future of cloud and IaC, platform engineering, and security.

Save Your Spot

👋 Kindness is contagious

Dive into this thoughtful article, cherished within the supportive DEV Community. Coders of every background are encouraged to share and grow our collective expertise.

A genuine "thank you" can brighten someone’s day—drop your appreciation in the comments below!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found value here? A quick thank you to the author makes a big difference.

Okay