By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
rocoderesrocoderes
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Notification Show More
Latest News
How to set the dropdown value by clicking on a table row
Javascript – How to set the dropdown value by clicking on a table row
JavaScript
Attempting to increase the counter, when the object's tag exist
Javascript – Attempting to increase the counter, when the object’s tag exist
JavaScript
Cycle2 JS center active slide
Javascript – Cycle2 JS center active slide
JavaScript
Can import all THREE.js post processing modules as ES6 modules except OutputPass
Javascript – Can import all THREE.js post processing modules as ES6 modules except OutputPass
JavaScript
How to return closest match for an array in Google Sheets Appscript
Javascript – How to return closest match for an array in Google Sheets Appscript
JavaScript
Aa
Aa
rocoderesrocoderes
Search
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Follow US
High Quality Design Resources for Free.
rocoderes > HTML & CSS > Loader > How to Make 3D Spinner in CSS
HTML & CSSLoader

How to Make 3D Spinner in CSS

Admin
Last updated: 2022/12/02 at 4:22 AM
Admin
Share
8 Min Read
3D Spinner in CSS

In this article, we will see how to make a 3d spinner in CSS. This project has a number of bars which will have different amount of sizes and also these bars will rotate with cool animation. It is going to be a beginner-friendly project, as always. Also, we will make this project with only CSS.

Contents
Pre-requisites of 3D Spinner in CSSCreating HTML Markup and Default ValuesAdding BarsReforming The Bars and Adding AnimationsFull Source Code of 3D Spinner in CSSOutputYou may also like:

Pre-requisites of 3D Spinner in CSS

  • Basic knowledge of HTML.
  • Basic knowledge of CSS and CSS animations.
View Demo

Creating HTML Markup and Default Values

<!DOCTYPE html>
<html>
    <head>
        <title>3D Spinner</title>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <div class="container">
            <div class="bar1"></div>
            <div class="bar2"></div>
            <div class="bar3"></div>
            <div class="bar4"></div>
            <div class="bar5"></div>
            <div class="bar6"></div>
            <div class="bar7"></div>
            <div class="bar8"></div>
            <div class="bar9"></div>
            <div class="bar10"></div>
        </div>
    </body>
</html>
body{
    margin: 0;
    padding: 0;
    background-color: #262626;
}

Now First of all, we will add HTML code for the structure of course. For that we have added a div with container class which will have another 10 div to 10 bars, now for CSS, we have just removed default margin and padding, and also, we have assigned #262626 color to background of the body.

Adding Bars

.container{
    height: 580px;
    width: 380px;
    position: absolute;
    margin: auto;
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
}

.container>div{
    position: relative;
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
    margin-bottom: 20px;
}
.bar1,.bar2,.bar3,.bar4,.bar5{
    border-top: 40px solid white;
    border-right: 40px solid transparent;
    border-left: 40px solid transparent;
}
.bar6,.bar7,.bar8,.bar9,.bar10{
    border-bottom: 40px solid white;
    border-right: 40px solid transparent;
    border-left: 40px solid transparent;
}

Now we need to add style container first, in this container we have gave some height, width, and margin to assign some space for containers, and we will add here bars. Then we have used position to absolute in the container class, and position to relative to divs in the container class with this container’s position will be fixed. And div which are present in the container have relative position, so divs won’t come out of the container, instead they will shift into another row.

Then we have added transform-style to preserve-3d, so the all div can get 3D-effect if you assign. Also, we have added -webkit to target Chrome browser, so Chrome can run the 3D-effect on this.

Now we have selected top 5 bars, in which we have added 40px white border from top, also we have cut edge from left and right using transparent property. So our bars will have diagonal cut at the edges. Same, we have done for bottom 5 bar, but we have added edge from bottom.

3D Spinner in CSS

Reforming The Bars and Adding Animations

.container{
    height: 580px;
    width: 380px;
    position: absolute;
    margin: auto;
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
    perspective: 800px;
    -webkit-perspective: 800px;
}
.bar1,.bar2,.bar3,.bar4,.bar5{
    border-top: 40px solid white;
    border-right: 40px solid transparent;
    border-left: 40px solid transparent;
    animation: flip 4s infinite forwards;
}
.bar6,.bar7,.bar8,.bar9,.bar10{
    border-bottom: 40px solid white;
    border-right: 40px solid transparent;
    border-left: 40px solid transparent;
    animation: flip 4s infinite forwards;
}

@keyframes flip{
    100%{
        transform: rotateY(-180deg);
    }
}

.bar1{
    width: 300px;
    border-top-color: #f05a31;
}

.bar2{
    width: 240px;
    border-top-color: #e6215b;
    left: 30px;
    animation-delay: .2s;
}
.bar3{
    width: 180px;
    border-top-color: #c62283;
    left: 60px;
    animation-delay: .4s;
}
.bar4{
    width: 120px;
    border-top-color: #642a89;
    left: 90px;
    animation-delay: .6s;
}
.bar5{
    width: 0px;
    border-top-color: #1875be;
    left: 150px;
    animation-delay: .8s;
}
.bar6{
    width: 0px;
    border-bottom-color: #05a296;
    left: 150px;
    animation-delay: 1s;
}
.bar7{
    width: 120px;
    border-bottom-color: #87c63c;
    left: 90px;
    animation-delay: 1.2s;
}
.bar8{
    width: 180px;
    border-bottom-color: #fbb233;
    left: 60px;
    animation-delay: 1.4s;
}
.bar9{
    width: 240px;
    border-bottom-color: #f15a2f;
    left: 30px;
    animation-delay: 1.6s;
}
.bar10{
    width: 300px;
    border-bottom-color: #e6215b;
    animation-delay: 1.8s;   
}

Now we have gave some width in decreasing order for top 5 bar and also, we have added some random colors to them. Then we have added width in decreasing order for the bottom 5 bars, and also we have added some random colors to them. Also, we have added left property to each of the bar to reposition to center each bar.

Now we need to add animation, we have used animation named flip for 4 seconds duration, for infinite times. We have defined the animation using @keyframes, in this we have just rotated our bars to -180 degrees in Y-Axis, it will flip vertically. Then after, we have added some delay to each of the bar, so animation will be run 0.2 second late on each of the bar.

Now lastly we have added perspective to container with 800px. The perspective property is used to give a 3D-positioned element some perspective. If we reduce it by some pixels, then you can feel some visual changes.

3D Spinner in CSS

Full Source Code of 3D Spinner in CSS

index.html

<!DOCTYPE html>
<html>
    <head>
        <title>3D Spinner</title>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <div class="container">
            <div class="bar1"></div>
            <div class="bar2"></div>
            <div class="bar3"></div>
            <div class="bar4"></div>
            <div class="bar5"></div>
            <div class="bar6"></div>
            <div class="bar7"></div>
            <div class="bar8"></div>
            <div class="bar9"></div>
            <div class="bar10"></div>
        </div>
    </body>
</html>

style.css

body{
    margin: 0;
    padding: 0;
    background-color: #262626;
}

.container{
    height: 580px;
    width: 380px;
    position: absolute;
    margin: auto;
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
    perspective: 800px;
    -webkit-perspective: 800px;
}

.container>div{
    position: relative;
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
    margin-bottom: 20px;
}
.bar1,.bar2,.bar3,.bar4,.bar5{
    border-top: 40px solid white;
    border-right: 40px solid transparent;
    border-left: 40px solid transparent;
    animation: flip 4s infinite forwards;
}
.bar6,.bar7,.bar8,.bar9,.bar10{
    border-bottom: 40px solid white;
    border-right: 40px solid transparent;
    border-left: 40px solid transparent;
    animation: flip 4s infinite forwards;
}

@keyframes flip{
    100%{
        transform: rotateY(-180deg);
    }
}

.bar1{
    width: 300px;
    border-top-color: #f05a31;
}

.bar2{
    width: 240px;
    border-top-color: #e6215b;
    left: 30px;
    animation-delay: .2s;
}
.bar3{
    width: 180px;
    border-top-color: #c62283;
    left: 60px;
    animation-delay: .4s;
}
.bar4{
    width: 120px;
    border-top-color: #642a89;
    left: 90px;
    animation-delay: .6s;
}
.bar5{
    width: 0px;
    border-top-color: #1875be;
    left: 150px;
    animation-delay: .8s;
}
.bar6{
    width: 0px;
    border-bottom-color: #05a296;
    left: 150px;
    animation-delay: 1s;
}
.bar7{
    width: 120px;
    border-bottom-color: #87c63c;
    left: 90px;
    animation-delay: 1.2s;
}
.bar8{
    width: 180px;
    border-bottom-color: #fbb233;
    left: 60px;
    animation-delay: 1.4s;
}
.bar9{
    width: 240px;
    border-bottom-color: #f15a2f;
    left: 30px;
    animation-delay: 1.6s;
}
.bar10{
    width: 300px;
    border-bottom-color: #e6215b;
    animation-delay: 1.8s;   
}

Output

3D Spinner in CSS
View Demo
Download Code

You may also like:

  • HOW TO MAKE BICYCLE USING HTML AND CSS
  • How To Make Chemical Reaction With CSS Animation
  • How To Make Skeleton Loading Animation With CSS & JS

Related

Subscribe to Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

TAGGED: 3D Spinner in CSS, Animation, loader
Share this Article
Facebook Twitter Email Print
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Posted by Admin
Follow:
Rocoderes is a blog you can learn HTML, CSS, JavaScript, React Js and Python along with creative coding stuff and free source code files.
Previous Article Coffee Cup Loading Animation In CSS How To Make Coffee Cup Loading Animation In CSS
Next Article crawl loader using css How to Make Crawl Loader using CSS
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

- Advertisement -

You Might Also Like

Price Range Slider

How to Make Price Range Slider Using JavaScript

December 8, 2022
save text as File in HTML

How to Save Text as File in JavaScript

December 5, 2022
Calendar in HTML

How to Make Dynamic Calendar in HTML & JavaScript

December 5, 2022
instagram signup form

How to Make Instagram Signup Page In HTML and CSS

December 5, 2022
rocoderesrocoderes
Follow US

Copyright © 2022 All Right Reserved By Rocoderes

  • Home
  • About us
  • Contact us
  • Disclaimer
Join Us!

Subscribe to our newsletter and never miss our latest news, podcasts etc.

Zero spam, Unsubscribe at any time.
Welcome Back!

Sign in to your account

Lost your password?