WebTech1223411 logo WebTech1223411Web tech, read closely
Dev Tools

How to Use the DevTools Coverage Tab to Find Dead CSS

A stylesheet on a project I inherited was 184KB minified, one file for the whole site. The Coverage tab in Chrome DevTools told me that 91 percent of it went unused on the homepage.

A browser Coverage panel listing stylesheets with unused byte percentages beside a source view with red gutter stripes

A stylesheet on a project I inherited was 184KB minified, one file for the whole site. The Coverage tab in Chrome DevTools told me that 91 percent of it went unused on the homepage. That felt like free money, so I deleted the rules that showed red in the gutter, shipped it, and broke the address form in checkout three days later. The validation error styling only existed on a page I had never recorded.

Coverage is one of the most useful panels in DevTools and one of the easiest to misread, because the word "unused" does not mean what it sounds like. It means "not used during the seconds I was watching". That is a completely different claim, and the gap between those two readings is where production incidents live. The panel is still worth your afternoon. It just needs a recording method and a rule about what you are allowed to conclude from it.

What the panel actually measures

Coverage instruments the engine while you interact with a page and records which bytes of each CSS and JavaScript resource were touched. For CSS, a rule counts as used the moment a selector matches an element in the document, whether or not that element is visible. For JavaScript, a byte counts as used when it executes.

Two consequences follow, and both surprise people the first time.

A rule for a hidden element still counts as used. If your markup contains a modal with display: none, every rule matching nodes inside that modal is reported as used, because the selectors matched. So CSS coverage over-reports usage for anything present in the DOM but invisible, which is most of a modern component library.

And a rule for an element that appears later counts as unused until it appears. Hover states, focus rings, validation messages, empty state illustrations, the second tab of a tab panel: none of those exist in the document until something happens. They sit in the unused column looking deletable while being load bearing.

The panel also measures bytes, not rules. A long block of vendor framework CSS with a large footprint and one matched selector reports partly used, and the ratio tells you nothing about which lines matter.

Recording a session that means something

The default way people use Coverage is to open it, press reload, and read the number. That produces the figure I trusted and regretted. Here is the routine I use now, which takes about four minutes per route and has not misled me since.

  1. Open the panel properly. Press Control plus Shift plus P in DevTools to open the command menu, type coverage, and run the command that shows the drawer. It lives under More tools in the menu as well, but the command menu is faster and it is the same panel.
  2. Choose per function or per block for JavaScript. There is a selector at the top of the drawer. Per block is the one that matches what the CSS side reports, and per function hides partial usage inside long functions. For a CSS investigation, leave it on per block.
  3. Record with reload, not start. The reload button restarts the page with instrumentation already attached, so you capture the initial render. Starting a recording on an already loaded page misses every rule that applied during first paint, which is exactly the set you care about for critical CSS.
  4. Then interact, deliberately, from a list. Write the list before you record: open each menu, focus each form field, submit one form with bad input, open and close the modal, expand every accordion, hover the nav, switch the theme if you have one. Blind clicking produces blind numbers.
  5. Repeat per viewport. Run the whole sequence once at desktop width and once with device emulation at a narrow width. Media query blocks that never match are reported unused, and a desktop only recording will condemn your entire mobile layout.
  6. Export the result. There is a download control in the drawer that writes a JSON file of ranges. Keep one per route and per viewport. Comparing two of those files is how you get a defensible answer rather than a screenshot.

The per file rows show total bytes and unused bytes with a bar. Click a row and the source opens with a gutter stripe beside every line: blue for executed, red for not. The red stripes are the interesting part, not the headline percentage.

Where the numbers get misleading

Three situations produce coverage figures that look dramatic and are not.

Inlined critical CSS gets counted twice. If your build inlines the above the fold rules into the head and also loads the full stylesheet, the external file will report a huge unused share, because its job on that page is to cover everything the inline block does not. The system is working as designed and the number looks like a failure.

Styles injected by JavaScript appear as separate anonymous entries. Component libraries using runtime style injection create one entry per injected sheet, often with names that look like hashes. Those entries are usually near 100 percent used and they shrink the apparent problem in the main file, so comparing before and after a refactor across these entries needs care.

Browser extensions inject their own stylesheets. I always record in a clean profile or an incognito window with extensions disabled, because an extension sheet sitting in the list skews the totals and wastes ten minutes of confusion. This is the same hygiene that makes a DevTools network waterfall readable, and for the same reason.

Why "delete the unused CSS" is bad advice

Every performance checklist tells you to remove unused CSS, and Coverage looks like the tool that hands you the list. It is not. Treat it as a discovery tool whose output is a set of questions, not a diff.

The reason is that coverage is evidence of presence, never evidence of absence. A rule shown blue is definitely used. A rule shown red is unproven in both directions. You can prove a rule is needed with one recording and you cannot prove it is unneeded with a hundred, because the hundred and first state is an error page nobody thought to visit.

What I do instead is use the red stripes to find candidates, then verify each candidate with a text search across the repository for the class name, including template files, email templates, content managed strings, and any string concatenation that builds class names at runtime. Dynamic class construction is the usual killer. A search for a literal class name finds nothing because the code assembles it from a prefix and a variable, and your grep comes back clean on a class that renders every day.

Then I delete in small batches behind a feature branch and let the visual regression suite disagree with me. On the project I mentioned, that process removed 61KB rather than the 167KB the panel implied, and the 61KB was safe. The honest saving was roughly a third of the exciting number, which is about the ratio I have come to expect.

The structural fix is different work anyway. Splitting one global stylesheet per route, or moving to component scoped styles, removes the dead bytes from the page without anybody auditing a single rule. Coverage is how you justify that project to whoever controls the roadmap, and the page weight argument is the same one behind render blocking resources.

A sensible first pass this week

Pick your three highest traffic routes. Record each one twice, desktop and narrow, following a written interaction list. Export the six JSON files. Then look only at files where the unused share is above 70 percent and the total is above 30KB, because anything smaller is not worth the risk of touching.

From that shortlist, open the largest file and scroll the gutter rather than reading the percentage. You will usually find two or three contiguous red blocks of several hundred lines each, often a framework component or a theme nobody ships anymore. Those blocks are where the real saving is, and they are far easier to verify than a thousand scattered single rules. More tooling walkthroughs sit in dev tools.

FAQ

Does Coverage work in Firefox or Safari?

Not as the same panel. Firefox has no direct equivalent for CSS coverage, and Safari's Web Inspector does not offer one either. Record in a Chromium based browser and remember that engine differences mean a rule exercised in Chrome may be dead in another engine for reasons coverage will never show you.

Why does my unused percentage change between reloads?

Because coverage depends entirely on what ran. Variations come from lazy loaded components, A/B test buckets, cookie banners that appear only on a first visit, and media queries matching a slightly different window size. Record three times and use the lowest unused figure as your working number.

Can I automate this in continuous integration?

Yes, through the Chrome DevTools Protocol, which exposes the same CSS coverage data to a headless script driving a browser against a local server such as localhost:3000. Puppeteer and Playwright both wrap it. Automated runs are only as good as the interaction script you write, which brings back the same problem in a different file.

Should I use a build time purge tool instead?

Usually yes, for the ongoing work, with a safelist for class names your code builds dynamically. A purge tool scans your templates rather than a live session, so it catches states you never visited. Use Coverage to find out whether the problem is large enough to justify adding the tool at all.

MC
Maren Castellanos

Maren worked in cross-browser QA before editing, and knows the DevTools Network tab better than most people know their inbox. She writes about how browsers load and render pages and about the tools that show what is really happening.

More posts by Maren

More in Dev Tools

01doorganico 084goad 3hot8 4465456 after5internprogram ahandfulofblessings ahmadpc ahomcybersecurity allodialresources annodex antiquesandperiodcollectibles aotc asianworldkashmir beedlectrics bloggertemplatefree bluefeatheragency bodyweightsolution campaign08blog carfixadvisor catstreetcollective cbstvsports cnfanspurchasing committeeof500yearsofdignityandresistance covertopsdjs cs-kaiyuangame cuestacomunicaciontotal cxoutlet dancebetgame deskgearhub destinyvillastay detectmagazine di33 diamondsteelbuildings donmo dyanadropship emarsysfinance emimattl escapechan eskitarih evautoplay everythingweddings-orlando farmzone feedviewerapp foxstudiosscratch gamevui123 gleasongrade greetingsday hacklabasu haskell iw-kaiyun jagoanproperti jilidskripsi joltbusinessfinance juegodepokergratis juegospucca kaeru-festival latestmehndidesigns lestanzediottaviano litemagazines localcommunityhero lustrsazan mariashebets menswheels newwebstechs1 nikkit ootheday oxigenvpn plurfitness prefetial probudgetcarpetcleaning psychicmrsmartin pyaten qvantor rejoignezlogis rexzbot riselayouts ruchin rwxqsgd5 sakaltime shibiaowang shop-bot skrtips spotlesshaven strcoding tetapatrium topselller uneplanteartificielle vipertechcr wo-kygaming yamaha-mekar yeknava yoybuysheets zenunwa yamaha-mekar jilidskripsi ankertoto ankertoto ankertoto