Create React loading component with CSS3

Loading component is a component indispensable in an application. How do you create a loading component in React app?
In this snippet, we will create it with CSS3.

Step 1: Create a file Loading.js component with the jsx codes below:

In this file, we have to include a styles.css file with the css3 animation codes for loading, and we have two props when we use this component: colors, size
- colors is an array included all of position border colors: [borderTopColor, borderRightColor, borderBottomColor, borderLeftColor]
- size is the size of the loading component, there are 3 size with type is string: large, medium and small

Step 2: Create a CSS file with the CSS codes below:

 .loader {
  border-color: #eee;
  border-style: solid;
  border-radius: 50%;
  border-top-color: #3498db;
  -webkit-animation: spin 2s linear infinite; /* Safari */
  animation: spin 2s linear infinite;

.large {
  width: 120px;
  height: 120px;
  border-width: 16px;

.medium {
  width: 40px;
  height: 40px;
  border-width: 8px;

.small {
  width: 20px;
  height: 20px;
  border-width: 4px;

/* Safari */
@-webkit-keyframes spin {
  0% {
    -webkit-transform: rotate(0deg);
  100% {
    -webkit-transform: rotate(360deg);

@keyframes spin {
  0% {
    transform: rotate(0deg);
  100% {
    transform: rotate(360deg);

Step 3: Usage in your app

© 2019 4codev

Created with love by Sil.