Skip navigation
CSS Trick! ⭐️ You can create this sparkly backdrop with a single element using mask-composite whilst…
0:00 / 0:59

CSS Trick! ⭐️ You can create this sparkly backdrop with a single element using mask-composite whilst…

jhey ʕ•ᴥ•ʔ

@jh3yy149K followers

Visit on X
1,542 likesDownloadOriginal post

280,048 views

CSS Trick! ⭐️ You can create this sparkly backdrop with a single element using mask-composite whilst animating the mask-position 😷 .canvas { background: var(--gradient); mask: var(--dots), var(--noise); mask-composite: intersect /* source-in, xor */; animation: flicker; } @​keyframes flicker { to { mask-position: 50% 50% , 0 50%; } } The trick is to layer the masks and then use the intersect value on the mask-composite ✨ Intersect works as it would in SVG by combining the masks and taking their intersection. The dots mask is a basic radial-gradient that is repeated across the element: mask: radial-gradient(circle at 50% 50%, white 2px, transparent 2.5px) 50% 50% / 40px 40px; The noise mask is a generated image of Perlin Noise (h/t to JohnPhamous for finding the site for that). That becomes the second mask: mask: url("noise.png") 50% 50% / 256px 256px; Once they are intersected. The last piece is to animate the mask-position as shown above 👆 Have a play with the demo and see what you think! CodePen.IO link below! 👇

10 Comments

Comments from the original post on X (Twitter)

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    Here's that @CodePen link! 🚀 Can use this to mask out words and icons as well 🔥

    32 likes

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    Here's John's post showing how he the same effect but using <canvas> 🤙

    12 likes

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    Annnnnddd here's that Perlin Noise generator site ⚡️ Tinker with the values until you find something that works for you. Had to mess with the alpha and seed until I found something I liked 😁

    8 likes

  • Adam Rackis's profile picture

    @AdamRackis

    C’mon bro crank that course / book out you’re killing us

    8 likes

  • Simon Vrachliotis's profile picture

    @simonswiss

    HOW does your brain think of this stuff 🤯

    8 likes

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    It's weird in there 🙃

    2 likes

  • Dan ⚡️'s profile picture

    @d4m1n

    this is not even from the future 👀 although it seems from the future

    2 likes

  • Viki ✨'s profile picture

    @viki_code

    Awesome trick 😎

    2 likes

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    Thanks Viki! 🤙

    1 like

  • Joshua's profile picture

    @JJAggas

    Your work has really been inspiring me lately.

    2 likes