whatisgithub

What is web-vitals?

googlechrome/web-vitals — explained in plain English

Analysis updated 2026-06-24

8,495JavaScriptAudience · developerComplexity · 2/5LicenseSetup · easy

In one sentence

web-vitals is a tiny JavaScript library from Google that measures your website's real-world loading speed and responsiveness using the exact signals Google uses for search rankings.

Mindmap

mindmap
  root((web-vitals))
    Metrics
      LCP loading speed
      INP interactivity
      CLS layout shift
      FCP first paint
      TTFB server speed
    Usage
      npm install
      Callback function
      CDN script tag
    Output
      Google Analytics
      Custom analytics
      Console logging
    Attribution build
      Pinpoint elements
      Diagnose root cause
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Track Largest Contentful Paint and Cumulative Layout Shift on your live site to match exactly what Google measures for search rankings.

USE CASE 2

Send real-user Core Web Vitals data to Google Analytics or a custom analytics endpoint with just a few lines of code.

USE CASE 3

Use the attribution build to pinpoint exactly which element or interaction is causing a poor LCP, INP, or CLS score.

What is it built with?

JavaScript

How does it compare?

googlechrome/web-vitalscodecombat/codecombatgridsome/gridsome
Stars8,4958,4938,492
LanguageJavaScriptJavaScriptJavaScript
Setup difficultyeasyhardmoderate
Complexity2/54/53/5
Audiencedevelopergeneraldeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min
Apache 2.0, use freely including in commercial products, with attribution.

So what is it?

web-vitals is a small JavaScript library from Google that measures how a website performs for the actual people visiting it. It tracks the specific signals Google uses to evaluate page experience in search rankings and developer tools, so the numbers you see in your own monitoring match what Google sees. The library covers three Core Web Vitals that Google considers the most important: Largest Contentful Paint, which measures how long it takes for the main content of the page to appear, Interaction to Next Paint, which measures how quickly the page responds when a user clicks or taps something, and Cumulative Layout Shift, which measures how much the page layout unexpectedly moves around while loading. It also captures two additional signals: First Contentful Paint and Time to First Byte, which relate to how quickly the server starts delivering content. You can install it from npm and import it into your JavaScript code with a couple of lines. For each metric, you provide a callback function that runs whenever a measurement is ready. From there, you decide what to do with the data: log it for debugging, send it to your own analytics system, or forward it to Google Analytics or Google Tag Manager. The library is intentionally small, roughly 2 kilobytes in its compressed form, so it adds very little overhead to your page. A second build called the attribution build is available for teams who want to understand not just what their score is but why it is low. It attaches extra diagnostic information to each metric report pointing to the specific element or interaction that caused the poor result. The library can be loaded via npm or directly from a CDN using a script tag. It is designed to be loaded after other content rather than early in the page, since it uses a browser feature that gives it access to performance data even when loaded late. The full README is longer than what was shown.

Copy-paste prompts

Prompt 1
Add the web-vitals library to my React app and send LCP, INP, and CLS scores to Google Analytics 4 on each page view.
Prompt 2
Using the web-vitals attribution build, log which specific DOM element is causing my Cumulative Layout Shift to the browser console.
Prompt 3
Set up web-vitals in a plain HTML page using a script tag from a CDN and log all five Core Web Vitals to the console.
Prompt 4
Write a Next.js reportWebVitals function that sends each metric to my custom /api/vitals analytics endpoint as a POST request.
Prompt 5
How do I measure Time to First Byte with web-vitals and alert when it exceeds 800ms in my monitoring setup?

Frequently asked questions

What is web-vitals?

web-vitals is a tiny JavaScript library from Google that measures your website's real-world loading speed and responsiveness using the exact signals Google uses for search rankings.

What language is web-vitals written in?

Mainly JavaScript. The stack also includes JavaScript.

What license does web-vitals use?

Apache 2.0, use freely including in commercial products, with attribution.

How hard is web-vitals to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is web-vitals for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.