Pick a severity below. JavaScript sets one custom property on the container — then pure CSS style queries update every child element, no class toggling involved.
JS runs exactly one line: container.style.setProperty('--severity', value).
Everything after that is CSS.
Style queries read the --severity custom property on the container
ancestor and apply styles to every child — icon, title colour, background — without
any JavaScript touching the child elements.
// JS reads state, toggles classes
el.classList.remove('error','warning','success');
el.classList.add(severity);
// CSS reacts to classes
.alert.error { border-color: red; }
.alert.warning { border-color: orange; }
.alert.success { border-color: green; }
// JS sets ONE custom property
container.style.setProperty(
'--severity', value
);
// CSS reads it — no class needed
@container style(--severity: error) {
.alert { border-color: red; }
}
With the CSS approach, adding a new child element means one new
@container style() rule — you never touch the JavaScript.