dom / latest / cssstylesheet / cssstylesheet.html /

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

options Optional

An object containing the following:

baseURL Optional

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

media Optional

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

disabled Optional

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

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
CSSStyleSheet
73
79
73
No
53
No
73
73
No
47
No
9.0

See also

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/CSSStyleSheet