Componentsintermediate

View Encapsulation Strategies

Explain Angular's three view encapsulation modes and how they affect CSS scoping.

By default, styles you write in a component only apply to that component's own template — Angular achieves this without Shadow DOM by rewriting your CSS selectors and adding unique attributes to the component's DOM elements, a mode called Emulated encapsulation. Interviewers ask about this because it explains a very common "why doesn't my CSS apply" bug: a style targeting a child component's internal element from the parent's stylesheet simply won't match, because the attribute-based scoping doesn't cross component boundaries.

Emulated encapsulation is like giving every component's furniture a unique inventory tag so movers only load items with matching tags onto the truck — it looks isolated, but it's the same warehouse floor underneath, not a separate sealed room like real Shadow DOM.

Key Concepts

1
The three modes are ViewEncapsulation.Emulated (the default, attribute-based faux-scoping), ViewEncapsulation.None (styles become global, unscoped CSS, which is occasionally useful for deliberately leaking a style but dangerous if used carelessly), and ViewEncapsulation.ShadowDom (uses the browser's real Shadow DOM, giving true style and DOM isolation but with tighter compatibility constraints, like global styles not penetrating in either direction at all).
ViewEncapsulation.EmulatedViewEncapsulation.NoneViewEncapsulation.ShadowDom
2
Understanding this also clarifies why Angular introduced the deprecated /deep/, >>>, and ::ng-deep pseudo-selectors historically used to intentionally pierce encapsulation and style child components from a parent — and why ::ng-deep is now discouraged in favor of :host combined with CSS custom properties for themable components.
/deep/>>>::ng-deep:host
3
A strong answer connects this to component library design: if you're building a design system meant to be themed by consumers, you generally want Emulated encapsulation plus CSS custom properties exposed on :host, rather than reaching for ShadowDom or disabling encapsulation outright.
Emulated:hostShadowDom