View Encapsulation Modes
Compare Emulated, None, and ShadowDom.
View Encapsulation Modes is a free Angular Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Angular Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Is View Encapsulation?
View encapsulation controls how a component styles are isolated from the rest of the page. Angular offers three modes via the encapsulation property.
Setting the Mode
Set the mode with the ViewEncapsulation enum in the @Component decorator.
import { Component, ViewEncapsulation } from "@angular/core";
@Component({
selector: "app-card",
encapsulation: ViewEncapsulation.Emulated
})
export class CardComponent {}Emulated (Default)
Emulated is the default. Angular simulates scoped styles by adding unique attributes to elements and selectors, without using native Shadow DOM.
@Component({
encapsulation: ViewEncapsulation.Emulated
})How Emulated Works
Emulated mode rewrites selectors with generated attributes, giving scoping that works in all browsers without Shadow DOM support requirements.
/* you write */
.title { color: blue; }
/* angular emits */
.title[_ngcontent-xyz] { color: blue; }None
None disables encapsulation entirely. The component styles become global and can affect any element on the page.
@Component({
encapsulation: ViewEncapsulation.None,
styles: [".title { color: red; }"]
})
// .title now applies app-wideWhen to Use None
Use None sparingly, for example to define shared theme rules from one component. Beware that styles can clash globally.
ShadowDom
ShadowDom uses the browser native Shadow DOM to truly isolate the component markup and styles.
@Component({
selector: "app-widget",
encapsulation: ViewEncapsulation.ShadowDom
})
export class WidgetComponent {}How ShadowDom Differs
With ShadowDom, the component renders inside a real shadow root. Global styles do not pierce in, and component styles do not leak out, giving the strongest isolation.
Style Leakage Compared
Emulated prevents leakage out but global styles can still target elements; None has no isolation; ShadowDom fully blocks both directions.
Choosing a Mode
Stick with Emulated for almost everything. Use ShadowDom for fully isolated widgets and None only for intentional global styles.
Encapsulation and Global Styles
Remember the global styles.css always applies regardless of mode, except inside a ShadowDom component, where global styles do not reach.
Quick Check
Test your understanding of view encapsulation modes.
Recap
Angular offers three encapsulation modes: Emulated (default, simulated scoping), None (global styles), and ShadowDom (native isolation). Emulated suits most cases; ShadowDom gives the strongest isolation.
Frequently asked questions
Is the “View Encapsulation Modes” lesson free?
Yes — the full text of “View Encapsulation Modes” is free to read here on the web, and the Angular Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Angular Academy course, upgrade to CoddyKit PRO.
What will I learn in “View Encapsulation Modes”?
Compare Emulated, None, and ShadowDom. You practise Angular Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Angular Academy?
No prior experience is required. Angular Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “View Encapsulation Modes” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Angular Academy lesson?
Yes. Every Angular Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Component-Scoped Styles
- View Encapsulation Modes
- Host and Host-Context Styling
- Dynamic Classes and Styles