cssdomcssom

Is Inline Styling Part of the CSSOM or the DOM?


I'm trying to understand the relationship between inline styles and the CSS Object Model (CSSOM) in a web document. Specifically, I want to know if inline styles applied directly to an element (either via HTML style attributes or JavaScript's element.style) are part of the CSSOM or handled by the DOM.

Inline styles are applied directly to an element, like this:

<div style="color: blue; font-size: 20px;">This text is styled with inline CSS.</div>

or using JavaScript:

const element = document.getElementById("myElement");
element.style.color = "blue";
element.style.fontSize = "20px";

My question is:

My understanding is:

Do you think I am wrong or correct? I've seen conflicting explanations, and I’d like to get a concrete answer with references if possible. Any clarification on whether inline styling is officially considered part of the CSSOM or just contributes to the computed styles would be helpful.


Solution

  • The spec for the style attribute clearly lays out

    The style IDL attribute is defined in CSS Object Model. [CSSOM]

    In can be found in chapter 7 DOM Access to CSS Declaration Blocks therein.