First of all, even though this tutorial is based on React, you can apply the same technique with any library/framework or just HTML and CSS.
Preparing the Template
Let's run the following command to create a new React app by using Vite.
After the installation is done and our project is created, we can open it and install our dependencies.
We will delete assets folder in src since we don't need it, apply some global styles to override the default browser stylings and a dark background to make the glow effect more visible.
Now, our template is ready and we can start creating our glowing images!
Glowing Images
Let's start creating GlowingImage component to render our images.
Let's display the image by centering it horizontally in our app.
It should look like this now:
Now we need to add the glow effect. As you can guess, we will use glowing-image-root to add the stylings.
We will create a pseudo element by using ::before and set its background image as same as our image. By doing this, we will have two layers of the same image on top of each other.
To be able to share the image URL between the component and CSS, we use custom properties (CSS variables).
We also set border-radius and make <img> to inherit it to have a little rounded image.
Now, we can apply stylings to the background image, without affecting the original one.
To imitate a glow effect, we will add some blur to the background image and give it a little saturation to make its colors sharper.
We have a subtle glow now!
To make it more visible, we can apply some scaling too. We can make the background image bigger by scaling it up, but I prefer making the original image slightly smaller like:
And it's done!
To better understand this technique, we can make the original image non-visible temporarily and reveal our glowing image trick like:
If you want, you can also add some hover animation to the glow effect like: