Put the vendor stylesheet in a named vendor layer, put your overrides in a later theme layer, and remove any duplicate unlayered load of that vendor CSS. For normal stylesheet declarations in the same origin and context, the later layer wins before selector specificity is compared. Check two computed properties in the browser: the one the theme should change and one the vendor stylesheet should still supply. A test that checks only the override can pass when the vendor import is broken.

Last reviewed: 2026-11-23 (Asia/Shanghai; 2026-11-22 UTC).

Decide which stylesheet owns the override

Suppose a coding agent changes the text color of an inventory badge. The vendor stylesheet uses #demo .badge, but the local theme uses .badge. Matching the vendor selector’s specificity might fix the color today, but it ties the theme to the vendor’s selectors. If you control the application’s stylesheet entry, declare the layer order there so both the agent and the reviewer can see where ordinary theme overrides belong.

The W3C cascade specification orders layers by their first declaration. In this example, @layer vendor, theme; sets the order before either layer is populated. Repeating that statement later does not move layers that already exist. Within a layer in this example, specificity and source order still matter. Normal declarations outside all named layers take precedence over normal declarations inside them. That last rule explains why wrapping the theme alone can make an override that used to work start losing.

Before editing, locate the existing vendor load. Check the stylesheet entry, template links and component imports. Replace the original unlayered load when you bring the vendor CSS into a layer. A second load can supply the same declarations outside the layer, even when the layered import itself is correct. If you cannot control an injected stylesheet, first look for the vendor’s theme or token interface. Adding a local @layer statement cannot move rules the vendor has already emitted outside it.

Isolate the badge color and keep its padding

Create these two files in the same directory. In vendor.css, the vendor rule owns both the original color and the padding:

#demo .badge {
  color: rgb(95, 57, 130);
  padding-left: 12px;
}

In index.html, the theme changes only the color. The order statement can appear before the import; keep the import ahead of style rules and layer blocks. The layer(vendor) clause assigns the imported rules to vendor.

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Badge cascade check</title>
<style>
  @layer vendor, theme;
  @import url("./vendor.css") layer(vendor);

  @layer theme {
    .badge { color: rgb(12, 88, 94); }
  }
</style>
<main id="demo"><p class="badge">In stock</p></main>
</html>

Open the file in a browser. The badge should have the theme color rgb(12, 88, 94) and 12px of left padding. The color demonstrates that a class selector in the later layer can beat an ID selector in the earlier layer. The padding matters because it has no theme declaration: if the vendor stylesheet disappears, the badge can still look teal but lose its spacing.

Trace the winner when the badge turns purple

In Chrome DevTools, inspect the badge in Elements. Filter Computed for color to see its resolved value, then find the matching declarations in Styles. Click a layer name or the layers toggle in Styles to view the order. The Chrome DevTools CSS reference shows both views. Write down which stylesheet supplied the winning declaration; the same computed color can come from a different rule after the patch.

Change one thing at a time in the fixture and restore it before trying the next change. These observations distinguish a priority problem from a missing stylesheet:

Change in the fixtureComputed colorLeft paddingWhat to inspect
Layered import and vendor, theme orderrgb(12, 88, 94)12pxThe theme wins for color; the vendor still supplies padding.
Add a second stylesheet link to vendor.css outside any layerrgb(95, 57, 130)12pxLook for a winning declaration outside vendor.
Reverse the initial order to theme, vendorrgb(95, 57, 130)12pxFind the first declaration of the layers.
Remove the import, or move it below the theme blockrgb(12, 88, 94)0pxCheck the import path, placement and loaded stylesheet.

If the vendor rule still wins after you restore the order and remove duplicate loads, compare declarations before changing selectors. For comparable !important declarations in different layers, earlier layers win; adding !important to a declaration in the later theme layer may still lose to an important declaration in the vendor layer. Check for an inline declaration or a rule that only applies in a particular state or viewport. The table covers ordinary stylesheet declarations for this badge, so include any other condition when you reproduce the problem.

Assert the winning color and a surviving vendor rule

With Playwright Test and its Chromium browser installed, save badge.spec.cjs beside the two files. The example opens the fixture directly from disk. The Playwright locator assertion reference documents toHaveCSS for checking a computed property on the element the locator finds.

const { test, expect } = require('@playwright/test');
const { join } = require('node:path');
const { pathToFileURL } = require('node:url');

test('theme color wins while vendor padding remains', async ({ page }) => {
  const fixture = pathToFileURL(join(__dirname, 'index.html'));
  await page.goto(fixture.href);
  const badge = page.getByText('In stock', { exact: true });

  await expect(badge).toHaveCSS('padding-left', '12px');
  await expect(badge).toHaveCSS('color', 'rgb(12, 88, 94)');
});

From that directory, run:

npx playwright test badge.spec.cjs

The fixture passed in Chromium. Separate computed style checks reproduced the table values for the duplicate load, reversed order, missing import and misplaced import. To check the assertions yourself, temporarily remove the import and confirm the padding assertion fails. Restore it and add the duplicate link; the padding assertion should pass and the color assertion should fail. Undo both changes before keeping the fixture. These checks cover the illustrated badge, not every selector in the vendor sheet.

Verify the route that ships the stylesheet

Once the small example passes, move the same pair of assertions to a test of the built route that loads the real component. A fixture opened directly from disk cannot catch a bundler emitting a second copy, another entry point declaring a layer first, or a route loading styles only when the component mounts. Use a state where the affected rule applies. If the patch changes several states, such as the selected and unselected badge, give each state its own expected value. Read the computed values in the browser used by the test instead of copying the spelling of the authored CSS.

Ask the agent to include the stylesheet entry point, the layer order, and the two observed values in its pull request review handoff . If a computed value disagrees with the intended design, record the selector and layer of the winning declaration before asking for a revision. When the override changes text or focus colors, also run the relevant accessibility checks for the changed UI state . Computed style can show which declaration won; it does not establish that the resulting state has enough contrast or a visible focus indicator.

Sources checked