Skip to Content

First contentful paint (FCP)

Chrome 60+ Edge 79+ Firefox 84+ Safari 15+ Details

Quick check for First Contentful Paint (opens in a new tab), the metric that marks when the browser renders the first piece of DOM content, text, image, canvas, or SVG. FCP measures the user’s perception of whether the page is loading.

Unlike LCP, FCP fires as soon as any content appears, making it the earliest signal of loading progress. A slow FCP almost always points to TTFB or render-blocking resources.

FCP rating thresholds

RatingTimeMeaning
Good≤ 1.8sContent appears quickly
Needs Improvement≤ 3sNoticeable delay
Poor> 3sUsers may perceive the page as broken

Render-blocking resources? Use Find Render-Blocking Resources for a detailed analysis with recommendations.

Snippet

Run it from an AI agent: the prompt uses the CLI to measure any URL and report the result.

// FCP Analysis
// First Contentful Paint with render-blocking phase breakdown
// https://webperf-snippets.net

(() => {
  // @shared hiddenBefore
  // Whether the page was hidden before `time`, a startTime: it loaded in a background tab, or the user
  // switched to another tab before it painted. A paint nobody saw is not the metric, and web-vitals does
  // not report it. The first visibility-state entry "hidden" says when, as in web-vitals: a prerendered
  // page is hidden until its activation, so only an entry from the activation on counts. Without one, the
  // page was hidden from its start only if it is hidden now.
  function hiddenBefore(time) {
    if (PerformanceObserver.supportedEntryTypes?.includes("visibility-state") && !document.prerendering) {
      const activationStart = performance.getEntriesByType("navigation")[0]?.activationStart || 0;
      const hidden = performance
        .getEntriesByType("visibility-state")
        .find((entry) => entry.name === "hidden" && entry.startTime >= activationStart);
      if (hidden) return hidden.startTime <= time;
    }
    return document.visibilityState === "hidden" && !document.prerendering;
  }

  // Why a snippet gives no value for a metric the page painted while it was hidden
  function hiddenMessage(metric) {
    return `The page was hidden before its ${metric} was painted, as when it loads in a background tab or the user switches to another tab before it paints, so the ${metric} is not what a user saw and web-vitals does not report it. Reload the page with its tab in front and run the snippet again.`;
  }

  // The result of a snippet whose metric the page painted while it was hidden: hiddenBeforePaint tells the
  // reports that it measured nothing, and that neither the snippet nor the page failed
  function hiddenResult(name, metric) {
    return { script: name, status: "error", hiddenBeforePaint: true, error: hiddenMessage(metric) };
  }

  // The warning of the console, once however many times the page paints while it is hidden
  let hiddenWarned = false;
  function warnHidden(metric) {
    if (!hiddenWarned) console.warn(`⚠️ ${hiddenMessage(metric)}`);
    hiddenWarned = true;
  }
  // @end-shared hiddenBefore

  // @shared isOwnRequest
  // True for the Resource Timing entry of a request a snippet made with ownRequestUrl: the page
  // did not make it, so no snippet counts it.
  function isOwnRequest(entry) {
    return entry.name.endsWith("#webperf-snippets");
  }
  // @end-shared isOwnRequest

  const valueToRating = (ms) =>
    ms <= 1800 ? "good" : ms <= 3000 ? "needs-improvement" : "poor";

  const RATING = {
    good: { icon: "🟢", color: "#0CCE6A" },
    "needs-improvement": { icon: "🟡", color: "#FFA400" },
    poor: { icon: "🔴", color: "#FF4E42" },
  };

  const ms = (val) => `${Math.round(val)}ms`;

  // @shared supportsRenderBlockingStatus
  // renderBlockingStatus (Resource Timing) is Chromium-only (Chrome 107+). Without it, which
  // resources block rendering is unknown: a snippet reports that, not "none".
  function supportsRenderBlockingStatus() {
    return !!window.PerformanceResourceTiming && "renderBlockingStatus" in window.PerformanceResourceTiming.prototype;
  }
  // @end-shared supportsRenderBlockingStatus

  // Without it, the time after TTFB is not split into render-blocking load and render delay
  const renderBlockingSupported = supportsRenderBlockingStatus();

  new PerformanceObserver((list) => {
    const fcpEntry = list.getEntriesByName("first-contentful-paint")[0];
    if (!fcpEntry) return;
    if (hiddenBefore(fcpEntry.startTime)) return warnHidden("FCP");

    const navEntry = performance.getEntriesByType("navigation")[0];
    // Prerendered pages: measure from activation, not from the start of the prerender
    const activationStart = navEntry?.activationStart || 0;
    const fcpTime = Math.max(0, fcpEntry.startTime - activationStart);
    const rating = valueToRating(fcpTime);
    const { icon, color } = RATING[rating];

    const ttfb = Math.max(0, (navEntry?.responseStart ?? 0) - activationStart);

    // Render-blocking resources (Chrome 107+, requires renderBlockingStatus API)
    const resources = performance.getEntriesByType("resource").filter((e) => !isOwnRequest(e));
    const blockingResources = resources.filter(
      (r) => r.renderBlockingStatus === "blocking"
    );

    const lastBlockingEnd = blockingResources.length
      ? Math.max(...blockingResources.map((r) => r.responseEnd)) - activationStart
      : ttfb;

    console.group(
      `%cFCP: ${icon} ${(fcpTime / 1000).toFixed(2)}s (${rating})`,
      `color: ${color}; font-weight: bold; font-size: 14px;`
    );

    // Phase breakdown
    console.log("");
    console.log("%cPhase Breakdown:", "font-weight: bold;");
    console.log(`   TTFB:                  ${ms(ttfb)}`);
    if (!renderBlockingSupported) {
      console.log(`   Render-blocking load and render delay: ${ms(Math.max(0, fcpTime - ttfb))}`);
      console.log("");
      console.log(
        "%cℹ️ renderBlockingStatus is not supported in this browser (Chrome 107+), so render-blocking resources cannot be identified",
        "color: #3b82f6;"
      );
      console.groupEnd();
      return;
    }
    if (blockingResources.length > 0) {
      console.log(
        `   Render-blocking load:  ${ms(Math.max(0, lastBlockingEnd - ttfb))}`
      );
    }
    console.log(
      `   Render delay:          ${ms(Math.max(0, fcpTime - lastBlockingEnd))}`
    );

    // Render-blocking summary
    console.log("");
    if (blockingResources.length > 0) {
      const totalBlockingTime = Math.max(0, lastBlockingEnd - ttfb);
      console.log(
        `%c⚠ ${blockingResources.length} render-blocking resource(s) — adding ${ms(totalBlockingTime)} before paint`,
        "color: #FFA400; font-weight: bold;"
      );
      blockingResources
        .sort((a, b) => b.responseEnd - a.responseEnd)
        .forEach((r) => {
          const filename = r.name.split("/").pop().split("?")[0] || r.name;
          const type = r.initiatorType === "link" ? "CSS" : "JS";
          console.log(`   [${type}] ${ms(r.duration)}  ${filename}`);
        });
      console.log("");
      console.log(
        "%c→ Find Render-Blocking Resources: %chttps://webperf-snippets.net/Loading/Find-render-blocking-resources",
        "color: #3b82f6;",
        "color: #3b82f6; text-decoration: underline;"
      );
    } else {
      console.log(
        "%c✓ No render-blocking resources detected",
        "color: #22c55e;"
      );
    }

    console.groupEnd();
  }).observe({ type: "paint", buffered: true });

  // Synchronous return for agent
  const fcpEntrySync = performance.getEntriesByName("first-contentful-paint")[0];
  if (!fcpEntrySync) return { script: "FCP", status: "error", error: "No FCP entry yet" };
  if (hiddenBefore(fcpEntrySync.startTime)) return hiddenResult("FCP", "FCP");
  const navEntrySync = performance.getEntriesByType("navigation")[0];
  const activationStartSync = navEntrySync?.activationStart || 0;
  const fcpTimeSync = Math.max(0, fcpEntrySync.startTime - activationStartSync);
  const ratingSync = valueToRating(fcpTimeSync);

  // Phases, measured from activation like the value: TTFB, then the wait for the last
  // render-blocking resource, then the rest until the paint. Without renderBlockingStatus the
  // two phases after TTFB are null, not 0 and the whole rest.
  const ttfbSync = Math.max(0, (navEntrySync?.responseStart ?? 0) - activationStartSync);
  const blockingSync = renderBlockingSupported
    ? performance
        .getEntriesByType("resource").filter((e) => !isOwnRequest(e))
        .filter((r) => r.renderBlockingStatus === "blocking")
    : [];
  const lastBlockingEndSync = Math.max(
    ttfbSync,
    ...blockingSync.map((r) => r.responseEnd - activationStartSync)
  );
  const ttfbMs = Math.round(ttfbSync);
  const renderBlockingLoadMs = renderBlockingSupported ? Math.round(lastBlockingEndSync - ttfbSync) : null;
  const renderDelayMs = renderBlockingSupported
    ? Math.max(0, Math.round(fcpTimeSync) - ttfbMs - renderBlockingLoadMs)
    : null;

  return {
    script: "FCP",
    status: "ok",
    metric: "FCP",
    value: Math.round(fcpTimeSync),
    unit: "ms",
    rating: ratingSync,
    thresholds: { good: 1800, needsImprovement: 3000 },
    details: {
      ttfbMs,
      renderBlockingLoadMs,
      renderDelayMs,
      blockingResourceCount: renderBlockingSupported ? blockingSync.length : null,
      renderBlockingSupported,
    },
    // Render-blocking resources, the last to finish first (at most 50)
    items: [...blockingSync]
      .sort((a, b) => b.responseEnd - a.responseEnd)
      .slice(0, 50)
      .map((r) => ({
        url: r.name.split("/").pop().split("?")[0] || r.name,
        type: r.initiatorType === "link" ? "CSS" : "JS",
        durationMs: Math.round(r.duration),
      })),
  };
})();

Phase breakdown

The three phases explain where time is spent before the first pixel is painted:

PhaseMeasured asOptimization
TTFBresponseStart, time until first byte of HTML arrivesServer response time, CDN, caching
Render-blocking loadTime blocked waiting for CSS/JS before the browser can paintDefer/async scripts, inline critical CSS
Render delayTime from resources ready to actual paintCSS complexity, main thread contention

On prerendered pages, every phase is measured from activationStart (the moment the page was shown), not from the start of the prerender.

Browser support: The render-blocking phase requires the renderBlockingStatus API (Chrome 107+, Edge 107+). Other browsers cannot tell which resources block rendering, so the snippet does not split the time after TTFB: details.renderBlockingSupported is false, and renderBlockingLoadMs, renderDelayMs and blockingResourceCount are null. The FCP value and TTFB are still measured.

A page hidden before it painted

A page that loads in a background tab, or that the user leaves for another tab before it paints, paints while nobody sees it, so its FCP is not what a user waited for, and web-vitals does not report it. The snippet returns an error with that reason instead of a time: reload the page with its tab in front and run it again. A prerendered page is hidden until its activation, and that does not count.

Browser support

The snippet needs these features to run.

FeatureChromeEdgeFirefoxSafari
PerformancePaintTiming (opens in a new tab) 60 79 84 14.1
PerformanceObserver (opens in a new tab) 52 79 57 11
PerformanceNavigationTiming (opens in a new tab) 57 12 58 15
All of the above 60 79 84 15

The snippet reports on these features. It runs without them, and its advice on each one applies where it is supported.

FeatureChromeEdgeFirefoxSafari
PerformanceResourceTiming.renderBlockingStatus (opens in a new tab) 107 107

Source: MDN browser compatibility data (opens in a new tab), version 8.1.10.

Further reading

Last updated on