CSSStyleSheet.CSSStyleSheet()

The CSSStyleSheet() constructor creates a new CSSStyleSheet object which represents a single Stylesheet.

After constructing a stylesheet the CSSStyleSheet.replace() or CSSStyleSheet.replaceSync() methods can be used to add rules to the new stylesheet.

Syntax

new CSSStyleSheet();
new CSSStyleSheet(options);

Parameters

optionsOptional

An object containing the following:

baseURLOptional

A string containing the baseURL used to resolve relative URLs in the stylesheet.

mediaOptional

A MediaList containing a list of media rules, or a string containing a single rule.

disabledOptional

A Boolean indicating whether the stylesheet is disabled. False by default.

Examples

In the following example a new CSSStyleSheet is constructed, with a media rule of "print". Printing StyleSheet.media to the console returns a MediaList with a single entry for this print rule.

let stylesheet = new CSSStyleSheet({media: 'print'});
console.log(stylesheet.media);

Specifications

Specification
CSS Object Model (CSSOM) (CSSOM)
# dom-cssstylesheet-cssstylesheet

Browser compatibility

BCD tables only load in the browser

Polyfill