Keep embedded widgets visually consistent with your brand. Propagate design tokens into sandboxed iframes using standard CSS custom properties without additional JavaScript wiring inside the widget.
Where: This change applies to Lightning Experience, Experience Builder sites, and Experience Cloud LWR sites in all editions.
How: Set CSS custom properties on the <lwc-shell> element or any ancestor element in your wrapper LWC. For example: style="--brand-color:#0070d2; --font-family:Salesforce Sans,sans-serif;".
Inside the widget, reference tokens with standard CSS: color: var(--brand-color).
The shell reads all --* properties from its computed style via getComputedStyle(this) once at mount and forwards them to the iframe. The shell does not observe host-side style mutations automatically.
To update tokens at runtime — for example, when a user switches to dark mode:
- Set new values on the host element with
style.setProperty(). - Call
shell.refreshTheme()to re-scrape computed styles and forward the updated tokens.
Keep these considerations in mind:
- Only CSS custom properties (names starting with
--) cross the iframe boundary. Regular CSS declarations (color,background) on the host don't propagate. - Tokens must be declared on the
<lwc-shell>element or an ancestor element. Tokens on sibling elements don't propagate —getComputedStyle(this)reads from the shell's own inheritance chain.