How to create Glowing Star effect using HTML and CSS?

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.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


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.



filter_none

edit
close

play_arrow

link
brightness_4
code

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);
     }

chevron_right


Complete Code: It is the combination of the above two sections of code.

filter_none

edit
close

play_arrow

link
brightness_4
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>

chevron_right


Output:

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.