files/en-us/web/api/largestcontentfulpaint/index.md
{{APIRef("Performance API")}}
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 {{Glossary("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:
<image> elements inside an SVG.To measure render times of other elements, use the {{domxref("PerformanceElementTiming")}} API.
Additional key paint moments are provided by the {{domxref("PerformancePaintTiming")}} API:
LargestContentfulPaint inherits from {{domxref("PerformanceEntry")}}.
{{InheritanceDiagram}}
To get an accurate measurement of render time for cross-origin resources, set the {{httpheader("Timing-Allow-Origin")}} header.
Developers should use startTime instead of renderTime as the LCP value, as the renderTime may not be set in some browsers.
See Cross-origin image render time and Use startTime over renderTime for more details.
This interface extends the following {{domxref("PerformanceEntry")}} properties by qualifying and constraining the properties as follows:
"largest-contentful-paint".0, otherwise the value of this entry's {{domxref("LargestContentfulPaint.loadTime", "loadTime")}}.0, as duration is not applicable to this interface.It also supports the following properties:
0 if the element is a cross-origin image loaded without the Timing-Allow-Origin header.This interface also inherits methods from {{domxref("PerformanceEntry")}}.
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 });
{{Specifications}}
{{Compat}}