Get to know MDN better
Injects CSS into a page.
Note: This method is available in Manifest V3 or higher in Chrome and Firefox 101. In Safari and Firefox 102+, this method is also available in Manifest V2.
To use this API, you must have the "scripting" permission and permission for the target's URL, either explicitly as a host permission or using the activeTab permission.
You can only inject CSS into pages whose URL can be expressed using a match pattern: meaning its scheme must be one of "http", "https", or "file". This means you can't inject CSS into any of the browser's built-in pages, such as about:debugging, about:addons, or the page that opens when you open a new empty tab.
Note: Firefox resolves URLs in injected CSS files relative to the CSS file rather than the page it's injected into.
The inserted CSS can be removed by calling scripting.removeCSS().
This is an asynchronous function that returns a Promise.
An object describing the CSS to insert and where to insert it. It contains the following properties:
css Optionalstring. A string containing the CSS to inject. Either css or files must be specified.
files Optionalarray of string. The path of CSS files to inject relative to the extension's root directory. Either files or css must be specified.
origin Optionalstring. The style origin for the injection, either USER, to add the CSS as a user stylesheet, or AUTHOR, to add it as an author stylesheet. Defaults to AUTHOR. This property is case-insensitive from Firefox 144.
scripting.InjectionTarget. Details specifying the target to inject the CSS into.
A Promise that fulfills with no arguments when all the CSS is inserted. If any error occurs, the promise is rejected.
This example inserts CSS taken from a string into the active tab.
This example inserts CSS loaded from a file (packaged with the extension) called "content-style.css":
Enable JavaScript to view this browser compatibility table.
Note: This API is based on Chromium's chrome.scripting API.
This page was last modified on Nov 7, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.