CKTIS / JavaScript
CSSStyleDeclaration.setProperty — setting CSS declarations
Set CSS declarations with setProperty(), passing a property name, value, and optional priority.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
style.setProperty(property, value, priority = "")CSSStyleDeclaration.setProperty changes a declaration, for example in element.style. It is a browser API, not an ECMAScript feature. Use CSS names such as margin-top, not marginTop; custom property names such as --accent are case-sensitive.
priority accepts "" or case-insensitive "important". Do not put !important in value. In a writable declaration block, an empty value removes the declaration before the priority is checked, even if the priority is invalid. With a non-empty value, an invalid priority causes no change.
Unsupported properties and invalid values cause no change. A read-only block throws NoModificationAllowedError. The method returns undefined.
Examples
const style = document.createElement("div").style;
style.setProperty("margin-top", "12px", "important");
console.log(style.getPropertyValue("margin-top"));
console.log(style.getPropertyPriority("margin-top"));
style.setProperty("margin-top", "");
console.log(JSON.stringify(style.getPropertyValue("margin-top")));Result
12px important ""
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.