Hướng dẫn về Cumulative Layout Shift (CLS)

Điều gì Cumulative Layout Shift measures, cách đó score là calculated (impact × distance), session windows, thresholds, đó phổ biến gây ra, và cách sửa và debug them.

Xuất bản lần đầu: 26 thg 6, 2026 · Cập nhật lần cuối: 8 thg 8, 2026 · Advanced
Ngôn ngữ

Cumulative Layout Shift (CLS) là đó Cốt lõi Web Vital cho visual stability — cách nhiều visible nội dung unexpectedly moves trong khi một trang là trong dùng. đây là một unitless score (impact fraction × distance fraction theo shift), và since June 2021 đây là đó largest session window of shifts, không đó lifetime sum. Good là ≤ 0,1 tại đó 75th percentile of trường dữ liệu; 0,1–0,25 cần improvement; > 0,25 là poor. Đó thông thường culprits là unsized images/quảng cáo/iframes/embeds, web fonts, và nội dung injected trên đó fold — cách sửa them by reserving space (width/height hoặc aspect-ratio), tuning font-display, và animating với transform. Lighthouse thường đọc near-0 vì điều này không interact với đó trang hoặc chạy đó đầy đủ trang lifecycle — trường dữ liệu (CrUX) là điều gì Google thực ra ranks on.

Tóm tắt — CLS là Cốt lõi Web Vital cho visual stability. mỗi shift scores as impact fraction × distance fraction; chỉ số itself là largest session window của shifts (≤ 1 s giữa shifts, ≤ 5 s window) — không lifetime sum, mà là Điều gì nó là trước khi June 2021. Good là ≤ 0,1, cần improvement ≤ 0,25, poor > 0,25, tại 75th percentile của trường dữ liệu. chỉ viewport-visible shifts count; shifts trong 500 ms của discrete input là excluded (scrolling không phải). gây ra là unsized images/video/quảng cáo/iframes/ embeds, web fonts, và nội dung injected trên existing nội dung; cácách sửa là reserving space, font-display/size-adjust, và transform-chỉ animation. trap để tránh: Lighthouse (lab) routinely đọc near-0 vì nó không interact với trang hoặc chạy đầy đủ lifecycle — trường dữ liệu (CrUX) là Điều gì Google thực ra measures.

Điều gì CLS measures

Google framing: “Cumulative Layout Shift (CLS) is a stable Core Web Vital metric. It’s an important, user-centric metric for measuring visual stability because it helps quantify how often users experience unexpected layout shifts.” (bản dịch) «Cumulative Layout Shift (CLS) là một chỉ số Cốt lõi Web Vital ổn định và lấy người dùng làm trung tâm, giúp đo độ ổn định hình ảnh bằng cách định lượng tần suất người dùng gặp phải các dịch chuyển bố cục bất ngờ.» Đó operative word là unexpected — nội dung đó moves on của nó own, không vì người dùng đã làm điều gì đó.

nó sits trong Core Web Vitals trio với Largest Contentful Paint (loading) và Interaction để tiếp theo Paint (responsiveness). nơi LCP và INP là timed trong milliseconds, CLS là odd một out: unitless ratio score. đó trips mọi người lên constantly. CLS của 0,05 không phải 50 ms. nó có không time unit tại all.

formula: impact × distance

Theo shift, Google defines nó as:

layout shift score = impact fraction × distance fraction
  • Impact fraction “measures how unstable elements impact the viewport area between two frames” (bản dịch) «measures cách không ổn định elements impact đó viewport area giữa hai frames» — đó combined visible area đó moving elements occupied (trước và sau), as một share of đó viewport.
  • Distance fraction“the greatest horizontal or vertical distance any unstable element has moved in the frame divided by the viewport’s largest dimension (width or height, whichever is greater).” (bản dịch) «đó greatest horizontal hoặc vertical distance bất kỳ không ổn định element có moved trong đó frame divided by đó viewport largest dimension (width hoặc height, whichever là greater).»

Cả hai dimensions quan trọng independently. nhỏ element đó travels across phần lớn của screen và lớn element đó barely nudges có thể score rất differently. web.dev worked ví dụ: impact fraction của 0.75 và distance fraction của 0.25 cho layout shift score của 0.1875.

One shift scores the visible area affected multiplied by the farthest movement relative to the viewport. Nguồn: web.dev

Three cards form the equation. Impact fraction is 0.75: the visible viewport area affected between two frames. Distance fraction is 0.25: the farthest movement divided by the viewport's largest dimension. Multiplying them produces a unitless individual layout-shift score of 0.1875. CLS ultimately keeps the largest session-window total, not a lifetime sum of every shift.

© Patrick Stox LLC · CC BY 4.0 ·

Session windows: part mọi người nhận sai

Ở đây single phần lớn-misstated fact về CLS, và một I phần lớn muốn bạn để take away. CLS không phải sum của all shifts over trang lifetime. nó được sử dụng để là — đó changed trong June 2021.

Hôm nay: “CLS measures the largest burst of layout shift scores for every unexpected layout shift that occurs during the entire lifecycle of a page.” (bản dịch) «CLS measures đó largest burst of layout shift scores cho mỗi unexpected layout shift đó occurs during đó entire lifecycle of một trang.» MỘT burst là một session window: “one or more individual layout shifts occur in rapid succession with less than 1-second in between each shift and a maximum of 5 seconds for the total window duration.” (bản dịch) «một hoặc hơn individual layout shifts occur trong rapid succession với ít hơn 1-second trong giữa mỗi shift và một maximum of 5 seconds cho đó total window duration.» CLS là đó score of đó largest such window — không đó sum, không đó average.

Evidence for this claim CLS uses the largest session window of unexpected layout shifts, with gaps under one second and a maximum five-second window; recent discrete input can exclude a shift. Scope: Current CLS session-window and recent-input rules. Confidence: high · Verified: web.dev: Cumulative Layout Shift

Vì sao đó thay đổi? Đó old sum-mọi thứ definition âm thầm punished dài-lived các trang. MỘT single-trang app hoặc an infinite-scroll feed accumulated hơn CLS chỉ by existing lâu hơn, ngay cả khi mỗi individual shift đã là tiny và well-spaced. Đó Chrome Speed Các chỉ số team moved để một maximum session window để dừng penalizing duration, và chose maximum over average để tránh một perverse outcome nơi sửa một nhỏ, phụ shift có thể làm của bạn score tệ hơn. Khi đó thay đổi rolled out, không origin đã nhận mộtệ hơn score, hầu hết saw không thay đổi, và một slice of chậm-UI và infinite-scroll các trang improved. Nếu bạn đọc an older post đó vẫn says “sum of all shifts,” (bản dịch) «sum of all shifts,» đây là out of date.

Điều gì được tính — và Điều gì không

Three exclusions quyết định Điều gì thực ra lands trong của bạn score:

  • Dưới đó fold không count. Chỉ shifts of nội dung visible trong đó hiện tại viewport là scored. MỘT shift tại đó bottom of một dài trang đó người dùng không bao giờ scrolls để có không impact. Practically, này có nghĩa là sửa trong-viewport shifts là gần như luôn cao hơn ROI hơn chasing shifts way xuống đó trang.
  • Người dùng-initiated shifts nhận một 500 ms truyền. “Layout shifts that occur within 500 milliseconds of user input will have the hadRecentInput flag set, so they can be excluded from calculations.” (bản dịch) «Layout shifts đó occur trong 500 milliseconds of người dùng input sẽ có đó hadRecentInput flag set, so they có thể là excluded từ calculations.» Google stance: shifts “that occur in response to user interactions… are generally fine, as long as the shift occurs close enough to the interaction that the relationship is clear to the user.” (bản dịch) «đó occur trong phản hồi để người dùng interactions… là generally fine, miễn là đó shift occurs close đủ để đó interaction đó đó mối quan hệ là clear để người dùng.» Open an accordion, expand một menu — đó movement là dự kiến, so đây là forgiven.
  • Nhưng scrolling không phải một free truyền. Đó 500 ms exclusion chỉ áp dụng để discrete events — tap, nhấp, keypress. Continuous gestures (scrolling, pinch-zoom) làm không trigger đó exclusion window. Nếu nội dung shifts trong khi ai đó scrolls, đó vẫn được tính. Này phân biệt là sai trong một lot of coverage; nhận điều này right.
Evidence for this claim A layout shift occurring within 500 milliseconds of a qualifying recent user input has hadRecentInput set and is excluded from CLS. Scope: field and lab Confidence: high · Verified: Cumulative Layout Shift (CLS)

Thresholds, và nơi score xuất hiện từ

“To provide a good user experience, sites should strive to have a CLS score of 0.1 or less,” (bản dịch) «Để cung cấp một good người dùng experience, các trang nên strive để có một CLS score of 0,1 hoặc ít hơn,» measured tại “the 75th percentile of page loads, segmented across mobile and desktop devices.” (bản dịch) «đó 75th percentile of trang loads, segmented across mobile và desktop devices.» Đó đầy đủ bands:

Evidence for this claim CLS is good at 0.1 or less and poor above 0.25, assessed at the 75th percentile of page loads. Scope: Current web.dev CLS field thresholds. Confidence: high · Verified: web.dev: Cumulative Layout Shift
  • Good: ≤ 0,1
  • Cần improvement: 0,1 – 0,25
  • Poor: > 0,25
Evidence for this claim CLS is good at 0.1 or less and poor above 0.25, assessed at the 75th percentile of page loads. Scope: Current web.dev CLS field thresholds. Confidence: high · Verified: web.dev: Cumulative Layout Shift

Đó 0,1 line không arbitrary. Google người dùng research được tìm thấy đó “levels of shift from 0.15 and higher were consistently perceived as disruptive, while shifts of 0.1 and lower were noticeable but not excessively disruptive.” (bản dịch) «levels of shift từ 0,15 và cao hơn đã là consistently perceived as disruptive, trong khi shifts of 0,1 và thấp hơn đã là noticeable nhưng không excessively disruptive.» They landed on 0,1 thay vì điều gì đó stricter partly vì bên thứ ba embeds (quảng cáo, social) so commonly nguyên nhân shifts đó một tighter bar sẽ là impractical cho đó real web.

Đó “75th percentile of field data” (bản dịch) «75th percentile of trường dữ liệu» part là load-bearing, mà brings us để đó biggest việc đo lường trap.

Lab so với. trường: Vì sao numbers disagree

Đây là nơi phần lớn mọi người nhận burned. Lighthouse và khác lab tools thường báo cáo CLS near 0,0 trong khi trường dữ liệu — và Google — hiển thị điều gì đó nhiều tệ hơn. khoảng trống không phải either tool là dishonest; nó phạm vi. lab chạy là single, ngắn, scripted trang load: nó không scroll, không nhấp, và không stick khoảng, so nó captures ban đầu-load shifts chỉ. Trường dữ liệu (CrUX) aggregates thực visits across nhiều người dùng, devices, và navigations over rolling window, và CLS là được định nghĩa over đểàn bộ trang lifecycle — menus opening, lazy nội dung loading as người dùng scrolls, muộn quảng cáo filling trong, tuy nhiên dài session chạy. ngắn lab chạy structurally có thể’t see phần lớn của đó.

So practical rule là: sử dụng lab dữ liệu để debug cụ thể shift, và trường dữ liệu để know của bạn thực score. Google ranks on trường dữ liệu từ Chrome Người dùng Experience Báo cáo (CrUX), surfaced trong PageSpeed Insights và Search Console. nếu Lighthouse đọc 0,0 nhưng PageSpeed Insights hiển thị 0,18, treat trường number as một đó reflects của bạn thực tế người dùng — sau đó go reproduce shift trong lab by interacting với trang way thực khách truy cập sẽ. Hai nhiều hơn phạm vi gaps worth knowing: phần lớn tools, including Lighthouse, không propagate iframe layout shifts lên để parent document score mặc dù CrUX có thể reflect them, và RUM được xây dựng on Layout Instability API inherits đó giống nhau iframe blind spot — so của bạn own thực-người dùng monitoring có thể dưới-giải thích CrUX number đó looks tệ hơn Điều gì của bạn đầu tiên-party attribution hiển thị.

phổ biến gây ra

Trong rough order của Cách thường I see them:

  1. Images và video không có dimensions. Không reserved height có nghĩ là mọi thứ dưới jumps Khi media loads.
  2. Quảng cáo, embeds, và iframes không có reserved space. Quảng cáo networks phục vụ dynamic sizes; embeds không announce của họ height trước khi loading.
  3. Dynamically injected nội dung trên existing nội dung. Cookie banners, notification bars, “related” widgets, muộn-loading promos — bất cứ điều gì đó pushes xuống Điều gì đã on screen.
  4. Web fonts (FOIT/FOUT). Khi custom font swaps trong cho fallback, text reflows nếu của họ các chỉ số differ.
  5. Animations on layout-triggering properties. Animating top, left, margin, box-shadow, hoặc box-sizing forces trình duyệt để re-lay-out trang on mỗi frame.

cácách sửa

mỗi khắc phục mirrors của nó nguyên nhân:

  • Images/video — reserve đó space. Set widthheight các thuộc tính so đó trình duyệt computes đó aspect ratio và holds đó box; pair với img { height: auto; width: 100%; } cho responsive behavior, hoặc dùng đó CSS aspect-ratio property. Này là đó single highest-leverage CLS cách sửa on hầu hết các trang.
  • Quảng cáo/embeds/iframes — reserve space cũng. Dùng min-height hoặc aspect-ratio on đó container; cho quảng cáo slots, Google Publisher Tag hướng dẫn là blunt: “Setting a fixed height and width directly on the ad slot div is the most effective way to do this.” (bản dịch) «Setting một fixed height và width trực tiếp on đó quảng cáo slot div là đó hầu hết effective way để làm này.» Cho multi-size slots, reserve cho đó largest configured size. Push muộn-loading nội dung thấp hơn so bất kỳ residual shift là dưới đó fold.
  • Dynamic nội dung — không insert vào đó flow. Reserve một placeholder đó matches đó cuối size, hoặc overlay đó nội dung thay vì injecting điều này. Skeleton loaders chỉ help nếu they match đó cuối dimensions chính xác — một skeleton even vài pixels ngắn hơn đó real nội dung vẫn shifts. Ưu tiên người dùng-triggered loads (“Load hơn”) over surprise insertions.
  • Fonts — match đó các chỉ số. font-display: optional là đó chỉ giá trị với effectively zero CLS risk; swap minimizes invisible text nhưng có thể shift on đó đổi. Tốt hơn vẫn, dùng đó CSS chỉ số overrides — size-adjust, ascent-override, descent-override, line-gap-override — để size đó fallback font để match đó web font so đó đổi là seamless. Preload cốt yếu fonts.
  • Animations — transform chỉ. Animate với transform (translate, scale, rotate) thay vì top/left/margin. Transform-based animations là composited và không trigger layout, so they không shift bất cứ điều gì.

Cách CLS fits vào thứ hạng (giữ nó trong proportion)

CLS là một input để Google trang experience tín hiệu. Google says Cốt lõi Web Chỉ số quan trọng là điều gì đó của nó xếp hạng các hệ thống dùng — nhưng hiện tại Tìm kiếm tài liệu không publish an chính xác CLS weight, một tiebreaker rule, hoặc một xếp hạng bảo đảm, so treat bất kỳ cụ thể mechanism (including “it’s a tiebreaker” (bản dịch) «đây là một tiebreaker») as một hoạt động approximation, không một được ghi lại fact. My standing advice across mọi thứ I ghi về Core Web Vitals: nhận vào đó “good” band và move on. Hầu hết các trang sẽ không see một có ý nghĩa xếp hạng hoặc business lift từ grinding 0,08 xuống để 0,02, và một single score rarely giải thích một revenue hoặc conversion outcome by itself. CLS là bảng stakes — bạn muốn để clear đó bar, nhưng điều này không nên become đó centerpiece of của bạn SEO program tại đó expense of LCP, INP, hoặc, frankly, của bạn thực tế nội dung.

Hai operational notes đó save lot của confusion:

  • CrUX lags ~28 days. đây là một rolling 28-day window, so một cách sửa bạn ship hôm nay sẽ không fully register trong PageSpeed Insights hoặc Search Console cho weeks. không panic khi đó number không move đó tiếp theo morning.
  • Đó attributed element là thường không đó root nguyên nhân. Đó Layout Shift Attribution API tells bạn mà element moved, nhưng as web.dev notes, “it’s possible that these elements are only indirectly related to the ‘root cause’ of layout instability.” (bản dịch) «đây là có thể đó những elements là chỉ indirectly related để đó ‘root nguyên nhân’ of layout instability.» Đó text đó jumped là thường đó victim of an unsized image trên điều này loading muộn — cách sửa đó nguyên nhân, không đó symptom. Hoạt động điều này as một timestamp-để-trigger loop: note đó shift bắt đầu time, thì kiểm tra điều gì khác changed trong đó giống nhau window — một network yêu cầu finishing, an image hoặc font arriving, một resize, hoặc một class/style thay đổi — và treat đó attributed node as một lead, không proof, until bạn đã khớp điều này để đó trigger.

Add an expert note

Pin an expert quote

New person? Create their unclaimed profile at /admin/experts/ → Pin a quote first.