Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober 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 Now×
Skip to content
World desk3 min

Puppeteer Frame.addStyleTag Options Explained

Use Puppeteer’s Frame.addStyleTag() to add inline CSS, a local stylesheet, or a URL-backed stylesheet to the frame you choose.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

frame.addStyleTag() adds CSS to the frame represented by that Puppeteer Frame object. Pass content for CSS text, path for a local CSS file, or url for a stylesheet URL. Use the frame method when the CSS belongs in a particular frame; page.addStyleTag() is the shortcut for the page’s main frame.

Choose the stylesheet input

The documented options are content, path, and url. Each is optional in the interface, but for predictable results, provide just the one source form you intend to use. The API references do not specify precedence or validation behavior when multiple fields are supplied together.

Option Use it for What Puppeteer receives
content CSS authored in your script A string containing raw CSS
path A stylesheet stored locally A CSS file path; a relative path resolves from Node.js process.cwd()
url A stylesheet available at a URL The URL of a CSS file, represented by a link element

Inline CSS: content

Use content when the CSS is short, generated dynamically, or already available as a string.

await frame.addStyleTag({
  content: 'body { background: #f5f5f5; }'
});

Local CSS: path

Use path to load a stylesheet from the machine running the Node.js process. Relative paths are based on the process working directory, not the page URL and not necessarily the directory containing the script. An absolute path avoids uncertainty about the working directory.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await frame.addStyleTag({
  path: '/absolute/path/to/test.css'
});

Remote CSS: url

Use url to link a stylesheet by URL. The URL overload produces a link element rather than an inline style element.

await frame.addStyleTag({
  url: 'https://example.com/test.css'
});

Target the frame that should receive the CSS

Call addStyleTag() on the Frame you want to modify. A page can contain a main frame and child frames; adding a stylesheet to one frame does not mean it has been added to every other frame.

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

If the target is the main frame, page.addStyleTag(options) is a convenience shortcut equivalent to page.mainFrame().addStyleTag(options). For a particular child frame, use that frame’s method instead.

What the method returns

The method returns a promise for a handle to the loaded element. In the documented overloads, options without url return an ElementHandle<HTMLStyleElement>; the URL overload returns an ElementHandle<HTMLLinkElement>. This distinction reflects how the stylesheet is represented: style element for the non-URL form and link element for the URL form.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

Common problems and fixes

  • The CSS file cannot be found: Check the Node process’s current working directory and the path spelling. Use an absolute path if the code may run from different directories.
  • The stylesheet affects the wrong content: Confirm that you called the method on the intended frame. page.addStyleTag() targets the main frame, not an arbitrary child frame.
  • The returned element is not the type expected: A URL-backed stylesheet uses a link element; the other documented overload uses a style element.
  • Several option fields are being passed together: The references do not define which field takes precedence or how combinations are validated. Pass only the intended source and check the API reference for the Puppeteer version installed in your project.

Version considerations

Puppeteer’s API references can render different documentation versions: the options interface page showed version 25.3.0, the Frame method page 25.9.0, and the Page method page 25.11.0 at the time those pages were reviewed. Documentation may change over time, so compare the method and option types with the version of Puppeteer your project actually uses.

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

Or skip the browser setup

If your goal is to produce a webpage screenshot rather than modify a particular Puppeteer frame, ScreenshotNeo provides a screenshot API. Its custom-CSS option can apply CSS to a capture, but that is not a replacement for choosing a specific Puppeteer frame with Frame.addStyleTag().

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Example cURL request:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo documentation for request options. Cookie banners, newsletter popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are not billed. Its MCP server lets AI agents take screenshots, and the free plan includes 1,000 screenshots a month without a card; paid plans start at $5 for 3,000. Sign up for the free plan.

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.

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.

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. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

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.