All skills
addyosmani avatar

/core-web-vitals

@c6b06ad official

Optimize Core Web Vitals (LCP, INP, CLS) for better page experience using field and lab evidence. Use when asked to "improve Core Web Vitals", "fix LCP", "reduce CLS", "optimize INP", "page experience optimization", or "fix layout shifts".

Use this Skill: https://skilld.dev/gh/addyosmani/web-quality-skills/core-web-vitals

This session only. Nothing lands on disk.

referencesCLS.md

≈1k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Cumulative Layout Shift (CLS)

Read this reference when field CLS is poor, a performance trace reports layout shifts, or source inspection finds content that changes geometry without reserved space.

CLS scores unexpected shift clusters across a page visit. A layout-shift score is the impact fraction × distance fraction. Use the shifted-node and initiator evidence: the element that moved may be the victim of content inserted above it.

Reserve media space

Bad:

<img src="photo.jpg" alt="Photo">
<iframe src="https://video.example/embed/123" title="Demo"></iframe>

Good:

<img src="photo.jpg" alt="Photo" width="800" height="600">

<div class="video-frame">
  <iframe src="https://video.example/embed/123" title="Demo"></iframe>
</div>
.video-frame {
  aspect-ratio: 16 / 9;
}

.video-frame iframe {
  height: 100%;
  width: 100%;
}

Reserve a realistic minimum for ads and embeds whose final size can vary. A placeholder that later collapses can also shift content.

Handle dynamic content deliberately

Do not insert banners, validation summaries, consent UI, or notifications above visible content without reserving space. Prefer an overlay, insert outside the active viewport, or allocate a stable container before the content arrives.

Bad:

main.prepend(notification);

Good:

const slot = document.querySelector('[data-notification-slot]');
slot.replaceChildren(notification);

The corresponding slot must already have appropriate reserved dimensions. Verify that responsive content and localization do not overflow it.

Stabilize fonts

Use a fallback with similar metrics and tune it with size-adjust, ascent-override, descent-override, and line-gap-override when trace evidence attributes shifts to font replacement.

@font-face {
  font-family: "Brand Fallback";
  src: local("Arial");
  size-adjust: 102%;
  ascent-override: 92%;
  descent-override: 24%;
  line-gap-override: 0%;
}

Do not copy these values to another font pair; derive them from the actual font metrics and test representative text.

Animate without layout

Prefer transform and opacity for visual motion. Animating height, width, top, or left can trigger layout, but replacing them mechanically is not enough: confirm the transformed element does not obscure content or change the intended hit area.

.toast {
  inset-block-start: 1rem;
  inset-inline-end: 1rem;
  position: fixed;
  transform: translateY(-150%);
  transition: transform 200ms;
}

.toast.is-visible {
  transform: translateY(0);
}

Inspect one browser session

This observer reports shifts seen during the current page session. It is not the distribution of real visits.

new PerformanceObserver((list) => {
  for (const entry of list.getEntries()) {
    if (!entry.hadRecentInput) {
      console.log('Layout shift', entry.value);
      entry.sources?.forEach(source => {
        console.log('Shifted node', source.node);
        console.log('Previous rect', source.previousRect);
        console.log('Current rect', source.currentRect);
      });
    }
  }
}).observe({ type: 'layout-shift', buffered: true });

Verification checklist

  • Images and responsive media reserve intrinsic space
  • Ads, embeds, and async components have stable containers
  • Banners and validation messages do not displace visible content unexpectedly
  • Font swaps use measured fallback metrics when they cause shifts
  • Animations avoid unnecessary layout work
  • The relevant page state and viewport are exercised, not only the initial load
  • Field improvement is claimed only after new RUM or CrUX visits

Sources

Source: SKILL.md on GitHub

No alerts16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    The skill provides comprehensive and secure instructions for optimizing Core Web Vitals (LCP, INP, CLS) using industry-standard browser APIs and development frameworks. No malicious patterns, hidden code, or security risks were detected.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer7mo

    2 files scanned · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at c6b06ad. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated last month
metadata
{
  "author": "web-quality-skills",
  "version": "2.0"
}
  • Performance
  • core-web-vitals
  • lcp
  • inp
  • cls
  • google-search
  • page-experience
  • web-vitals
  • optimization

README badge

README badge for addyosmani/web-quality-skills/core-web-vitals

Optimizes Largest Contentful Paint (LCP), Interaction to Next Paint (INP), and Cumulative Layout Shift (CLS) — the three metrics Google uses to rank page experience. Provides concrete fixes for each metric: preloading critical resources and using Speculation Rules for LCP, breaking long tasks and prioritizing visual feedback for INP, and reserving space for images and embeds to prevent CLS.

Generated from the current SKILL.md.

Does this skill cover all three Core Web Vitals?
Yes. It covers LCP (Largest Contentful Paint), INP (Interaction to Next Paint), and CLS (Cumulative Layout Shift), with optimization strategies and code examples for each.
What tools or libraries does this skill assume I'm using?
It's framework-agnostic but includes examples for React/Vue, Web APIs like scheduler.yield() and requestIdleCallback, and references the web-vitals library for field debugging.
Does this include debugging tools or just optimization patterns?
Both. It provides PerformanceObserver code snippets to identify LCP elements and slow interactions, plus guidance on using the web-vitals library with Long Animation Frame attribution for real-user data.
Will this help improve my Google Search ranking?
Yes. Google measures Core Web Vitals at the 75th percentile for search ranking—the skill explains the thresholds and how to meet them.
Does this cover third-party script optimization?
Yes. It includes patterns for lazy-loading heavy widgets and avoiding third-party blocking, particularly relevant for INP.

Generated from the current SKILL.md. These answers refresh after source changes.