This feature is not Baseline because it does not work in some of the most widely-used browsers.
The LargestContentfulPaint interface provides timing information about the largest image or text paint before user input on a web page.
The key moment this API provides is the Largest Contentful Paint (LCP) metric. It provides the render time of the largest image or text block visible within the viewport, recorded from when the page first begins to load. The following elements are considered when determining the LCP:
<img> elements.<image> elements inside an SVG.<video> elements.background-image.<p>.To measure render times of other elements, use the PerformanceElementTiming API.
Additional key paint moments are provided by the PerformancePaintTiming API:
LargestContentfulPaint inherits from PerformanceEntry.
This interface extends the following PerformanceEntry properties by qualifying and constraining the properties as follows:
PerformanceEntry.entryType Read only Experimental
Returns "largest-contentful-paint".
PerformanceEntry.name Read only Experimental
Always returns an empty string.
PerformanceEntry.startTime Read only Experimental
Returns the value of this entry's renderTime if it is not 0, otherwise the value of this entry's loadTime.
PerformanceEntry.duration Read only Experimental
Returns 0, as duration is not applicable to this interface.
It also supports the following properties:
LargestContentfulPaint.element Read only
The element that is the current largest contentful paint.
LargestContentfulPaint.renderTime Read only
The time the element was rendered to the screen. May not be available if the element is a cross-origin image loaded without the Timing-Allow-Origin header.
LargestContentfulPaint.loadTime Read only
The time the element was loaded.
LargestContentfulPaint.size Read only
The intrinsic size of the element returned as the area (width * height).
LargestContentfulPaint.id Read only
The id of the element. This property returns an empty string when there is no id.
LargestContentfulPaint.url Read only
If the element is an image, the request url of the image.
This interface also inherits methods from PerformanceEntry.
LargestContentfulPaint.toJSON()Returns a JSON representation of the LargestContentfulPaint object.
In the following example, an observer is registered to get the largest contentful paint while the page is loading. The buffered flag is used to access data from before observer creation.
The LCP API analyzes all content it finds (including content that is removed from the DOM). When new largest content is found, it creates a new entry. It stops searching for larger content when scroll or input events occur, since these events likely introduce new content on the website. Thus the LCP is the last performance entry reported by the observer.
const observer = new PerformanceObserver((list) => {
const entries = list.getEntries();
const lastEntry = entries[entries.length - 1]; // Use the latest LCP candidate
console.log("LCP:", lastEntry.startTime);
console.log(lastEntry);
});
observer.observe({ type: "largest-contentful-paint", buffered: true });
For security reasons, the value of the renderTime property was originally 0 if the resource is a cross-origin request. Instead the loadTime property should be used as a fallback.
Browsers may now expose a slightly coarsened render time in these situations. Check for browser support.
To expose more accurate cross-origin render-time information, the Timing-Allow-Origin HTTP response header needs to be set.
For example, to allow https://developer.mozilla.org to see an accurate renderTime, the cross-origin resource should send:
Timing-Allow-Origin: https://developer.mozilla.org
Like in the code example, you can use startTime, which returns the value of the entry's renderTime if it is not 0, and otherwise the value of this entry's loadTime. However, it is recommended to set the Timing-Allow-Origin header so that the metrics will be more accurate.
If you use startTime, you can flag any inaccuracies by checking if renderTime was used:
const isAccurateLCP = Boolean(entry.renderTime);
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
LargestContentfulPaint |
77 | 79 | 122 | 64 | No | 77 | 122 | 55 | No | 12.0 | 77 | No |
element |
77 | 79 | 122 | 64 | No | 77 | 122 | 55 | No | 12.0 | 77 | No |
id |
77 | 79 | 122 | 64 | No | 77 | 122 | 55 | No | 12.0 | 77 | No |
loadTime |
77 | 79 | 122 | 64 | No | 77 | 122 | 55 | No | 12.0 | 77 | No |
paintTime |
No | No | 140 | No | No | No | 140 | No | No | No | No | No |
presentationTime |
No | No | 140 | No | No | No | 140 | No | No | No | No | No |
renderTime |
77 | 79 | 122 | 64 | No | 77 | 122 | 55 | No | 12.0 | 77 | No |
size |
77 | 79 | 122 | 64 | No | 77 | 122 | 55 | No | 12.0 | 77 | No |
toJSON |
77 | 79 | 122 | 64 | No | 77 | 122 | 55 | No | 12.0 | 77 | No |
url |
77 | 79 | 122 | 64 | No | 77 | 122 | 55 | No | 12.0 | 77 | No |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/LargestContentfulPaint