First Input Delay (FID) Stay organized with collections Save and categorize content based on your preferences.
We all know how important it is to make a good first impression. It's importantwhen meeting new people, and it's also important when building experiences onthe web.
On the web, a good first impression can make the difference between someonebecoming a loyal user or them leaving and never coming back. The question is,what makes for a good impression, and how do you measure what kind of impressionyou're likely making on your users?
On the web, first impressions can take a lot of different forms—we havefirst impressions of a site's design and visual appeal as well as firstimpressions of its speed and responsiveness.
While it is hard to measure how much users like a site's design with web APIs,measuring its speed and responsiveness is not!
The first impression users have of how fast your site loads can be measured withFirst Contentful Paint (FCP). But how fast your site can paint pixelsto the screen is just part of the story. Equally important is how responsiveyour site is when users try to interact with those pixels!
The First Input Delay (FID) metric helps measure your user's first impression ofyour site's interactivity and responsiveness.
What is FID?
FID measures the time from when a user first interacts with a page (that is, whenthey click a link, tap on a button, or use a custom, JavaScript-powered control)to the time when the browser is actually able to begin processing event handlersin response to that interaction.
What is a good FID score?
To provide a good user experience, sites should strive to have a First InputDelay of100 milliseconds or less. To ensure you're hitting this target formost of your users, a good threshold to measure is the75th percentile ofpage loads, segmented across mobile and desktop devices.
FID in detail
As developers who write code that responds to events, we often assume our codeis going to be run immediately—as soon as the event happens. But as users,we've all frequently experienced the opposite—we've loaded a web page onour phone, tried to interact with it, and then been frustrated when nothinghappened.
In general, input delay (a.k.a. input latency) happens because the browser'smain thread is busy doing something else, so it can't (yet) respond to the user.One common reason this might happen is the browser is busy parsing and executinga large JavaScript file loaded by your app. While it's doing that, it can't runany event listeners because the JavaScript it's loading might tell it to dosomething else.
FID only measures the "delay" in event processing. It does not measure the total event processing duration itself, nor the time it takes the browser to update the UI after running event handlers. While this time does affect the user experience, including it as part of FID would incentivize developers to respond to events asynchronously—which would improve the metric but likely make the experience worse. Seewhy only consider the input delay below for more details.Consider the following timeline of a typical web page load:
The above visualization shows a page that's making a couple of network requestsfor resources (most likely CSS and JS files), and—after those resourcesare finished downloading—they're processed on the main thread.
This results in periods where the main thread is momentarily busy, which isindicated by the beige-coloredtaskblocks.
Long first input delays typically occur betweenFirst Contentful Paint(FCP) andTime to Interactive (TTI) because the page hasrendered some of its content but isn't yet reliably interactive. To illustratehow this can happen, FCP and TTI have been added to the timeline:
You may have noticed that there's a fair amount of time (including threelongtasks) between FCP and TTI, if a user tries tointeract with the page during that time (for example, by clicking on a link), there will be adelay between when the click is received and when the main thread is able torespond.
Consider what would happen if a user tried to interact with the page near thebeginning of the longest task:
Because the input occurs while the browser is in the middle of running a task,it has to wait until the task completes before it can respond to the input. Thetime it must wait is the FID value for this user on this page.
Note: In this example the user just happened to interact with the page at the beginning of the main thread's most busy period. If the user had interacted with the page just a moment earlier (during the idle period) the browser could have responded right away. This variance in input delay underscores the importance of looking at the distribution of FID values when reporting on the metric. You can read more about this in the section below on analyzing and reporting on FID data.What if an interaction doesn't have an event listener?
FID measures the delta between when an input event is received and when the mainthread is next idle. This means FID is measuredeven in cases where an eventlistener has not been registered. The reason is because many user interactionsdo not require an event listener butdo require the main thread to be idle inorder to run.
For example, all of the following HTML elements need to wait forin-progress tasks on the main thread to complete prior to responding to userinteractions:
- Text fields, checkboxes, and radio buttons (
<input>
,<textarea>
) - Select dropdowns (
<select>
) - links (
<a>
)
Why only consider the first input?
While a delay from any input can lead to a bad user experience, we primarilyrecommend measuring the first input delay for a few reasons:
- The first input delay will be the user's first impression of your site'sresponsiveness, and first impressions are critical in shaping our overallimpression of a site's quality and reliability.
- The biggest interactivity issues we see on the web today occur during pageload. Therefore, we believe initially focusing on improving site's first userinteraction will have the greatest impact on improving the overallinteractivity of the web.
- The recommended solutions for how sites should fix high first input delays(code splitting, loading less JavaScript upfront, etc.) are not necessarilythe same solutions for fixing slow input delays after page load. By separatingout these metrics we'll be able to provide more specific performanceguidelines to web developers.
What counts as a first input?
FID is a metric that measures a page's responsiveness during load. As such, itonly focuses on input events from discrete actions like clicks, taps, and keypresses.
Other interactions, like scrolling and zooming, are continuous actions and havecompletely different performance constraints (also, browsers are often able tohide their latency by running them on a separate thread).
To put this another way, FID focuses on the R (responsiveness) in theRAILperformancemodel, whereasscrolling and zooming are more related to A (animation), and their performancequalities should be evaluated separately.
What if a user never interacts with your site?
Not all users will interact with your site every time they visit. And not allinteractions are relevant to FID (as mentioned in the previous section). Inaddition, some user's first interactions will be at bad times (when the mainthread is busy for an extended period of time), and some user's firstinteractions will be at good times (when the main thread is completely idle).
This means some users will have no FID values, some users will have low FIDvalues, and some users will probably have high FID values.
How you track, report on, and analyze FID will probably be quite a bit differentfrom other metrics you may be used to. The next section explains how best to dothis.
Why only consider the input delay?
As mentioned above, FID only measures the "delay" in event processing. It doesnot measure the total event processing duration itself, nor the time it takesthe browser to update the UI after running event handlers.
Even though this time is important to the user anddoes affect the experience,it's not included in this metric because doing so could incentivize developersto add workarounds that actually make the experience worse—that is, theycould wrap their event handler logic in an asynchronous callback (viasetTimeout()
orrequestAnimationFrame()
) in order to separate it from thetask associated with the event. The result would be an improvement in the metricscore but a slower response as perceived by the user.
However, while FID only measure the "delay" portion of event latency, developerswho want to track more of the event lifecycle can do so using theEvent TimingAPI. See the guide oncustommetrics for more details.
How to measure FID
FID is a metric that can only be measuredin thefield, as it requires a realuser to interact with your page. You can measure FID with the following tools.
Note: FID requires a real user and thus cannot be measured in the lab. However, theTotal Blocking Time (TBT) metric is lab-measurable, correlates well with FID in the field, and also captures issues that affect interactivity. Optimizations that improve TBT in the lab should also improve FID for your users.Field tools
- Chrome User ExperienceReport
- PageSpeed Insights
- Search Console (Core Web Vitalsreport)
web-vitals
JavaScript library
Measure FID in JavaScript
To measure FID in JavaScript, you can use theEvent TimingAPI. The following example shows how tocreate aPerformanceObserver
that listens forfirst-input
entries and logs them to the console:
newPerformanceObserver((entryList)=>{for(constentryofentryList.getEntries()){constdelay=entry.processingStart-entry.startTime;console.log('FID candidate:',delay,entry);}}).observe({type:'first-input',buffered:true});
first-input
entries to the console and calculate their delay. However, measuring FID in JavaScript is more complicated. See below for details:In the above example, thefirst-input
entry's delay value is measured bytaking the delta between the entry'sstartTime
andprocessingStart
timestamps. In most cases this will be the FID value; however, not allfirst-input
entries are valid for measuring FID.
The following section lists the differences between what the API reports and howthe metric is calculated.
Differences between the metric and the API
- The API will dispatch
first-input
entries for pages loadedin a background tab but those pages should be ignored when calculating FID. - The API will also dispatch
first-input
entries if the page was backgroundedprior to the first input occurring, but those pages should also be ignoredwhen calculating FID (inputs are only considered if the page was in theforeground the entire time). - The API does not report
first-input
entries when the page is restored fromtheback/forward cache, but FID shouldbe measured in these cases since users experience them as distinct pagevisits. - The API does not report inputs that occur within iframes but the metric doesas they are part of the user experience of the page. This canshow as a difference between CrUX and RUM.To properly measure FID you should consider them. Sub-frames can use the APIto report their
first-input
entries to the parent frame for aggregation.
Analyzing and reporting on FID data
Due to the expected variance in FID values, it's critical that when reporting onFID you look at the distribution of values and focus on the higher percentiles.
Whilechoice ofpercentile for allCore Web Vitals thresholds is the 75th, for FID in particular we still stronglyrecommend looking at the 95th–99th percentiles, as those will correspond to theparticularly bad first experiences users are having with your site. And it willshow you the areas that need the most improvement.
This is true even if you segment your reports by device category or type. Forexample, if you run separate reports for desktop and mobile, the FID value youcare most about on desktop should be the 95th–99th percentile of desktop users,and the FID value you care about most on mobile should be the 95th–99thpercentile of mobile users.
How to improve FID
A full guide onoptimizing FID is available to guide you through techniques to improve this metric.
Changelog
Occasionally, bugs are discovered in the APIs used to measure metrics, and sometimes in the definitions of the metrics themselves. As a result, changes must sometimes be made, and these changes can show up as improvements or regressions in your internal reports and dashboards.
To help you manage this, all changes to either the implementation or definition of these metrics will be surfaced in thisChangelog.
If you have feedback for these metrics, you can provide it in theweb-vitals-feedback Google group.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-10-06 UTC.