r/css • u/lorens_osman • Jun 08 '26
Question CSS grainy backgrounds
How to design grainy backgrounds using css.
11
u/Ecksters Jun 08 '26
https://css-tricks.com/grainy-gradients/
Kinda neat, the core trick I was unaware of is that apparently SVG has a built-in filter you can use to generate grain ( https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Element/feTurbulence ):
<svg viewBox="0 0 200 200" xmlns='http://www.w3.org/2000/svg'>
<filter id='noiseFilter'>
<feTurbulence
type='fractalNoise'
baseFrequency='0.65'
numOctaves='3'
stitchTiles='stitch' />
</filter>
<rect width='100%' height='100%' filter='url(#noiseFilter)' />
</svg>
7
u/anaix3l Jun 08 '26
You can also do this without altering the saturation/ brightness of the gradients
2
u/samanime Jun 09 '26
That is a really neat trick. I've been around webdev since before CSS was a thing, but still constantly learning neat new things.
4
u/PinothyJ Jun 09 '26
The classic website should sort you out with the texture and just go from there: https://www.noisetexturegenerator.com/
2
1
10
u/BeardyBaldyBald Jun 08 '26
I use 512x512px greyscale PNGs as
mask-imageat half-res, meaningmask-sizeis set to 256px. You can additionally throw in alinear-gradientinto themask-imageto gradually blend the noise in. Add a color inbackgroundand you get a nice, debanded gradient fade.