Overview
Hosts provide a theme preference ("light" or "dark") via host context. The SDK provides functions to apply this theme to the document and read the current theme state.
applyDocumentTheme
Sets thedata-theme attribute and color-scheme CSS property on document.documentElement. This enables:
- CSS selectors like
[data-theme="dark"] - The CSS
light-dark()function - Native elements (scrollbars, form controls) respecting the theme
Signature
Usage
CSS Selectors
After callingapplyDocumentTheme, use these patterns in your CSS:
getDocumentTheme
Reads the current theme fromdocument.documentElement. Checks the data-theme attribute first, then falls back to the dark class for Tailwind CSS compatibility.