How to Find the LCP Element for Core Web Vitals
The LCP (Largest Contentful Paint) element for Core Web Vitals can be found by reading largest-contentful-paint entries with the browser's PerformanceObserver. When Lighthouse or PageSpeed Insights reports that LCP is slow but you cannot tell which image or heading on the page to fix, this is the element to identify first. Here I use three methods to find the LCP element: a snippet pasted into the DevTools console, the web-vitals library, and Lighthouse. I include the results exactly as they came out in my test environment.
The test environment was Ubuntu 24.04, Node.js 22, Lighthouse 13.6.0, and web-vitals 6.2.3. For the browser, I used Chrome for Testing 153, which is bundled with Playwright 1.63.0. For the console snippet, I opened the page with Playwright, ran the snippet 1.5 seconds after load, and recorded the text printed to the console. The run-snippet.mjs in the body is the test script that performs this procedure. wv.mjs opens the page in the same way and reads the web-vitals result. The screen sizes were 412×823 for a mobile setup and 1350×940 for a desktop setup. I served the test pages from a small server running in the test environment (localhost:8080, HTTP/1.1). I did not test the DevTools Performance panel UI, PageSpeed Insights, real-user data (CrUX), or results on a live public site.
What Can Be the LCP Element
According to web.dev's LCP explanation, the following can be an LCP element:
<img>elements<video>elements<image>elements inside<svg>- Elements that load a background image with the CSS
url()function (gradients are not included) - Block-level elements that contain text
Size is determined by the part visible within the viewport. Parts that overflow or are clipped are not counted. For text elements, the size is that of the smallest rectangle enclosing all the text. Because the page is painted progressively, the largest element can change during rendering.
List the LCP Candidates in Order with a Console Snippet
LCP candidates come out one at a time as largest-contentful-paint entries. If you paste the following snippet into the DevTools console and run it, it prints the candidates in chronological order and adds a pink outline (outline) to the element of the last candidate.
// Paste into the DevTools console and run. Prints LCP candidates in order and outlines the last one
new PerformanceObserver((list) => {
const entries = list.getEntries();
for (const e of entries) {
const el = e.element;
const name = el
? el.tagName.toLowerCase() + (el.id ? '#' + el.id : '') + (el.className ? '.' + el.className : '')
: '(要素なし)';
console.log(`${Math.round(e.startTime)}ms size=${e.size} ${name} url=${e.url || '(なし)'}`, el);
}
entries.at(-1).element?.style.setProperty('outline', '4px solid #d85878');
}).observe({ type: 'largest-contentful-paint', buffered: true });
As described on MDN's LargestContentfulPaint page, passing buffered: true also delivers entries that were emitted before the snippet ran. Even if you paste the snippet after the page has finished loading, you still get all the candidates from during loading. The main properties of an entry are:
| Property | Contents |
|---|---|
element |
The element that is the LCP at that moment |
size |
The area of the element (width × height) |
url |
For an image element, the URL of the image request |
startTime |
The time it was painted (same value as renderTime) |
For the second argument of console.log, I pass the element itself (el). In my test, I recorded the console text with Playwright, so this part shows up as JSHandle@node.
A Heading Becomes a Candidate First, and an Image Replaces It Later
The page I tested had a large image below a heading. The server delayed the image by 1000 milliseconds before responding.
<h1>猫の手日記</h1>
<img src="/slow/hero.jpg" alt="水色のもようの大きな画像" width="1200" height="675">
<p>大きな画像の下に、短い段落があります。</p>
Here is the result of opening the page at mobile width and running the snippet.
$ node run-snippet.mjs candidates.html mobile
candidates.html mobile 412x823 153.0.8010.12
console: 36ms size=5868 h1 url=(なし) JSHandle@node
console: 1032ms size=81320 img url=http://localhost:8080/slow/hero.jpg JSHandle@node
At 36 milliseconds, the h1 first became the candidate, and at 1032 milliseconds, when the image was painted, the img replaced it. The LCP element is the img, which is the last candidate shown. Do not conclude from the first line alone that the LCP is the heading; check the bottom line.
The size of the image at mobile width was 81320. This is because the 1200×675 image is displayed scaled down to 380×214. When I opened the page at desktop width (1350×940), the size was 810000 (1200×675). The size depends on the size shown on screen, not on the original image dimensions.
The LCP Element Can Change with Screen Width
Even on the same page, the LCP element can change depending on the screen width. The page I tested had a 600px-wide image and a long paragraph side by side, which wrap vertically on a narrow screen.
<div class="wrap">
<img src="/side.jpg" alt="水色のもようの画像" width="600" height="400">
<p class="lead">きょうは、朝から窓のそばで日なたぼっこをしました。…(長い段落)</p>
</div>
.wrap{display:flex;flex-wrap:wrap;gap:16px;align-items:flex-start}
.wrap img{width:600px}
.wrap p{flex:1 1 300px;margin:0;line-height:1.8}
Here are the results of running the snippet at mobile and desktop widths.
$ node run-snippet.mjs layout.html mobile
layout.html mobile 412x823 153.0.8010.12
console: 48ms size=136488 p.lead url=(なし) JSHandle@node
$ node run-snippet.mjs layout.html desktop
layout.html desktop 1350x940 153.0.8010.12
console: 64ms size=240000 img url=http://localhost:8080/side.jpg JSHandle@node
At mobile width, the paragraph (p.lead) was the LCP element; at desktop width, the image (img) was. At mobile width the image shrank to 380×253 and the paragraph stretched vertically to 380×374, so the paragraph became the larger element.


When I opened the same page at desktop width again to take the screenshot, the paragraph became a candidate at 44 milliseconds and was replaced by the image at 48 milliseconds. The order of intermediate candidates differed between the first and second runs. In both runs, the last candidate was the image.
If the mobile results in PageSpeed Insights or Lighthouse are poor, open the page at mobile width to investigate. The element you see on a desktop screen is not necessarily the LCP element.
When a Background Image Is the LCP Element
A hero section using a CSS background image can also be the LCP element.
<style>
.hero{aspect-ratio:16/9;background:url(/hero.jpg) center/cover}
</style>
<div class="hero" id="top-visual"></div>
$ node run-snippet.mjs background.html desktop
background.html desktop 1350x940 153.0.8010.12
console: 52ms size=810000 div#top-visual.hero url=http://localhost:8080/hero.jpg JSHandle@node
The element was the div holding the background image, and url contained the background image's URL. If you search the HTML for an <img> and cannot find the LCP element, suspect a background-image element as well.
Get the LCP Element as a Selector String with web-vitals
To collect LCP elements from real users' browsers, you can use the attribution build of onLCP from web-vitals. The web-vitals README describes the attribution build as intended for investigating issues that occur for real users. attribution.target contains a selector string representing the LCP element. In my test, I injected the following code before page load using Playwright's addInitScript.
// Added after the contents of web-vitals.attribution.iife.js
webVitals.onLCP((m) => {
window.__lcp = { value: m.value, target: m.attribution.target, url: m.attribution.url };
}, { reportAllChanges: true });
According to the README, passing reportAllChanges: true causes the callback to run each time a new LCP candidate appears. In my test, I read the last value received.
$ node wv.mjs layout.html mobile
layout.html mobile {"value":48,"target":"html>body>div.wrap>p.lead"}
$ node wv.mjs layout.html desktop
layout.html desktop {"value":56,"target":"html>body>div.wrap>img","url":"http://localhost:8080/side.jpg"}
$ node wv.mjs background.html mobile
background.html mobile {"value":48,"target":"#top-visual","url":"http://localhost:8080/hero.jpg"}
As with the snippet, the paragraph was the element at mobile width and the image at desktop width. For the background-image div with an id, the target was the short string #top-visual.
If the selector string is hard to read, the generateTarget option lets you change how the string is built. The README has an example that returns the element's data-name attribute.
The Element Also Appears in Lighthouse's LCP Breakdown
In Lighthouse 13, the element for LCP appears in the report's "LCP breakdown" item. In the result JSON, it is the item with type set to node inside the details of lcp-breakdown-insight. I used a script (lcp-element.mjs) that extracts the selector and HTML snippet from there and read the results for the mobile preset (the default) and the desktop preset (--preset=desktop). I ran Lighthouse as follows.
$ npx lighthouse http://localhost:8080/layout.html --only-categories=performance --output=json --output=html --output-path=out/layout-mobile --chrome-flags="--headless=new --no-sandbox" --quiet
This is the output extracting the LCP element from the result JSON.
$ node lcp-element.mjs out/layout-mobile.report.json
mobile screen=412x823 LCP=0.8 s
selector: body > div.wrap > p.lead
snippet: <p class="lead">
size: 380x374
$ node lcp-element.mjs out/layout-desktop.report.json
desktop screen=1350x940 LCP=0.3 s
selector: body > div.wrap > img
snippet: <img src="/side.jpg" alt="水色のもようの画像" width="600" height="400">
size: 600x400
Lighthouse's screen sizes were 412×823 for the mobile preset and 1350×940 for the desktop preset. As with the snippet and web-vitals, the LCP element was the paragraph on mobile and the image on desktop. For this page, when I matched the screen width to Lighthouse's, all three methods reported the same element.
The LCP element is the element of the last largest-contentful-paint entry that was emitted. It can change with screen width, so check at the same width as the setting where the score was poor (mobile or desktop).
According to web.dev's LCP explanation, the browser stops emitting new entries once the user has interacted with the page through a tap, scroll, or keypress. A large image that appears after such an interaction will not show up as an LCP candidate.





