Inheritable Properties in Shadow DOM
You'll learn which CSS properties naturally cross the shadow boundary and which stop at the wall.
The Inheritance Boundary
Not all CSS properties treat the shadow boundary the same way. Inherited properties (like color, font-family, line-height) naturally flow from the host document through the shadow root to elements inside, just like they flow through regular DOM trees. However, non-inherited properties (like border, margin, background) stop at the boundary and don't affect shadow DOM internals unless explicitly set.
Think of it like hereditary traits: eye color passes down through generations (inherited properties), but wearing a jacket doesn't make your children wear jackets (non-inherited properties).
Why This Matters
This inheritance behavior is intentional and powerful. It lets your component respect the document's typography and color scheme automatically while maintaining encapsulation for layout properties:
/* In the document */
body {
font-family: 'Arial'; /* Flows into shadow DOM */
color: #333; /* Flows into shadow DOM */
margin: 20px; /* Does NOT flow in */
}
Inside your shadow root, elements inherit font-family and color without any extra work. But margin won't leak in, keeping your component's internal spacing intact.
The Custom Property Bridge
Remember from the previous lesson that CSS Custom Properties (variables) are always inherited. This creates a powerful pattern: use custom properties as explicit "ports" to pass values through the shadow boundary when you need more control than default inheritance provides.
Key Takeaway: Inherited CSS properties (typography, colors) naturally cross the shadow boundary, while non-inherited properties (layout, borders) don't—giving you automatic theming consistency while preserving encapsulation for structure.