← Back to CSS domain

CSS.addRule

Inserts a new rule with the given `ruleText` in a stylesheet with given `styleSheetId`, at the position specified by `location`.

Domain: CSS experimental

Parameters

NameTypeDescription
styleSheetIdDOM.StyleSheetIdThe css style sheet identifier where a new rule should be inserted.
ruleTextstringThe text of a new rule.
locationSourceRangeText position of a new rule in the target style sheet.
nodeForPropertySyntaxValidation (optional)DOM.NodeIdNodeId for the DOM node in whose context custom property declarations for registered properties should be validated. If omitted, declarations in the new rule text can only be validated statically, which may produce incorrect results if the declaration contains a var() for example.

Returns

NameTypeDescription
ruleCSSRuleThe newly created rule.

Example Request

{
  "id": 1,
  "method": "CSS.addRule",
  "params": {
    "styleSheetId": "styleSheetId-value",
    "ruleText": "ruleText-value",
    "location": "location-value"
  }
}

Example Response

{
  "id": 1,
  "result": {
    "rule": "rule-value"
  }
}

Usage in Node.js

const result = await send('CSS.addRule', {"styleSheetId": "styleSheetId-value", "ruleText": "ruleText-value", "location": "location-value"});
console.log(result);
// {"rule": "rule-value"}