Playwright toHaveCSS() reads pseudo-element styles
Introduced 2026-05-11 · score 0.90
HOW TO USE IT
When asserting a locator’s computed CSS for a `::before` or `::after` pseudo-element, pass `pseudo: 'before'` or `pseudo: 'after'` in the `toHaveCSS()` options.
await expect(locator).toHaveCSS('content', '"New"', { pseudo: 'before' });await expect(locator).toHaveCSS('content', '"New"', { pseudo: 'after' });WHY THIS HELPS
Assert the computed CSS style of a locator's `::before` or `::after` pseudo-element.
REQUIREMENTS AND LIMITATIONS
- Version: v1.60.0
- name (required): CSS property name.
- value (required): Expected CSS property value; may be a string or RegExp.
- options.pseudo: Selects the pseudo-element to read computed styles from: `before` or `after`.
- The release names `::before` and `::after` as supported pseudo-elements.
FIRST-PARTY EVIDENCE
- https://github.com/microsoft/playwright/releases/tag/v1.60.0
- https://playwright.dev/docs/api/class-locatorassertions#locator-assertions-to-have-css
Check the installed version and the source before using it. Entry JSON