# 累积布局偏移

**累积布局偏移**（Cumulative Layout Shift，CLS）是一项无量纲的网页性能指标，由谷歌设计，是[核心网页指标](https://www.edgepedia.org/zh/core-web-vitals)（Core Web Vitals）之一，用于衡量页面整个生命周期内发生的最大一波意外布局偏移分数。<sup>[1](https://web.dev/articles/cls)</sup><sup> • </sup><sup>[2](https://developer.mozilla.org/en-US/docs/Glossary/CLS)</sup> 它量化的是视觉稳定性：用户阅读或与页面交互时，可见内容发生意外移动的程度。每一次单独的偏移由 [Performance API](https://www.edgepedia.org/zh/performance-api) 的 `LayoutShift` 接口测量，再汇总为页面级分数。<sup>[2](https://developer.mozilla.org/en-US/docs/Glossary/CLS)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义 | 页面整个生命周期内，每一次意外布局偏移分数中最大的那一波（会话窗口）<sup>[1](https://web.dev/articles/cls)</sup> |
| 单次偏移分数 | 影响分数 × 距离分数；示例：0.75 × 0.25 = 0.1875<sup>[1](https://web.dev/articles/cls)</sup><sup> • </sup><sup>[3](https://wicg.github.io/layout-instability/)</sup> |
| 会话窗口 | 相邻偏移间隔小于 1 秒，窗口总时长上限为 5 秒<sup>[1](https://web.dev/articles/cls)</sup> |
| 阈值 | 良好：0.1 或以下；较差：大于 0.25（以页面加载的第 75 百分位计）<sup>[1](https://web.dev/articles/cls)</sup> |
| 豁免 | 用户输入后 500 毫秒内的偏移带有 `hadRecentInput` 标志，可予以排除<sup>[1](https://web.dev/articles/cls)</sup> |
| 实地通过率 | 2025 年：72% 的桌面页面和 81% 的移动页面达到良好 CLS<sup>[4](https://almanac.httparchive.org/en/2025/performance)</sup> |
| Lighthouse 权重 | 占 Lighthouse 10 性能得分的 25%<sup>[5](https://developer.chrome.com/blog/lighthouse-10-0)</sup> |

## 分数如何计算

每一次单独的布局偏移，其分数为两个分数之积。影响分数是影响区域的面积——即不稳定元素在两个帧中的可见区域的并集——除以视口面积（若视口面积为 0，则为 0）。<sup>[3](https://wicg.github.io/layout-instability/)</sup> 若偏移发生时视口已被完全填满，影响分数为 1。<sup>[6](https://doi.org/10.1109/qomex55416.2022.9900881)</sup> 距离分数的计算方式为：取任一不稳定元素在该帧内水平或垂直方向移动的最远距离，再除以视口的长边（宽或高）。<sup>[1](https://web.dev/articles/cls)</sup> 规范将距离分数上限定为 1.0。<sup>[3](https://wicg.github.io/layout-instability/)</sup> 引入距离分数是为了避免对“大元素小幅移动”的情形惩罚过重。<sup>[1](https://web.dev/articles/cls)</sup>

\[ \text{布局偏移分数} = \text{影响分数} \times \text{距离分数} \]

在 web.dev 记载的示例中，影响分数为 0.75，距离分数为 0.25，得分为 0.75 × 0.25 = 0.1875。<sup>[1](https://web.dev/articles/cls)</sup> 一项 2023 年发表的同行评审研究以 Cookie 同意横幅作为偏移的受控成因，结果表明，当横幅将内容向下推时，距离分数——即横幅高度相对于视口大小的比例——可以完全决定 CLS 分数。<sup>[7](https://link.springer.com/article/10.1007/s41233-023-00058-3)</sup>

页面级分数并非简单的全生命周期累加。偏移会被归入会话窗口：即一连串一次或多次偏移，相邻偏移间隔小于 1 秒，窗口总时长上限为 5 秒。页面的 CLS 就是最大的那个会话窗口的累计分数。<sup>[1](https://web.dev/articles/cls)</sup> 后代浏览上下文（iframe）内的偏移通过子框架权重因子计入，该因子定义为子浏览上下文视口占顶层视口的比例。<sup>[3](https://wicg.github.io/layout-instability/)</sup> 页面进入后台时，以及卸载时，都应上报最终分数，使用 `visibilitychange` 事件即可覆盖这两种情形。<sup>[1](https://web.dev/articles/cls)</sup>

阈值按页面加载的第 75 百分位评估，并分移动端与桌面端：良好 CLS 为 0.1 或以下，较差为大于 0.25。<sup>[1](https://web.dev/articles/cls)</sup> 站点应力争至少 75% 的页面访问 CLS 在 0.1 或以下。<sup>[8](https://web.dev/articles/optimize-cls)</sup>

## 什么算作布局偏移

只有当已存在的可见元素在帧与帧之间改变了起始位置时，才会记录为布局偏移。向 DOM 中添加新元素，或改变现有元素的大小，只要该变化没有导致其他可见元素的起始位置发生变化，就不计入。<sup>[1](https://web.dev/articles/cls)</sup>

“意外”这一定语通过用户输入来落实。用户输入后 500 毫秒内发生的布局偏移会设置 `hadRecentInput` 标志，因此可从计算中排除；交互后 500 毫秒内的偏移视为预期内。<sup>[1](https://web.dev/articles/cls)</sup><sup> • </sup><sup>[8](https://web.dev/articles/optimize-cls)</sup> 该豁免有边界：用户滚动时懒加载内容导致的页面偏移仍算作意外，因为滚动不属于能获得豁免窗口的那类交互。<sup>[8](https://web.dev/articles/optimize-cls)</sup>

## 常见原因与修复

布局偏移的主要成因包括：未指定尺寸的图片、广告、未指定尺寸的嵌入内容和 iframe、动态注入的内容以及网页字体。<sup>[8](https://web.dev/articles/optimize-cls)</sup> 每种都有标准修复方法：

- **未指定尺寸的媒体。** 为图片和视频设置 `width` 和 `height` 属性，可让浏览器在加载时预留正确空间；CSS 的 `aspect-ratio` 属性是另一种选择。<sup>[8](https://web.dev/articles/optimize-cls)</sup>
- **广告与嵌入内容。** 唯一能保证避免广告布局偏移的方法，是用 CSS 为广告位预留足够空间，在广告位 `div` 上设置固定的高度和宽度最为有效。<sup>[9](https://developers.google.com/publisher-tag/guides/minimize-layout-shift)</sup> 谷歌还推荐使用 `min-height` 和 `min-width`，这样既预留了最小空间，又允许浏览器在投放更大尺寸的广告素材时扩大容器。<sup>[9](https://developers.google.com/publisher-tag/guides/minimize-layout-shift)</sup>
- **网页字体。** `font-display: optional` 可避免重新布局；`size-adjust`、`ascent-override`、`descent-override` 和 `line-gap-override` 等 API 可尽量缩小备用字体与网页字体之间的尺寸差异。<sup>[8](https://web.dev/articles/optimize-cls)</sup>
- **策略控制。** 研究人员对浏览器策略特性（包括 `unsized-media`、`layout-animations` 和 `font-display-late-swap`）做了每项 20 次测试，结果表明此类控制可缓解未指定尺寸媒体和字体延迟替换造成的布局不稳定；在 `unsized-media` 策略下，违规图片会被替换为占位符。<sup>[10](https://ar5iv.labs.arxiv.org/html/2111.09960)</sup>

## CLS 在核心网页指标中的位置

CLS 是三项核心网页指标之一，另两项是[最大内容绘制](https://www.edgepedia.org/zh/largest-contentful-paint)（Largest Contentful Paint，LCP）——一项加载指标，以及交互到下次绘制（Interaction to Next Paint，INP）——一项交互响应性指标。<sup>[11](https://www.searchenginejournal.com/google-explains-how-cumulative-layout-shift-cls-is-measured/529987/)</sup> 与以秒或毫秒计的 LCP、INP 不同，CLS 是无量纲的：它结合了可见内容移动了多少与元素移动了多远，而不是测量一段时长。<sup>[8](https://web.dev/articles/optimize-cls)</sup><sup> • </sup><sup>[11](https://www.searchenginejournal.com/google-explains-how-cumulative-layout-shift-cls-is-measured/529987/)</sup> 它属于以用户为中心的网页指标家族，学界更青睐这类指标，而非文档完成时间（onLoad）之类更简单却不准确的度量。<sup>[12](https://dl.acm.org/doi/10.1145/3027947.3027949)</sup> 已有学术工作考察了包括 CLS 在内的核心网页指标与实际用户体验质量之间的关系。<sup>[6](https://doi.org/10.1109/qomex55416.2022.9900881)</sup>

## 数据一览

实地数据表明，自该指标推出以来已有显著改善。在 2021 年《网络年鉴》中，桌面和移动网站均有 62% 达到良好 CLS（低于 0.1），15% 的桌面站点和 17% 的移动站点被归为较差（达到或超过 0.25）。<sup>[13](https://almanac.httparchive.org/en/2021/performance)</sup> 到 2025 年 7 月，72% 的桌面页面和 81% 的移动页面达到良好 CLS 分数；桌面页面“需要改进”的比例更高（17%，移动端为 10%），而各设备上较差的比例相近，约为 9% 到 10%。<sup>[4](https://almanac.httparchive.org/en/2025/performance)</sup>

一项针对 2026 年第二季度手机实地数据、覆盖 189,915 个站点的站点级分析报告称，88.8% 的站点 CLS 在 0.10 或以下，典型站点为 0.00，75% 的站点低于 0.02，仅 11.2% 未通过；全部站点中有 73.8% 位于 0.00 至 0.02 之间，最差的 10% 高于 0.12，最差的 1% 高于 0.73。<sup>[14](https://www.corewebvitals.io/state-of-cwv/explorer/cwv/cls)</sup> 页面级（《网络年鉴》）与站点级（State of Web Vitals）数据来自不同总体和不同时间段，不应取平均。

移动端与桌面端体验存在结构性差异。响应式或移动端布局可能暴露出在较大视口中不会出现的布局偏移，例如仅移动端才有的导航元素。<sup>[15](https://developer.chrome.com/blog/devtools-realtime-cwv)</sup>

## 在实际中测量 CLS

测量 CLS 的工具包括 Chrome 用户体验报告（CrUX）、PageSpeed Insights、搜索控制台、web-vitals [JavaScript](https://www.edgepedia.org/zh/javascript) 库、Chrome 开发者工具、[Lighthouse](https://www.edgepedia.org/zh/lighthouse) 和 WebPageTest。<sup>[1](https://web.dev/articles/cls)</sup> web-vitals 库提供了一个参考 JavaScript 实现，所有调试工具——包括浏览器开发者工具中的那些——都使用底层的 `LayoutShift` API，该 API 可将偏移信息输出到控制台或发送到服务器端点。<sup>[1](https://web.dev/articles/cls)</sup><sup> • </sup><sup>[16](https://developer.mozilla.org/en-US/docs/Web/API/LayoutShift)</sup> Chrome 开发者工具的性能面板会实时显示本地的核心网页指标，包括 CLS 和 INP，并按良好/较差阈值着色；其实地数据来自公开的 CrUX API，是按页面和来源对真实用户体验做的 28 天聚合。<sup>[15](https://developer.chrome.com/blog/devtools-realtime-cwv)</sup>

实验室值与实地值因结构性原因而存在差异。实验室工具在合成环境中加载页面，只能测量页面加载期间的偏移，因此实验室 CLS 可能低于实地 CLS。<sup>[1](https://web.dev/articles/cls)</sup> CrUX 测量页面整个生命周期的 CLS，而 Lighthouse 等实验室工具通常只测量初始页面加载。<sup>[8](https://web.dev/articles/optimize-cls)</sup> 此外，iframe 中发生的 CLS 无法通过 Web API 测量，但用户看得见，因此会被纳入 CrUX 数据。<sup>[8](https://web.dev/articles/optimize-cls)</sup>

Lighthouse 对 CLS 赋予了很高的权重：在 Lighthouse 10 中，可交互时间被移除，其 10% 的分数权重转移给了 CLS，使 CLS 占到整体性能得分的 25%。在对最新一轮 HTTP Archive 中 1300 万次页面加载的分析中，90% 的页面在此改动后得分会提高，其中 50% 提高超过 5 分。<sup>[5](https://developer.chrome.com/blog/lighthouse-10-0)</sup>

## 指标的历史与演进

当前定义只计最大的那一波偏移，而非页面上的每一次偏移。<sup>[1](https://web.dev/articles/cls)</sup> Chrome 的实现也不断调整以符合规范；自 Chrome 86 起，实现使用布局溢出矩形，该矩形包含位于任何片段盒边界内的所有点。<sup>[17](https://chromium.googlesource.com/chromium/src/+/main/docs/speed/metrics_changelog/2020_10_cls.md)</sup> 布局不稳定性规范还会报告最多五个 DOM 元素的采样，这些元素的偏移对该帧偏移值贡献最大，按影响面积降序排列，为调试工具中的归因提供支持。<sup>[3](https://wicg.github.io/layout-instability/)</sup> 一项 2024 年关于网站性能预测文献的系统综述，将累积布局偏移列为衡量加载期间影响视觉稳定性和用户体验的意外布局偏移的标准指标。<sup>[18](https://www.mdpi.com/2073-431X/14/10/446)</sup>

## References

1. [Cumulative Layout Shift (CLS), web.dev](https://web.dev/articles/cls)
2. [Cumulative Layout Shift (CLS), MDN Glossary](https://developer.mozilla.org/en-US/docs/Glossary/CLS)
3. [Layout Instability API, W3C/WICG draft specification](https://wicg.github.io/layout-instability/)
4. [Performance, The Web Almanac 2025, HTTP Archive](https://almanac.httparchive.org/en/2025/performance)
5. [What's new in Lighthouse 10, Chrome for Developers](https://developer.chrome.com/blog/lighthouse-10-0)
6. [A Vital Improvement? Relating Google's Core Web Vitals to Actual Web QoE, QoMEX 2022](https://doi.org/10.1109/qomex55416.2022.9900881)
7. [Do you agree? Contrasting Google's Core Web Vitals and the impact of cookie consent banners with actual web QoE, Quality and User Experience (2023)](https://link.springer.com/article/10.1007/s41233-023-00058-3)
8. [Optimize Cumulative Layout Shift, web.dev](https://web.dev/articles/optimize-cls)
9. [Minimize layout shift, Google Publisher Tag](https://developers.google.com/publisher-tag/guides/minimize-layout-shift)
10. [Reining in Mobile Web Performance with Document and Permission Policies, arXiv 2111.09960](https://ar5iv.labs.arxiv.org/html/2111.09960)
11. [Google Explains How Cumulative Layout Shift (CLS) Is Measured, Search Engine Journal](https://www.searchenginejournal.com/google-explains-how-cumulative-layout-shift-cls-is-measured/529987/)
12. [Measuring the Quality of Experience of Web users, ACM SIGCOMM CCR](https://dl.acm.org/doi/10.1145/3027947.3027949)
13. [Performance, The Web Almanac 2021, HTTP Archive](https://almanac.httparchive.org/en/2021/performance)
14. [CLS distribution: The State of Web Vitals 2026](https://www.corewebvitals.io/state-of-cwv/explorer/cwv/cls)
15. [Monitor your local and real-user Core Web Vitals performance in DevTools, Chrome for Developers](https://developer.chrome.com/blog/devtools-realtime-cwv)
16. [LayoutShift, MDN Web API reference](https://developer.mozilla.org/en-US/docs/Web/API/LayoutShift)
17. [Cumulative Layout Shift Changes in Chrome 86, Chromium source docs](https://chromium.googlesource.com/chromium/src/+/main/docs/speed/metrics_changelog/2020_10_cls.md)
18. [Predicting Website Performance: A Systematic Review of Metrics, Methods, and Research Gaps (2010–2024), MDPI Computers](https://www.mdpi.com/2073-431X/14/10/446)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Web development and web-platform technologies › Web performance metrics

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/cumulative-layout-shift

English original: https://www.edgepedia.org/cumulative-layout-shift
