api-member
CSS.registerProperty — CSS reference
This static method registers a custom property for the document. The name must be valid, inherits is a required boolean, and syntax defaults to "*". Invalid syntax or initial values can throw SyntaxError; duplicate JavaScript registration throws InvalidModificationError. It returns undefined.
Formal Syntax & Structure
css syntaxcss
CSS.registerProperty({name: "--gap", syntax: "<length>", inherits: false, initialValue: "16px"})Working Example
Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>CSS substitution lab</title><style>body {margin:0} .sample {height:12px;background:#006050}#parent {width:300px} .sample {width:40px;height:30px;margin-bottom:4px;color:white}.sample{width:var(--gap,30px)} #b{--gap:60px}</style><body><div id="parent"><div id="a" class="sample">A</div><div id="b" class="sample">B</div></div><script>const options={name:"--gap",syntax:"<length>",inherits:false,initialValue:"16px"};CSS.registerProperty(options);try{CSS.registerProperty(options)}catch(e){window.duplicateError=e.name}</script></body></html>