Apply a CSS declaration string to an element property-by-property through the
CSSOM (style.setProperty). Unlike el.style.cssText = …, the style
attribute, or setAttribute("style", …), per-property CSSOM writes are NOT
subject to the CSP style-src directive — so this is the strict-CSP-safe way
to set dynamic inline styles (security roadmap B.5).
Intended for simple, code-owned declaration strings (no data: URIs); values
are split on the first : and trailing !important is forwarded as priority.
Parameters
el: HTMLElement
The target element.
css: string
A CSS declaration string, e.g. "display:flex;gap:8px".
Apply a CSS declaration string to an element property-by-property through the CSSOM (
style.setProperty). Unlikeel.style.cssText = …, thestyleattribute, orsetAttribute("style", …), per-property CSSOM writes are NOT subject to the CSPstyle-srcdirective — so this is the strict-CSP-safe way to set dynamic inline styles (security roadmap B.5).Intended for simple, code-owned declaration strings (no data: URIs); values are split on the first
:and trailing!importantis forwarded as priority.