Use a linear gradient on the border or fill of a background container so that it fades out of view.
This is an expressive choice, so you can use it whenever you like. But it has some practical benefits. For example, if the background is varied the container might be visible when it helps contrast the most, and fade away when it doesn’t.
If the background container around the foreground element is there to help provide contrast between the element and its background, then fading it out isn’t a good idea.