中文
2026 · 摄影集夜行
Night Walk
Background & decoration · CSS only

Grain overlay

动态噪点颗粒

A fine film-grain noise layer over the section that keeps jittering.

Also searched as: 给背景加一层胶片颗粒, 画面上细细的噪点在抖动, 老胶片质感的背景, 颗粒感噪点背景

AI Markdown (.md)
Placement
Background
Mood
Refined, Dramatic
Trigger
一直循环
Site types
个人网站, 作品集

How it works & accessibility

An oversized SVG feTurbulence noise layer sits on top, jumps between eight fixed offsets with steps(1, end) and returns to the start each loop; it ignores clicks, is hidden from screen readers, and stays still (grain kept) under reduced motion.

Best for: Background (一直循环).

Reduced motion: 不抖,噪点留着(静止的颗粒)

Mobile & touch: 和桌面一样;噪点图是当图片用的 SVG,浏览器只画一次、缓存起来平铺,动起来只挪位置,不每帧重算滤镜

Key parameters

ParameterKeyDefaultRangeNotes
一圈抖动多久duration800ms——
噪点浓度intensity12%——

Ready-to-paste AI prompt

Add “Grain overlay” to the background in my project: An oversized SVG feTurbulence noise layer sits on top, jumps between eight fixed offsets with steps(1, end) and returns to the start each loop; it ignores clicks, is hidden from screen readers, and stays still (grain kept) under reduced motion.
Parameters: duration: 800ms, intensity: 12%.
Preserve existing content and layout. Respect prefers-reduced-motion by showing the final state. Content must remain visible if JavaScript fails or is disabled.
Reference: https://donglang.linter.top/effects/grain-overlay.md (canonical specification and reference code).

Dependency-free reference code

CSS
/* 动态噪点颗粒(Grain overlay)· 只用 CSS,不需要脚本。画面上盖一层细细的噪点,一直轻轻地抖,像老胶片的颗粒。
   参考 Animation Handbook 的 grain-overlay 的做法(MIT),自己实现,没有复制代码。
   用法:区块加 class="grain",最后放 <span class="gr-noise" aria-hidden="true"></span>。
   - 噪点图是 SVG 的 feTurbulence 生成的:去掉颜色、整张不透明、把明暗拉开(颗粒更清楚,浅色背景上也看得出来),
     写在下面的 background-image 里,200px 一块平铺,不用另外的图片文件。SVG 是当图片用的:浏览器画好一块缓存起来平铺,
     动起来只挪位置(交给显卡),不会每一帧重算滤镜,手机上也不费电。
   - 噪点层上下左右各比区块多出一半(一共大一倍),一圈里跳 8 个位置(每个位置停住,到下一段才跳,steps(1, end)),首尾都回到原位;
     跳的距离最多是自己宽高的 6%,比多出来的那一半小得多,边永远露不出来;区块把多出来的部分裁掉(overflow: hidden)。
   - 噪点层盖在内容上面(区块是一个独立的层叠上下文),不挡点击(pointer-events: none),读屏读不到(aria-hidden)。
   - 区块要有定位(relative、absolute、sticky 都行):默认的 position: relative 写在 :where() 里,网站自己写的定位优先;
     但别在区块上写 position: static(噪点层会跑到更外层的定位祖先里,可能溢出 overflow: hidden)。
   - --gr-intensity:噪点浓度,就是噪点层的透明度(12% 很淡;深色背景上最明显,太浓字会看不清);--gr-duration:一圈抖动多久。
   - 开启"减少动态"时:不抖,噪点留着(静止的颗粒)。 */
/* 默认值和定位写在 :where() 里(不占优先级):网站自己在 .grain 上改的变量、区块自己写的定位(absolute、sticky 这些),
   不管写在这段代码前面还是后面,都用网站自己的 */
:where(.grain) {
  --gr-duration: 800ms;
  --gr-intensity: 12%;
  position: relative;
}
.grain {
  overflow: hidden;
  isolation: isolate;
}
.gr-noise {
  position: absolute;
  inset: -50%;
  z-index: 1;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='matrix' values='0.33 0.33 0.33 0 0 0.33 0.33 0.33 0 0 0.33 0.33 0.33 0 0 0 0 0 0 1'/%3E%3CfeComponentTransfer%3E%3CfeFuncR type='linear' slope='3' intercept='-1'/%3E%3CfeFuncG type='linear' slope='3' intercept='-1'/%3E%3CfeFuncB type='linear' slope='3' intercept='-1'/%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
  background-size: 200px;
  opacity: var(--gr-intensity);
  animation: gr-jitter var(--gr-duration) steps(1, end) infinite;
}
/* 8 个位置(自己宽高的百分比),每段停在自己开头的位置,到下一段才跳;100% 回到原位,一圈接得上 */
@keyframes gr-jitter {
  0% { translate: 0 0; }
  12.5% { translate: -3% 4%; }
  25% { translate: 5% -3%; }
  37.5% { translate: -4% -6%; }
  50% { translate: 6% 2%; }
  62.5% { translate: -2% 5%; }
  75% { translate: 3% -5%; }
  87.5% { translate: -5% 3%; }
  100% { translate: 0 0; }
}
@media (prefers-reduced-motion: reduce) {
  .gr-noise { animation: none; }
}
HTML
<!-- 动态噪点颗粒:区块加 class="grain",内容照常写,最后放噪点层 -->
<section class="grain" style="background: #1f2430; color: #f5f1e8">
  <h1>夜行</h1>
  <p>2026 年的街头摄影</p>
  <span class="gr-noise" aria-hidden="true"></span>
</section>

More in Background & decoration

Browse all 86 effects →

Shown once per release · Always available in changelog