Last updated 3 years ago
Was this helpful?
Web Components ⟩ Shadow DOM ⟩ Styling ⟩
Google ⟩ Web Component ⟩ Creating style hooks using CSS custom properties
CSS Variables
⭐️ use CSS variables: CSS variables exist on all levels, both in light and shadow. 📗 JS.info ⟩ CSS hooks with custom properties
<style> fancy-tabs { margin-bottom: 32px; --fancy-tabs-bg: black; <!-- ⭐️ css var --> } </style> <fancy-tabs background>...</fancy-tabs>
/* inside shadow DOM */ :host([background]) { background: var(--fancy-tabs-bg, #9E9E9E); /* ⭐️ css hook */ border-radius: 10px; padding: 10px; }