How to make gradient borders in CSS?

How to make gradient borders in CSS?
Average rating: 1.4
(26 votes)

Thanks! You’ve rated this material!

CSS shapes make a differenсe in your design. But what if we say that you can do even more? Do you know how to make gradient borders in CSS? We’ll teach you!

If you hate the idea of a wrapping element, you could use a pseudo-element, as long as a negative z-index value is OK. You could even place individual sides as skinny pseudo-element rectangles if you didn’t need all four sides. But don’t totally forget about border-image, perhaps the most obtuse CSS property of all time. You can use it to get gradient borders even on individual sides. Using both border-image and border-image-slice is probably the easiest possible syntax for a gradient border, it’s just incompatible with border-radius.

If you need a gradient border around an element, just make a wrapper element with a linear-gradient background, then an inner element will block out most of that background, except a thin line of padding around it.

Explore how it all works here.

By the way, here you can find a comparison of CSS Grid vs. Flexbox!

Rate this article, if you like it

Thanks! You’ve rated this material!

Got a project? Let's discuss it!

    Kyiv Sofiivska 1/2a, 01001, Kyiv, Ukraine
    Dnipro Hlinky 2, of. 1003, 49000, Dnipro, Ukraine
    Kharkiv Otakara Yarosha 22, 61000, Kharkiv, Ukraine