Open In App

How to create Glowing Star effect using HTML and CSS?

Improve
Improve
Like Article
Like
Save
Share
Report

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:



Last Updated : 14 Jul, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads