How to get that neat Messenger gradient scrolling effect with CSS
Luis Augusto

Luis Augusto @luisaugusto

About: Fullstack JavaScript Developer based in Sacramento. When I'm not coding, I'm outside hiking and adventuring.

Location:
Sacramento, CA
Joined:
Sep 25, 2019

How to get that neat Messenger gradient scrolling effect with CSS

Publish Date: May 10 '20
83 3

For those of you that use Messenger, you probably already know that there are ways to customize a chatroom by changing the message colors, emoji, group name and photo, nicknames, etc. However I recently found that you can add a gradient to you message bubbles which I find to be really pleasing:

Messenger Background Options

So how does this work? It's actually really easy to do and a great use of background-attachment: fixed property value.

With background-attachment: fixed, the background does not scroll with its container, and it becomes fixed in place relative to the browser viewport. You can see this a lot in Squarespace templates to create that parallax image effect:

The same property can be used with gradients, since those are also treated as images in CSS, creating that scrolling gradient effect. If you also have multiple elements with the same background and fixed attachment, it makes it look like the background gradients flow into each other from bubble to bubble. Since the background is relative to the viewport, the size of the gradient is the size of the viewport:

Messenger gradient scrolling

What are some other neat things you can do with this? You can make it look like a box is disappearing when you scroll up:

It's pretty neat what one property in CSS can do to create such an interesting design effect. I'll definitely be putting this in my toolkit!

Comments 3 total

  • Brian Breeden
    Brian BreedenMay 10, 2020

    That is cool, thanks for sharing!

  • Bayu Angora
    Bayu AngoraMay 11, 2020

    Can we make parallax efect with this?

    • Luis Augusto
      Luis AugustoMay 11, 2020

      Not really, but a fixed background effect like this does make it look like the image is detached from the rest of the content

Add comment