Menu

GM_addStyle

mmartz

Description

This API method adds a string of CSS to the document.

It creates a new <style> element, adds the given CSS to it, and inserts it into the <head>.

| Examples | See Also | Notes

Syntax

GM_addStyle( css )

Value: Function
Returns: undefined
Compatibility: Greasemonkey 0.6.1 - 3.12.0
Access: @grant

Parameters

Properties
css
  • All properties are optional except css.

Properties


css

Value: String
Usage: css = "body { color: red }";

Examples

| Spanning with Line Continuation | Spanning with ES6+ Template Strings | Spanning with E4X

Core

GM_addStyle("body { color: white; background-color: black } img { border: 0 }");

Spanning with Line Continuation

GM_addStyle("body { color: white; background-color: black }\
  img { border: 0 }\
  .footer { width: 875px; }");

Spanning with ES6+ Template Strings

GM_addStyle(`

body { color: white; background-color: black }
img { border: 0 }
.footer { width: 875px; }

`);

Spanning with E4X

GM_addStyle(<><![CDATA[

body { color: white; background-color: black }
img { border: 0 }
.footer { width: 875px; }


]]></>.toString()
);

See Also

Notes

  • Add !important at the end of the code to override an existing value.


Related

Wiki: Greasemonkey_Manual:API
Wiki: Version_history

MongoDB Logo MongoDB