CSSOM tree

CSSOM 트리

The browser parses CSS rules into a style structure of selectors and declarations.

···
html
<div class="v"><header>CSSOM MATCH <span id="rule">.card</span></header><div class="stage match"><div class="rules"><div class="r" id="r0">.card { color }</div><div class="r" id="r1">.badge { fill }</div></div><div class="beam">→</div><div class="targets"><div class="t" id="t0">card</div><div class="t" id="t1">badge</div></div></div><div class="muted">selector → matched node → computed style</div></div>
css
.v{width:min(94vw,760px);height:min(88vh,320px);padding:clamp(9px,2.4vmin,18px);border:1px solid var(--line);border-radius:12px;background:var(--surface);font:500 clamp(12px,2.4vmin,16px)/1.3 var(--font-sans,system-ui,sans-serif);display:flex;flex-direction:column;gap:clamp(5px,1.4vmin,10px);overflow:hidden}.v header{display:flex;align-items:center;justify-content:space-between;gap:8px;color:var(--accent);font-weight:700}.v header span{color:var(--muted);font-weight:500}.v .stage{flex:1;min-height:0;position:relative}.v .muted{color:var(--muted)}.v .active{background:color-mix(in srgb,var(--accent) 18%,var(--surface));border-color:var(--accent)!important;color:var(--fg)}.v button{font:inherit;color:var(--fg);background:var(--bg);border:1px solid var(--line);border-radius:7px;padding:5px 8px;cursor:pointer}.match{display:flex;align-items:center;justify-content:center;gap:clamp(6px,3vmin,30px)}.rules,.targets{display:flex;flex-direction:column;gap:8px}.r,.t{border:1px solid var(--line);border-radius:7px;padding:7px;background:var(--bg);min-width:94px;text-align:center}.r.on,.t.on{border-color:var(--accent);background:color-mix(in srgb,var(--accent) 20%,var(--surface))}.beam{color:var(--accent);font-size:clamp(18px,4vmin,28px)}
js
let i=0;function tick(){for(let j=0;j<2;j++){document.getElementById("r"+j).classList.toggle("on",i===j);document.getElementById("t"+j).classList.toggle("on",i===j)}document.getElementById("rule").textContent=i?".badge":".card";i=1-i}tick();setInterval(tick,1000)

The CSSOM is the browser’s object model for CSS rules. When a selector matches a DOM element, its declarations participate in style calculation.

The demo connects a selector to a matching element and changes its color. Specificity and inheritance also affect the result, so reading a CSS file alone does not settle the final style.

When to use

Use it with the DOM when tracing selector conflicts or style calculation cost.

Open as page ↗