The insertRule() method of the CSSGroupingRule interface adds a new CSS rule to a list of CSS rules.
insertRule(rule)
insertRule(rule, index)ruleA string
index OptionalAn optional index at which to insert the rule; defaults to 0.
The index of the new rule.
IndexSizeError DOMExceptionThrown if index is greater than the number of child CSS rules.
HierarchyRequestError DOMExceptionThrown if rule cannot be inserted at the specified index due to some CSS constraint.
HierarchyRequestError DOMExceptionThrown if the rule is a valid statement but not a nested statement.
let myRules = document.styleSheets[0].cssRules;
myRules[0].insertRule(
"html {background-color: blue;}",
0,
); /* inserts a rule for the HTML element at position 0 */