How to create Glowing Star effect using HTML and CSS? - GeeksforGeeks

14 Jul, 2020
The glowing star effect is one of the coolest effects that is used for dark themed websites. It is known as star effect because it has small glowing balls animated in different ways which looks like stars. This effect can be used for image slider, loader, and maybe as an showcase UI element.
Approach: The approach is to create small balls using unordered list and then animating them using keyframes and n-th child property. Basic knowledge of these two properties is a prerequisite of going any further in this article.
HTML Code: In this section, we have created an unordered list.
<!DOCTYPE html><html><head><title>GLOWING STAR EFFECT</title></head><body><ul>      <li></li>      <li></li>      <li></li>      <li></li>      <li></li>            </ul></body></html>
CSS Code: For CSS, follow the given below steps:
Step 1: Align the list according to your need. We have aligned the list to the center of the page.
Step 2: Remove all the list styles and give them circle shape using border-radius.
Step 3: Use keyframes to animate the balls by increasing the scale. There is no fix way of doing this you can change scale on different frames as you like.
Step 4:  Use n-th child property to apply some delay between animation of each li element.
Tip: This effect is one of the most versatile effects. You can change the type of animation on different frames or can change the delay. So, try out  different values of the properties that are used in this article to find the best animation for yourself. Also this effect only looks good on a dark-theme page so don’t use it on light-themed websites.
body {       background: rgb(70, 69, 69);     }     ul {       position: absolute;       top: 50%;       left: 50%;       display: flex;     }     ul li {       list-style: none;       width: 40px;       height: 40px;       background: #fff;       border-radius: 50%;        animation: animate 1.7s ease-in-out infinite;     }     @keyframes animate {       0%,       40%,       100% {         transform: scale(0.2);       }       20% {         transform: scale(1);       }     }      ul li:nth-child(1) {       animation-delay: -1.2s;       background: yellow;       box-shadow: 0 0 50px yellow;     }     ul li:nth-child(2) {       animation-delay: -1s;       background: rgb(99, 247, 136);       box-shadow: 0 0 50px rgb(99, 247, 136);     }     ul li:nth-child(3) {       animation-delay: -0.8s;       background: rgb(30, 243, 225);       box-shadow: 0 0 50px  rgb(30, 243, 225);     }     ul li:nth-child(4) {       animation-delay: -0.6s;       background: rgb(241, 58, 58);       box-shadow: 0 0 50px rgb(241, 58, 58);     }     ul li:nth-child(5) {       animation-delay: -0.4s;       background: rgb(247, 61, 176);       box-shadow: 0 0 50px  rgb(247, 61, 176);     }
Complete Code: It is the combination of the above two sections of code.
<!DOCTYPE html><html><head><title>GLOWING STAR EFFECT</title>  <style>   body {        background: rgb(70, 69, 69);      }      ul {        position: absolute;        top: 50%;        left: 50%;        display: flex;      }      ul li {        list-style: none;        width: 40px;        height: 40px;        background: #fff;        border-radius: 50%;          animation: animate 1.7s ease-in-out infinite;      }      @keyframes animate {        0%,        40%,        100% {          transform: scale(0.2);        }        20% {          transform: scale(1);        }      }        ul li:nth-child(1) {        animation-delay: -1.2s;        background: yellow;        box-shadow: 0 0 50px yellow;      }      ul li:nth-child(2) {        animation-delay: -1s;        background: rgb(99, 247, 136);        box-shadow: 0 0 50px rgb(99, 247, 136);      }      ul li:nth-child(3) {        animation-delay: -0.8s;        background: rgb(30, 243, 225);        box-shadow: 0 0 50px  rgb(30, 243, 225);      }      ul li:nth-child(4) {        animation-delay: -0.6s;        background: rgb(241, 58, 58);        box-shadow: 0 0 50px rgb(241, 58, 58);      }      ul li:nth-child(5) {        animation-delay: -0.4s;        background: rgb(247, 61, 176);        box-shadow: 0 0 50px  rgb(247, 61, 176);      }      </style>    </head><body>      <ul>      <li></li>      <li></li>      <li></li>      <li></li>      <li></li>            </ul></body></html>
Output:
Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.
CSS-Advanced
CSS
HTML
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Create a Responsive Navbar using ReactJS
Design a web page using HTML and CSS
Form validation using jQuery
How to apply style to parent if it has child with CSS?
How to auto-resize an image to fit a div container using CSS?
How to set the default value for an HTML <select> element ?
How to set input type date in dd-mm-yyyy format using HTML ?
Hide or show elements in HTML using display property
How to Insert Form Data into Database using PHP ?
REST API (Introduction)