Marti / GM_setStyle


Version: updated

Summary: Alternative to GM_addStyle for Greasemonkey

Copyright: 2011+, Marti Martz (

License: GPL-3.0-or-later;

License: CC-BY-NC-SA-4.0;

Collaborator: sizzle


  • No miscellaneous notes at this time


  • This API library is not frozen yet
  • Return values may not be present with @run-at document-start in this implementation depending on the status of upstream#1384... In these situations use the callback object parameter instead.
  • Comments are removed from CSS by design during validation. :)


Alternative to using GM_addStyle with validation and "pretty" simple formatting.

To be used with @require. It won't do any good if installed directly.

NOTE: Firefox 3.6.x has some issues so validation and formatting will not occur if the ability is not present.

More details to come as they develop. :)

Compatibility Matrix

Mozilla Firefox Mozilla Seamonkey Apple Safari Opera Software Opera Microsoft Internet Explorer Chromium Projects ChromiumGoogle Chrome                     
Linux Greasemonkey Greasemonkey prc Greasemonkey Port
Macintosh Greasemonkey Greasemonkey prc Greasemonkey Port
Windows Greasemonkey Greasemonkey prc Greasemonkey Port
  • Use this compatibility matrix to determine if this script is right for your system. Find the platform on the left and find your browser on the top. Where they intersect is the compatibility.


Quick example until full API listing can be created (possibly some more features too)

let styleNode = GM_setStyle({

  // OPTIONAL: Set the node to reuse... use null to return cssText instead of styleNode
  node: styleNode,

  // OPTIONAL: Set the media attribute
  media: "screen, projection",

  // OPTIONAL: The CSS to use... supports CDATA Multi-line XMLLists DIRECTLY!
  data: ".selectorA { rule: value; } #selectorB { position: fixed }",

  // OPTIONAL: How to reassemble the rules... default is newline character
  space: "\n",

  // OPTIONAL: Callback usually for use with @run-at document-start
  callback: function () {


Rating: 4

4 Votes