Skip navigation
CSS Trick! ⭐️ You can animate your gradient borders by defining types for your custom properties…
0:00 / 0:47

CSS Trick! ⭐️ You can animate your gradient borders by defining types for your custom properties…

jhey ʕ•ᴥ•ʔ

@jh3yy149K followers

Visit on X
1,387 likesDownloadOriginal post

258,918 views

CSS Trick! ⭐️ You can animate your gradient borders by defining types for your custom properties with @ property 🔥 1. Define a property @ property --angle { syntax: ' '; /* 👈 type angle*/ inherits: true; initial-value: 0deg; } 2. Animate the value article { animation: rotate 2s infinite linear paused; } @ keyframes rotate { to { --angle: 360deg; } } 3. Use the value in your conic-gradient background. article { --gradient: conic-gradient(from var(--angle), ...); background: linear-gradient(var(--bg), var(--bg)) padding-box, var(--gradient) border-box; border: 4px solid transparent; } 4. Change the play state to running on :hover, etc. article:is(:hover, :focus-within) { animation-play-state: running; } That's it! 🤙 As soon as Firefox 120 lands, this one will work in all browsers! 🙌 Until then, it's a progressive enhancement. You will still get the brightening of the border on hover, etc. That's handled with a pseudo-element ✨ CodePen.IO link below! 👇

11 Comments

Comments from the original post on X (Twitter)

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    Here's that @CodePen link! 🚀 (Which I may or may have not forgotten to post yesterday 👀) Got the "Final boss" border demo that people have been asking for tomorrow 🤞😅

    14 likes

  • Bill Criswell's profile picture

    @crswll

    I think with this and :has I'll be pretty happy for a while. If I get a :stuck for position: sticky I will dance in the street.

    2 likes

  • Danny Clayden Chambers's profile picture

    @ClaydenChambers

    Now this really is something new to me.. banking this!

    1 like

  • Shaun Levett's profile picture

    @shaunlevett

    Succulent

    1 like

  • Янус Двуликий's profile picture

    @Conkur27

    Long time no see thnx

    1 like

  • Blueming's profile picture

    @forreacting

    Oh wow that looks cool I need this ..thankuuuuuu

    1 like

  • 🙊 Shady Sieo 👹's profile picture

    @HgSieo

    Yeah i tried it too to animate some buttons, works fine on nearly square items, as soon as you do more rectangle shapes, the animation seems to slow down on the corners and the shorts edges... Any tips on how to bypass that ? gg anyway !

    1 like

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    Got jus' the thing you need 🤙

    10 likes

  • lil uzi perf's profile picture

    @ken_wheeler

    Sheesh

    1 like

  • Lilesh Jadav's profile picture

    @lileshjadav

    Which tool was that for showing separate layers?

    1 like

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    Straight up CSS 🤙