Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

HTMLElement.style — an element’s inline styles

HTMLElement.style exposes a mutable inline CSS declaration object, not the result of the cascade.

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

element.style.propertyName = "value";
element.style.setProperty("property-name", "value", "important");
element.style.removeProperty("property-name");

HTMLElement.style always returns the same inline declaration object associated with the style attribute. The specification defines it as CSSStyleProperties, inheriting from CSSStyleDeclaration.

Use camelCase names such as marginTop, or setProperty() with CSS names. For custom properties, use setProperty(). Supply the important priority as the third argument, not within the value.

removeProperty() removes a declaration; an absent value reads as "". style does not expose the cascade result—use getComputedStyle() for that. Assigning text to element.style forwards it to cssText, replacing the entire inline block rather than one declaration.

Examples

const element = document.createElement("div");
const style = element.style;
style.marginTop = "12px";
style.setProperty("--gap", "8px");
console.log(style === element.style);
console.log(style.marginTop);
console.log(style.getPropertyValue("--gap"));
style.removeProperty("margin-top");
console.log(JSON.stringify(style.marginTop));

Result

true
12px
8px
""

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources