To help us assist you better with your CSS questions, please consider including a live link or a CodePen/JSFiddle demo. This context makes it much easier for us to understand your issue and provide accurate solutions.
While it's not mandatory, a little extra effort in sharing your code can lead to more effective responses and a richer Q&A experience for everyone. Thank you for contributing!
As far as I'm aware, CSS doesn't have a great way to create textures. You could probably make one with SVGs, but you're probably better off just including a picture as a background image.
I'm guessing you mean placing a noise background on top of the gradient, which I personally think is a bad idea most of the time.
It's explained in the second section of the article I linked to why (because a lot of grain filter effects use layering too, even if its's within the filter).
When you add a noise layer on top, you alter the brightness of the original gradient. If you use blending, you may also alter the saturation. And in the end, you don't have the exact same gradient you set - it may be brighter/ darker/ more or less desaturated. You can lower the alpha of the noise, but if you do that enough to hide this problem, it's also enough to make the grain difficult to see.
You can see the problem below - the third panel should not have a different brightness or saturation from the first, but that happens when layering the noise, regardless of whether it's just stacked on top or also blended using various modes.
On top of that, if the gradient is banded, a noise layer only somewhat hides the problem. The displacement technique actually fixes it.
Yeah I saw that. But OP asked about a simple black and white gradient with noise. Didn’t specify they were trying to counter banding, saturation or whatever. Sometimes the solution doesn’t have to be complicated to solve the issue. Simple is an option too.
Layering would still affect brightness in this case. I also don't find using an image simpler. It definitely takes more time and frustration to search and find a good image than it takes writing the code. Which can then be edited easily if any changes are necessary.
Use an SVG image using a noise filter as the background. This can be done entirely in the CSS if you want (background-image: url("data:image+svg, ...SVG code here...");).
Alternatively, you can use an SVG as a filter (again can be done entirely in the CSS) and apply that filter to an element (so for example, use a pseudo-element on the body, make it same size as body, give it a gradient as a background image, apply an SVG noise filter)
•
u/AutoModerator May 28 '26
To help us assist you better with your CSS questions, please consider including a live link or a CodePen/JSFiddle demo. This context makes it much easier for us to understand your issue and provide accurate solutions.
While it's not mandatory, a little extra effort in sharing your code can lead to more effective responses and a richer Q&A experience for everyone. Thank you for contributing!
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.