October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Blur an Element in a Screenshot with CSS Selectors

A practical guide to blurring one element in Playwright screenshots with CSS selectors, including assertion and direct-capture examples, masks, and troubleshooting.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In Playwright, blur a specific element by adding a selector-based CSS rule to the screenshot: use stylePath with toHaveScreenshot(), or the style option with page.screenshot(). The selector must match the rendered element. For a solid cover rather than a blurred appearance, use Playwright’s locator-based mask option.

Blur an element in a Playwright screenshot assertion

Put the CSS rule in a file, then pass its path to toHaveScreenshot(). This is useful when a visual assertion should blur volatile or sensitive-looking content without changing the application’s regular stylesheet.

As an Amazon Associate I earn from qualifying purchases.

  1. Create screenshot.css alongside your test, or adjust the path to match your project:

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
    /* screenshot.css */
    .account-number {
      filter: blur(8px) !important;
    }
  2. Use the selector stylesheet in the assertion:

    await expect(page).toHaveScreenshot({ stylePath: './screenshot.css' });
  3. Run the test and inspect the resulting screenshot. Confirm that the selector matches only the intended element and that the blur looks sufficient at the image’s actual size.

    #1 Best Overall
    Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
    • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
    • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
    • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
    • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
    • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents

Playwright’s visual-comparison documentation describes screenshot stylesheets as a way to filter dynamic content; its example hides iframes with CSS. The stylesheet is applied for the screenshot, not as a change to your application’s source data. Playwright: Visual comparisons

toHaveScreenshot() is part of Playwright’s test assertion API and works with the Playwright test runner. If you are not using that runner, use the Page screenshot API instead. Playwright: PageAssertions

Apply CSS to a direct page screenshot

For a direct page.screenshot() call, pass stylesheet text using the style option rather than stylePath:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.screenshot({
  path: 'page.png',
  style: '.account-number { filter: blur(8px) !important; }',
});

The style option applies CSS for the capture and, according to the Page API documentation, pierces Shadow DOM and applies to inner frames. The API documents this option as added in Playwright v1.41. Playwright: Page

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors

Choose blur or a solid mask

Method What appears in the screenshot Use it when
CSS filter: blur(...) The selected content remains visible as a softened rendering. You want the area’s shape and colors to remain, while its details become indistinct.
Playwright mask An overlay covers the matched element’s bounding box. The documented default is pink; a mask color can be chosen. You want a solid cover instead of a softened view.

Playwright’s mask is locator-based, while a CSS blur rule targets the element through a CSS selector. The PageAssertions API documents maskColor as added in v1.35. Playwright: PageAssertions

Make the selector reliable

  • Prefer a stable class, ID, or attribute that identifies the intended element and no unrelated content.

  • Check the rendered page, not just the source markup: the element must exist and match when the screenshot is taken.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Use !important if the page’s own styles override the screenshot rule; remove it if it is unnecessary.

    Rank #3
    Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
    • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
    • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
    • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
    • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
    • Ultra-thin bezels: Maximize your viewing experience with thin bezels.
  • Inspect the captured image at full size. CSS blur changes the rendered capture, but it does not remove the underlying page content or alter source data. The cited Playwright documentation does not establish blur as a security guarantee. For sensitive information, verify that the exported image fully obscures it.

Version and troubleshooting notes

Playwright documents stylePath for screenshot assertions and style for Page screenshots as introduced in v1.41. If either option is unavailable, check the version installed in the project and update it as appropriate. The maskColor option is documented as introduced in v1.35. Visual comparisons · Page · PageAssertions

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

ScreenshotNeo is a website screenshot API. A single GET request can return a screenshot or PDF; for this example, request a PNG capture of the target page. See the ScreenshotNeo API documentation for request options.

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.
curl -G "https://api.screenshotneo.com/v1/shot" 
  -d access_key=YOUR_API_KEY 
  --data-urlencode url=https://stripe.com 
  -o shot.png

This API is an alternative when you want a hosted capture rather than configuring Playwright locally. ScreenshotNeo removes supported cookie and consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, failed loads, and cache hits are not billed. Its MCP server provides screenshot and PDF tools for AI agents. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.

Learn about ScreenshotNeo or sign up free for 1,000 screenshots a month, no card required.

Frequently Asked Questions

Does CSS blur remove sensitive content from the page?

No. It changes how the selected content is rendered in the screenshot; it does not remove the underlying page content.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can I use stylePath with page.screenshot()?

No. Use stylePath with toHaveScreenshot(); the direct Page screenshot API takes stylesheet text in its style option.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.