DEV Community

Opeyemi Ogunsanya
Opeyemi Ogunsanya

Posted on • Edited on

CSS Particle Animation

Alt Text
Animation is a plays an important artistic role in websites. Animating a website make it more fanciful and intresting to use. 97.5% of websites uses animation in

one form or the other using many programming llanguages. CSS Particle Animation as its name suggest, are small circular dots used an the background scope of a

website. Using this CSS Particle Animation on your website can bring out light on the background scope.

Writing the code for the CSS Particle Animation

HTML5


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>CSS Particle Animation</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="glow">
        <span style="--i:1"></span>
        <span style="--i:2"></span>
        <span style="--i:3"></span>
    </div>
    <div class="glow">
        <span style="--i:1"></span>
        <span style="--i:2"></span>
        <span style="--i:3"></span>
    </div>
    <div class="glow">
        <span style="--i:1"></span>
        <span style="--i:2"></span>
        <span style="--i:3"></span>
    </div>
    <div class="glow">
        <span style="--i:1"></span>
        <span style="--i:2"></span>
        <span style="--i:3"></span>
    </div>
    <div class="glow">
        <span style="--i:1"></span>
        <span style="--i:2"></span>
        <span style="--i:3"></span>
    </div>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

CSS

*
{
    margin: 0;
    padding: 0;
}
body
{
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    height: 100vh;
    width: 100%;
    background: #111;
    overflow: hidden;
}
.glow
{
    min-width: 750px;
    height: 750px;
    margin: -200px;
    transform-origin: right;
    animation: glow_movement 5s linear infinite;
}
@keyframes glow_movement
{
    0%
    {
        transform: rotate(0deg);
        filter: hue-rotate(0deg);
    }
    100%
    {
        transform: rotate(360deg);
        filter: hue-rotate(360deg);
    }
}
.glow:nth-child(even)
{
    transform-origin: left;
}
.glow span
{
    position: absolute;
    top: calc(80px * var(--i));
    left: calc(80px * var(--i));
    right: calc(80px * var(--i));
    bottom: calc(80px * var(--i));
}
.glow span::before
{
    content: '';
    position: absolute;
    top: 50%;
    left: -8px;
    width: 12px;
    height: 12px;
    background: #ac0;
    border-radius: 50%;
}
.glow span:nth-child(3n + 1)::before
{
    background: rgb(0, 255, 242);
    box-shadow: 0 0 15px rgb(0, 255, 242),
                0 0 25px rgb(0, 255, 242),
                0 0 35px rgb(0, 255, 242),
                0 0 45px rgb(0, 255, 242),
                0 0 55px rgb(0, 255, 242),
                0 0 0 4px rgb(0, 255, 242);
}
.glow span:nth-child(3n + 2)::before
{
    background: rgb(0, 255, 145);
    box-shadow: 0 0 10px rgb(0, 255, 145),
                0 0 20px rgb(0, 255, 145),
                0 0 30px rgb(0, 255, 145),
                0 0 40px rgb(0, 255, 145),
                0 0 0 4px rgb(0, 255, 145);
}
.glow span:nth-child(3n + 3)::before
{
    background: rgb(255, 0, 212);
    box-shadow: 0 0 10px rgb(255, 0, 212),
                0 0 20px rgb(255, 0, 212),
                0 0 30px rgb(255, 0, 212),
                0 0 40px rgb(255, 0, 212),
                0 0 0 4px rgb(255, 0, 212);
}
.glow span:nth-child(3n + 1)
{
    animation: animate 10s alternate infinite;
}
.glow span:nth-child(3n + 2)
{
    animation: animate_reverse 3s alternate infinite;
}
.glow span:nth-child(3n + 3)
{
    animation: animate 8s alternate infinite;
}
@keyframes animate
{
    0%
    {
        transform: rotate(0deg);
    }
    100%
    {
        transform: rotate(360deg);
    }
}
@keyframes animate_reverse
{
    0%
    {
        transform: rotate(360deg);
    }
    100%
    {
        transform: rotate(0deg);
    }
}
Enter fullscreen mode Exit fullscreen mode

Thank you for reading.

Top comments (0)