Core Web Vitals LCP Becomes the Cookie Consent Banner
On narrow smartphone screens, the long text in a Cookie consent banner can take up more area than the image on the page. When that happens, the banner text becomes the LCP (Largest Contentful Paint) element for Core Web Vitals, and the LCP value becomes the time the banner was displayed. On the page I tested, a consent banner that appeared later delayed LCP from 832ms to 2,032ms. When I shortened the banner text, the LCP element went back to the image, at 832ms.
This article is for when you have added a Cookie consent banner (a consent management tool, or CMP) and Lighthouse or PageSpeed Insights starts showing the banner text as the LCP element. It explains how to confirm the cause and fix it.
The test environment was Ubuntu 24.04, Node.js 22.23.4, web-vitals 6.2.3, Playwright 1.63.0, and Lighthouse 13.6.0. For the browser, I used Chrome for Testing 153, which is bundled with Playwright. The page was served from a server written with Node.js's http module (localhost:8080), and the script that shows the consent banner was served from a different origin (127.0.0.1:8081). I did not throttle the network. The server waited 800ms before returning the hero image (1200×675, a JPEG of about 277KB) and 2,000ms before returning the consent banner script. I opened the page in Playwright with a 412px wide by 823px high viewport and measured LCP with web-vitals five times per page. I did not test a real consent management tool, PageSpeed Insights, real user data (CrUX), or browsers other than Chrome. This article does not cover what the banner needs to say.
- 1. A block of text can also be the LCP element
- 2. A banner that appeared later made LCP 2,032ms
- 3. Whether the explanation became larger than the image depended on its length
- 4. Lighthouse also showed the banner explanation as the element
- 5. Clicking before the banner appeared kept the banner out of LCP
- 6. Fixes: shorten the text, or put the banner in the first HTML
A block of text can also be the LCP element
The LCP explanation on web.dev lists text-containing block-level elements as candidates, in addition to images and videos. The comparison uses the size of the part visible in the viewport. Parts that overflow outside the screen are not counted.
Consent banners are usually fixed to the bottom of the screen and similar places. The Cookie notice best practices on web.dev says that consent notices are usually small and rarely become the LCP element, but on smartphones they can cover a large share of the screen, and a notice with a long text can become the LCP element.
A banner that appeared later made LCP 2,032ms
The page I used for the test had only a header, a full-width hero image, a heading, and two short paragraphs. The consent banner script was loaded from a different origin with async, and the script inserted the banner at the end of body. The banner was position: fixed at the bottom of the screen, used 15px text, and showed an 11-line explanation about consent. The following code is a shortened version of what I used in the test.
<script src="http://127.0.0.1:8081/cmp.js" async></script>
// cmp.js (stand-in for a consent management tool)
(() => {
const d = document.createElement('div');
d.innerHTML = '<div id="consent" role="dialog" aria-label="Cookie の同意">'
+ '<p>当サイトでは、サイトの利用状況の分析、……</p>'
+ '<button id="accept">すべて許可</button><button>設定</button></div>';
document.body.append(d.firstChild);
})();
I measured five times each for a page without the banner and a page with the banner.
| Page | LCP (median of 5) | LCP element |
|---|---|---|
| No consent banner | 832ms | html>body>img.hero |
| Consent banner added later | 2,032ms | #consent>p |
Until partway through, the page with the banner added later behaved the same as the page without it. First, a body paragraph (size 17,616) was the candidate. Around 830ms, when the hero image was displayed, the candidate moved to the image (size 95,584). Then, around 2,032ms, when the script arrived and the banner was displayed, the banner text (size 104,604) became the new candidate. The order was the same in all five runs, and the final candidate was the banner text each time.

At a screen width of 412px, the hero image was 412×232, with a size of 95,584. The banner explanation text was 380×281, with a size of 104,604. The 380×281 multiplication does not match the size, because for text elements the size is measured not from the element's box but from the smallest rectangle that contains all the text (see the LCP explanation). Since the explanation text is larger than the image, the LCP element is replaced as soon as the text is displayed.
async is an attribute that keeps loading a script from blocking HTML parsing (MDN's explanation of the script element). Even with async, the banner is displayed only after the script has arrived and run.
Whether the explanation became larger than the image depended on its length
I changed the length of the banner explanation and measured the page with the later banner five times each. Whether the LCP element was replaced depended on whether the explanation's size exceeded the hero image's 95,584. In the page with the later banner, the 8-line and 10-line explanations were not LCP candidates, so the size values in the table are the values reported as the first candidate on a page where the same banner was included in the initial HTML.
| Banner explanation | Explanation size | Explanation size |
LCP element |
|---|---|---|---|
| 8 lines | 380×204 | 75,800 | Hero image |
| 10 lines | 380×255 | 95,129 | Hero image |
| 11 lines | 380×281 | 104,604 | Banner explanation |
With 10 lines, the difference from the image was only 455. The image was still larger, so the LCP element stayed the image. When I added one more sentence to make it 11 lines, the banner explanation became the LCP element. Even on the same page, a small addition to the banner text can change the LCP element.
Lighthouse also showed the banner explanation as the element
I ran Lighthouse 13.6.0 from the command line with the default settings (mobile), three times per page. I took the LCP breakdown from the lcp-breakdown-insight audit.
| Page | LCP shown by Lighthouse | LCP observed in practice | LCP element |
|---|---|---|---|
| No consent banner | 2.4 s | 852–883ms | body > img.hero |
| Consent banner added later | 3.6 s | 2,050–2,065ms | body > div#consent > p |
The LCP shown by Lighthouse is calculated by simulating a slow network and a slow CPU, as explained in the Lighthouse throttling documentation. The LCP observed in practice is the value of observedLargestContentfulPaint in the metrics section of the JSON.
On the page with the later banner, the LCP breakdown had only two parts, time to first byte (TTFB) and element render delay (elementRenderDelay), and the render delay was 2,042–2,059ms. There was no item for image loading. The web.dev explanation of optimizing LCP says that when the LCP element does not need a resource to load (for example, text drawn with a system font), the load delay and load duration are 0. When the LCP element is the banner explanation and the render delay is large, suspect the time spent waiting for the script that displays the banner to arrive.
Clicking before the banner appeared kept the banner out of LCP
On the same page with the later banner, I clicked once near the body text 1,200ms after the page was opened and then measured. This is the case where a user touches the screen before the banner appears.
In all five runs, LCP stayed at the hero image (median 832ms). Not only the web-vitals value but also the largest-contentful-paint entries received by the browser's PerformanceObserver contained only the body paragraph and the image, with no entry for the banner. The LCP explanation also says that once the user interacts with the page by tapping, scrolling, or pressing a key, the browser stops emitting new entries.
In the Lighthouse runs, I did not interact with the page. So, as in the Lighthouse results above, the banner that appeared later became the LCP element as it was.
Fixes: shorten the text, or put the banner in the first HTML
I tried two fixes.
The first is to shorten the banner explanation and move the detailed explanation to a linked page. When I changed the explanation to a single line (380×26) saying that cookies are used for analytics and advertising, with a link for details, the LCP element went back to the hero image, even though the banner still appeared 2,000ms later.
The second is to stop inserting the banner with a script later, and instead include it in the first HTML the server returns. The explanation stayed at 11 lines.
| Page | LCP in Playwright (median of 5) | LCP shown by Lighthouse | LCP element |
|---|---|---|---|
| One-line explanation, shown later | 832ms | 2.4 s | Hero image |
| 11-line banner in the first HTML | 40ms | 0.9 s | Banner explanation |
On the page with the banner in the first HTML, the banner explanation was displayed together with the first contentful paint (FCP), and LCP was 40ms, the same as FCP. However, the LCP element was still the banner explanation. The hero image was smaller than the explanation, so even after the image was displayed it did not become an LCP candidate. The LCP value gets smaller, but when the image was displayed no longer appears in the LCP value.
The Cookie notice best practices recommend loading the notice script asynchronously, and writing a <script> tag directly in the first HTML rather than going through a tag manager or inserting it from another script. Inserting the script from another script hides it from the lookahead parser, the mechanism by which the browser scans HTML ahead to find scripts, so loading does not start until the inserting JavaScript runs.
If the banner explanation becomes the LCP element, first check at a smartphone width which is larger, the explanation or the page image. To make the image the LCP element again, make the explanation smaller than the image. To keep the banner and still improve speed, display the banner earlier.





