November 24, 2023
Want to elevate your website design with eye-catching animated gradient borders? Let's explore four techniques to achieve this stunning effect in CSS.
Creating a gradient border and animating it in CSS can be tricky. Let's dive into some ways to do it together in this experiment.
For a border without radius needs, use border-image:
To maintain radius with no transparency:
You can combine backgrounds and use more background properties to achieve the same effect.
If you need both transparency and radius, CSS masking is the way.
We can use CSS Houdini to animate a gradient border.
For browsers that don't support Houdini, you can utilize the CSS @supports feature. This ensures users still receive the gradient, even if they can't view the animation.
No radius, but allows a transparent background and eliminates the need for an extra element, avoiding z-index issues.
Provides a radius but lacks transparency and may pose potential z-index challenges.
Gives us the radius but doesn't offer transparency; it bypasses z-index complexities.
Offers both radius and transparency but presents a z-index drawback.
I made the following flowchart to illustrate how you can choose the best option.
If a radius isn't necessary, opt for the border-image technique. Need a radius? If transparency isn't required, use multiple backgrounds. For a transparent background with a radius, CSS masking is the solution.
Join the conversation initiated by Lea on GitHub regarding a potential CSS value for gradient borders.
Do you want to learn all about these techniques? You can watch me explain them on YouTube.
For a live demo and source code, check out our GitHub repository: Bejamas Experiments.